james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [1/5] james-project git commit: JAMES-1715 Aggregate SetMailboxes processors response
Date Tue, 05 Apr 2016 12:02:06 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 68ab61763 -> 8005257c4


JAMES-1715 Aggregate SetMailboxes processors response


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/169e7bfc
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/169e7bfc
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/169e7bfc

Branch: refs/heads/master
Commit: 169e7bfc1bddb83316b17cef56303b08103f102b
Parents: 68ab617
Author: Antoine Duprat <antduprat@gmail.com>
Authored: Thu Mar 31 10:05:33 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Tue Apr 5 11:24:51 2016 +0200

----------------------------------------------------------------------
 .../methods/SetMailboxesCreationProcessor.java  |  2 +-
 .../james/jmap/methods/SetMailboxesMethod.java  | 20 ++++++++------
 .../james/jmap/model/SetMailboxesResponse.java  | 28 ++++++++++++++++++--
 .../jmap/methods/SetMailboxesMethodTest.java    |  2 +-
 4 files changed, 40 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/169e7bfc/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
index 205528f..fe6696b 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
@@ -98,7 +98,7 @@ public class SetMailboxesCreationProcessor<Id extends MailboxId> implements
SetM
             mailboxManager.createMailbox(mailboxPath, mailboxSession);
             Optional<Mailbox> mailbox = mailboxUtils.mailboxFromMailboxPath(mailboxPath,
mailboxSession);
             if (mailbox.isPresent()) {
-                builder.creation(mailboxCreationId, mailbox.get());
+                builder.created(mailboxCreationId, mailbox.get());
                 creationIdsToCreatedMailboxId.put(mailboxCreationId, mailbox.get().getId());
             } else {
                 builder.notCreated(mailboxCreationId, SetError.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/169e7bfc/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java
index 51ae92f..f454bff 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java
@@ -62,16 +62,20 @@ public class SetMailboxesMethod<Id extends MailboxId> implements
Method {
         Preconditions.checkNotNull(mailboxSession);
         Preconditions.checkArgument(request instanceof SetMailboxesRequest);
         SetMailboxesRequest setMailboxesRequest = (SetMailboxesRequest) request;
-        return processors.stream()
-            .map(processor -> processor.process(setMailboxesRequest, mailboxSession))
-            .map(response -> toJmapResponse(clientId, response));
+        return Stream.of(
+                JmapResponse.builder().clientId(clientId)
+                .response(setMailboxesResponse(setMailboxesRequest, mailboxSession))
+                .responseName(RESPONSE_NAME)
+                .build());
     }
 
-    private JmapResponse toJmapResponse(ClientId clientId, SetMailboxesResponse response)
{
-        return JmapResponse.builder()
-                .clientId(clientId)
-                .responseName(RESPONSE_NAME)
-                .response(response)
+    private SetMailboxesResponse setMailboxesResponse(SetMailboxesRequest request, MailboxSession
mailboxSession) {
+        return processors.stream()
+                .map(processor -> processor.process(request, mailboxSession))
+                .reduce(SetMailboxesResponse.builder(),
+                        (builder, resp) -> resp.mergeInto(builder) ,
+                        (builder1, builder2) -> builder2.build().mergeInto(builder1)
+                )
                 .build();
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/169e7bfc/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
index 2d38706..caeb42a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMailboxesResponse.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import org.apache.james.jmap.methods.Method;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 
+import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableMap;
 
 public class SetMailboxesResponse implements Method.Response {
@@ -41,11 +42,16 @@ public class SetMailboxesResponse implements Method.Response {
             notCreated = ImmutableMap.builder();
         }
 
-        public Builder creation(MailboxCreationId creationId, Mailbox mailbox) {
+        public Builder created(MailboxCreationId creationId, Mailbox mailbox) {
             created.put(creationId, mailbox);
             return this;
         }
 
+        public Builder created(ImmutableMap<MailboxCreationId, Mailbox> created) {
+            this.created.putAll(created);
+            return this;
+        }
+
         public Builder notCreated(Map<MailboxCreationId, SetError> notCreated) {
             this.notCreated.putAll(notCreated);
             return this;
@@ -59,7 +65,6 @@ public class SetMailboxesResponse implements Method.Response {
         public SetMailboxesResponse build() {
             return new SetMailboxesResponse(created.build(), notCreated.build());
         }
-
     }
 
     private final ImmutableMap<MailboxCreationId, Mailbox> created;
@@ -77,4 +82,23 @@ public class SetMailboxesResponse implements Method.Response {
     public Map<MailboxCreationId, SetError> getNotCreated() {
         return notCreated;
     }
+
+    public SetMailboxesResponse.Builder mergeInto(SetMailboxesResponse.Builder responseBuilder)
{
+        return responseBuilder
+            .created(getCreated());
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(created);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof SetMailboxesResponse) {
+            SetMailboxesResponse other = (SetMailboxesResponse) obj;
+            return Objects.equal(this.created, other.created);
+        }
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/169e7bfc/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
index 0019460..fcf2a2e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
@@ -93,7 +93,7 @@ public class SetMailboxesMethodTest {
         SetMailboxesRequest creationRequest = SetMailboxesRequest.builder().create(creationId,
fooFolder).build();
 
         Mailbox createdfooFolder = Mailbox.builder().name("fooFolder").id("fooId").build();
-        SetMailboxesResponse creationResponse = SetMailboxesResponse.builder().creation(creationId,
createdfooFolder).build();
+        SetMailboxesResponse creationResponse = SetMailboxesResponse.builder().created(creationId,
createdfooFolder).build();
         JmapResponse jmapResponse = JmapResponse.builder()
             .response(creationResponse)
             .clientId(ClientId.of("clientId"))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message