You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2018/08/28 12:12:25 UTC
[08/13] james-project git commit: JAMES-2530 Requests/Responses for
JMAP filters
JAMES-2530 Requests/Responses for JMAP filters
This will be tested later in JMAP CRUD tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2224a02e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2224a02e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2224a02e
Branch: refs/heads/master
Commit: 2224a02eb9957e89a6c91d2d13b292162da1fa6d
Parents: 25965a9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 28 09:35:22 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Aug 28 14:11:50 2018 +0200
----------------------------------------------------------------------
.../james/jmap/model/GetFilterRequest.java | 55 ++++++++++++
.../james/jmap/model/GetFilterResponse.java | 88 ++++++++++++++++++++
.../james/jmap/model/SetFilterRequest.java | 75 +++++++++++++++++
.../james/jmap/model/SetFilterResponse.java | 56 +++++++++++++
4 files changed, 274 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/2224a02e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
new file mode 100644
index 0000000..52195f0
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jmap.model;
+
+import org.apache.james.jmap.JmapFieldNotSupportedException;
+import org.apache.james.jmap.methods.JmapRequest;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+
+@JsonDeserialize(builder = GetFilterRequest.Builder.class)
+public class GetFilterRequest implements JmapRequest {
+ private static final String ISSUER = "GetFilterRequest";
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+
+ private Builder() {
+
+ }
+
+ public Builder accountId(String accountId) {
+ throw new JmapFieldNotSupportedException(ISSUER, "accountId");
+ }
+
+ public GetFilterRequest build() {
+ return new GetFilterRequest();
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private GetFilterRequest() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/2224a02e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterResponse.java
new file mode 100644
index 0000000..6cbe278
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterResponse.java
@@ -0,0 +1,88 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jmap.model;
+
+import java.util.List;
+
+import org.apache.james.jmap.api.filtering.Rule;
+import org.apache.james.jmap.methods.Method;
+
+import com.google.common.collect.ImmutableList;
+
+public class GetFilterResponse implements Method.Response {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private String accountId;
+ private String state;
+ private ImmutableList.Builder<JmapRuleDTO> rules;
+
+ public Builder() {
+ this.rules = ImmutableList.builder();
+ }
+
+ public Builder accountId(String accountId) {
+ this.accountId = accountId;
+ return this;
+ }
+
+ public Builder state(String state) {
+ this.state = state;
+ return this;
+ }
+
+ public Builder rules(List<Rule> rules) {
+ this.rules.addAll(rules.stream()
+ .map(JmapRuleDTO::from)
+ .collect(ImmutableList.toImmutableList()));
+ return this;
+ }
+
+ public GetFilterResponse build() {
+ return new GetFilterResponse(accountId, state, rules.build());
+ }
+ }
+
+ private final String accountId;
+ private final String state;
+ private final List<JmapRuleDTO> rules;
+
+ private GetFilterResponse(String accountId, String state, List<JmapRuleDTO> rules) {
+ this.accountId = accountId;
+ this.state = state;
+ this.rules = rules;
+ }
+
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public List<JmapRuleDTO> getSingleton() {
+ return rules;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/2224a02e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterRequest.java
new file mode 100644
index 0000000..5371534
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterRequest.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jmap.model;
+
+import java.util.List;
+
+import org.apache.james.jmap.JmapFieldNotSupportedException;
+import org.apache.james.jmap.methods.JmapRequest;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.collect.ImmutableList;
+
+@JsonDeserialize(builder = SetFilterRequest.Builder.class)
+public class SetFilterRequest implements JmapRequest {
+
+ private static final String ISSUER = "SetFilterRequest";
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+ private final ImmutableList.Builder<JmapRuleDTO> rules;
+
+ private Builder() {
+ this.rules = ImmutableList.builder();
+ }
+
+ public Builder accountId(String accountId) {
+ throw new JmapFieldNotSupportedException(ISSUER, "accountId");
+ }
+
+ public Builder ifInState(String ifInState) {
+ throw new JmapFieldNotSupportedException(ISSUER, "ifInState");
+ }
+
+ public Builder singleton(List<JmapRuleDTO> rules) {
+ this.rules.addAll(rules);
+ return this;
+ }
+
+ public SetFilterRequest build() {
+ return new SetFilterRequest(rules.build());
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private final List<JmapRuleDTO> singleton;
+
+ private SetFilterRequest(List<JmapRuleDTO> singleton) {
+ this.singleton = singleton;
+ }
+
+ public List<JmapRuleDTO> getSingleton() {
+ return singleton;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/2224a02e/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterResponse.java
new file mode 100644
index 0000000..fe56cbf
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetFilterResponse.java
@@ -0,0 +1,56 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jmap.model;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.james.jmap.methods.Method;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class SetFilterResponse implements Method.Response {
+ public static final String SINGLETON = "singleton";
+
+ public static SetFilterResponse updated() {
+ return new SetFilterResponse(ImmutableList.of(SINGLETON), ImmutableMap.of());
+ }
+
+ public static SetFilterResponse notUpdated(SetError error) {
+ return new SetFilterResponse(ImmutableList.of(), ImmutableMap.of(SINGLETON, error));
+ }
+
+ private final List<String> updated;
+ private final Map<String, SetError> notUpdated;
+
+ private SetFilterResponse(List<String> updated, Map<String, SetError> notUpdated) {
+ this.updated = updated;
+ this.notUpdated = notUpdated;
+ }
+
+ public List<String> getUpdated() {
+ return updated;
+ }
+
+ public Map<String, SetError> getNotUpdated() {
+ return notUpdated;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org