JAMES-2346 sendMDN should be part of JMAP response and requests

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

Branch: refs/heads/master
Commit: b54014d10c65c6609fd52c2bf7a9cb946b6be1a4
Parents: 4e7d6a0
Author: benwa <btell...@linagora.com>
Authored: Thu Mar 8 10:58:04 2018 +0700
Committer: benwa <btell...@linagora.com>
Committed: Tue Mar 13 15:11:54 2018 +0700

----------------------------------------------------------------------
 .../apache/james/jmap/methods/ValueWithId.java  |  7 +++++
 .../james/jmap/model/SetMessagesRequest.java    | 31 ++++++++++++++++++--
 .../james/jmap/model/SetMessagesResponse.java   | 26 ++++++++++++++--
 .../jmap/model/SetMessagesRequestTest.java      |  2 +-
 .../jmap/model/SetMessagesResponseTest.java     |  4 ++-
 5 files changed, 64 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b54014d1/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/ValueWithId.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/ValueWithId.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/ValueWithId.java
index 194e6d1..e8ce60c 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/ValueWithId.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/ValueWithId.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.methods;
 
 import org.apache.james.jmap.model.CreationMessage;
 import org.apache.james.jmap.model.CreationMessageId;
+import org.apache.james.jmap.model.MDN;
 import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.SetError;
 
@@ -50,6 +51,12 @@ public class ValueWithId<T> {
         }
     }
 
+    public static class CreationMDNEntry extends ValueWithId<MDN> {
+        public CreationMDNEntry(CreationMessageId creationId, MDN mdn) {
+            super(creationId, mdn);
+        }
+    }
+
     public static class ErrorWithId extends ValueWithId<SetError> {
         public ErrorWithId(CreationMessageId creationId, SetError error) {
             super(creationId, error);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54014d1/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
index 9e213ec..2f3cd68 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
@@ -28,6 +28,7 @@ import java.util.function.Function;
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.methods.JmapRequest;
 import org.apache.james.jmap.methods.UpdateMessagePatchConverter;
+import org.apache.james.jmap.methods.ValueWithId.CreationMDNEntry;
 import org.apache.james.jmap.methods.ValueWithId.CreationMessageEntry;
 import org.apache.james.mailbox.model.MessageId;
 
@@ -53,12 +54,14 @@ public class SetMessagesRequest implements JmapRequest {
         private String accountId;
         private String ifInState;
         private HashMap<CreationMessageId, CreationMessage> create;
+        private HashMap<CreationMessageId, MDN> sendMDN;
         private ImmutableMap.Builder<MessageId, 
Function<UpdateMessagePatchConverter, UpdateMessagePatch>> updatesProvider;
 
         private ImmutableList.Builder<MessageId> destroy;
 
         private Builder() {
             create = new HashMap<>();
+            sendMDN = new HashMap<>();
             updatesProvider = ImmutableMap.builder();
             destroy = ImmutableList.builder();
         }
@@ -87,6 +90,16 @@ public class SetMessagesRequest implements JmapRequest {
             return this;
         }
 
+        public Builder sendMDN(CreationMessageId creationMessageId, MDN mdn) {
+            this.sendMDN.put(creationMessageId, mdn);
+            return this;
+        }
+
+        public Builder sendMDN(Map<CreationMessageId, MDN> mdns) {
+            this.sendMDN.putAll(mdns);
+            return this;
+        }
+
         public Builder update(Map<MessageId, ObjectNode> updates) {
             this.updatesProvider.putAll(Maps.transformValues(updates, json -> 
converter -> converter.fromJsonNode(json)));
             return this;
@@ -99,7 +112,7 @@ public class SetMessagesRequest implements JmapRequest {
 
         public SetMessagesRequest build() {
             return new SetMessagesRequest(Optional.ofNullable(accountId), 
Optional.ofNullable(ifInState), 
-                    messageCreations(), updatesProvider.build(), 
destroy.build());
+                    messageCreations(), mdnSendings(), 
updatesProvider.build(), destroy.build());
         }
 
         private ImmutableList<CreationMessageEntry> messageCreations() {
@@ -107,18 +120,28 @@ public class SetMessagesRequest implements JmapRequest {
                     .map(entry -> new CreationMessageEntry(entry.getKey(), 
entry.getValue()))
                     .collect(Guavate.toImmutableList());
         }
+
+        private ImmutableList<CreationMDNEntry> mdnSendings() {
+            return sendMDN.entrySet().stream()
+                    .map(entry -> new CreationMDNEntry(entry.getKey(), 
entry.getValue()))
+                    .collect(Guavate.toImmutableList());
+        }
     }
 
     private final Optional<String> accountId;
     private final Optional<String> ifInState;
     private final List<CreationMessageEntry> create;
+    private final List<CreationMDNEntry> sendMDN;
     private final Map<MessageId, Function<UpdateMessagePatchConverter, 
UpdateMessagePatch>> update;
     private final List<MessageId> destroy;
 
-    @VisibleForTesting SetMessagesRequest(Optional<String> accountId, 
Optional<String> ifInState, List<CreationMessageEntry> create, Map<MessageId, 
Function<UpdateMessagePatchConverter, UpdateMessagePatch>>  update, 
List<MessageId> destroy) {
+    @VisibleForTesting SetMessagesRequest(Optional<String> accountId, 
Optional<String> ifInState,
+                    List<CreationMessageEntry> create, List<CreationMDNEntry> 
sendMDN, Map<MessageId,
+                    Function<UpdateMessagePatchConverter, UpdateMessagePatch>> 
update, List<MessageId> destroy) {
         this.accountId = accountId;
         this.ifInState = ifInState;
         this.create = create;
+        this.sendMDN = sendMDN;
         this.update = update;
         this.destroy = destroy;
     }
@@ -135,6 +158,10 @@ public class SetMessagesRequest implements JmapRequest {
         return create;
     }
 
+    public List<CreationMDNEntry> getSendMDN() {
+        return sendMDN;
+    }
+
     public Map<MessageId, UpdateMessagePatch> 
buildUpdatePatches(UpdateMessagePatchConverter converter) {
         return Maps.transformValues(update, func -> func.apply(converter));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54014d1/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesResponse.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesResponse.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesResponse.java
index 7fef42e..5700df0 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesResponse.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesResponse.java
@@ -25,6 +25,7 @@ import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.methods.Method;
 import org.apache.james.mailbox.model.MessageId;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
@@ -53,6 +54,7 @@ public class SetMessagesResponse implements Method.Response {
         private final ImmutableList.Builder<MessageId> updated;
         private final ImmutableList.Builder<MessageId> destroyed;
         private final ImmutableMap.Builder<CreationMessageId, SetError> 
notCreated;
+        private final ImmutableMap.Builder<CreationMessageId, SetError> 
MDNNotSent;
         private final ImmutableMap.Builder<MessageId, SetError> notUpdated;
         private final ImmutableMap.Builder<MessageId, SetError> notDestroyed;
 
@@ -61,6 +63,7 @@ public class SetMessagesResponse implements Method.Response {
             updated = ImmutableList.builder();
             destroyed = ImmutableList.builder();
             notCreated = ImmutableMap.builder();
+            MDNNotSent = ImmutableMap.builder();
             notUpdated = ImmutableMap.builder();
             notDestroyed = ImmutableMap.builder();
         }
@@ -106,6 +109,16 @@ public class SetMessagesResponse implements 
Method.Response {
             this.notCreated.putAll(notCreated);
             return this;
         }
+
+        public Builder MDNNotSent(Map<CreationMessageId, SetError> notCreated) 
{
+            this.MDNNotSent.putAll(notCreated);
+            return this;
+        }
+
+        public Builder MDNNotSent(CreationMessageId creationMessageId, 
SetError error) {
+            this.MDNNotSent.put(creationMessageId, error);
+            return this;
+        }
         
         public Builder notCreated(CreationMessageId id, SetError error) {
             this.notCreated.put(id, error);
@@ -133,7 +146,8 @@ public class SetMessagesResponse implements Method.Response 
{
 
         public SetMessagesResponse build() {
             return new SetMessagesResponse(accountId, oldState, newState, 
-                    created.build(), updated.build(), destroyed.build(), 
notCreated.build(), notUpdated.build(), notDestroyed.build());
+                created.build(), updated.build(), destroyed.build(),
+                notCreated.build(), MDNNotSent.build(), notUpdated.build(), 
notDestroyed.build());
         }
     }
 
@@ -144,11 +158,12 @@ public class SetMessagesResponse implements 
Method.Response {
     private final ImmutableList<MessageId> updated;
     private final ImmutableList<MessageId> destroyed;
     private final ImmutableMap<CreationMessageId, SetError> notCreated;
+    private final ImmutableMap<CreationMessageId, SetError> MDNNotSent;
     private final ImmutableMap<MessageId, SetError> notUpdated;
     private final ImmutableMap<MessageId, SetError> notDestroyed;
 
     @VisibleForTesting SetMessagesResponse(String accountId, String oldState, 
String newState, ImmutableMap<CreationMessageId, Message> created, 
ImmutableList<MessageId> updated, ImmutableList<MessageId> destroyed,
-            ImmutableMap<CreationMessageId, SetError> notCreated, 
ImmutableMap<MessageId, SetError> notUpdated, ImmutableMap<MessageId, SetError> 
notDestroyed) {
+                                           ImmutableMap<CreationMessageId, 
SetError> notCreated, ImmutableMap<CreationMessageId, SetError> mdnNotSent, 
ImmutableMap<MessageId, SetError> notUpdated, ImmutableMap<MessageId, SetError> 
notDestroyed) {
         this.accountId = accountId;
         this.oldState = oldState;
         this.newState = newState;
@@ -156,6 +171,7 @@ public class SetMessagesResponse implements Method.Response 
{
         this.updated = updated;
         this.destroyed = destroyed;
         this.notCreated = notCreated;
+        this.MDNNotSent = mdnNotSent;
         this.notUpdated = notUpdated;
         this.notDestroyed = notDestroyed;
     }
@@ -196,6 +212,11 @@ public class SetMessagesResponse implements 
Method.Response {
         return notDestroyed;
     }
 
+    @JsonProperty("MDNNotSent")
+    public ImmutableMap<CreationMessageId, SetError> getMDNNotSent() {
+        return MDNNotSent;
+    }
+
     public SetMessagesResponse.Builder mergeInto(SetMessagesResponse.Builder 
responseBuilder) {
         responseBuilder.created(getCreated());
         responseBuilder.updated(getUpdated());
@@ -203,6 +224,7 @@ public class SetMessagesResponse implements Method.Response 
{
         responseBuilder.notCreated(getNotCreated());
         responseBuilder.notUpdated(getNotUpdated());
         responseBuilder.notDestroyed(getNotDestroyed());
+        responseBuilder.MDNNotSent(getMDNNotSent());
         if (! Strings.isNullOrEmpty(getAccountId())) {
             responseBuilder.accountId(getAccountId());
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54014d1/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesRequestTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesRequestTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesRequestTest.java
index 5c3107f..eef2d18 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesRequestTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesRequestTest.java
@@ -50,7 +50,7 @@ public class SetMessagesRequestTest {
     public void builderShouldWork() {
         ImmutableList<MessageId> destroy = 
ImmutableList.of(TestMessageId.of(4));
 
-        SetMessagesRequest expected = new SetMessagesRequest(Optional.empty(), 
Optional.empty(), ImmutableList.of(), ImmutableMap.of(), destroy);
+        SetMessagesRequest expected = new SetMessagesRequest(Optional.empty(), 
Optional.empty(), ImmutableList.of(), ImmutableList.of(), ImmutableMap.of(), 
destroy);
 
         SetMessagesRequest setMessagesRequest = SetMessagesRequest.builder()
             .accountId(null)

http://git-wip-us.apache.org/repos/asf/james-project/blob/b54014d1/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
index 83429ff..61cf8fb 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMessagesResponseTest.java
@@ -73,7 +73,8 @@ public class SetMessagesResponseTest {
         ImmutableMap<CreationMessageId, SetError> notCreated = 
ImmutableMap.of(CreationMessageId.of("dead-beef-defec8"), 
SetError.builder().type("created").build());
         ImmutableMap<MessageId, SetError> notUpdated = 
ImmutableMap.of(TestMessageId.of(4), 
SetError.builder().type("updated").build());
         ImmutableMap<MessageId, SetError> notDestroyed  = 
ImmutableMap.of(TestMessageId.of(5), 
SetError.builder().type("destroyed").build());
-        SetMessagesResponse expected = new SetMessagesResponse(null, null, 
null, created, updated, destroyed, notCreated, notUpdated, notDestroyed);
+        ImmutableMap<CreationMessageId, SetError> mdnNotSent = 
ImmutableMap.of(CreationMessageId.of("dead-beef-defec9"), 
SetError.builder().type("MDNNotSent").build());
+        SetMessagesResponse expected = new SetMessagesResponse(null, null, 
null, created, updated, destroyed, notCreated, mdnNotSent, notUpdated, 
notDestroyed);
 
         SetMessagesResponse setMessagesResponse = SetMessagesResponse.builder()
             .created(created)
@@ -82,6 +83,7 @@ public class SetMessagesResponseTest {
             .notCreated(notCreated)
             .notUpdated(notUpdated)
             .notDestroyed(notDestroyed)
+            .MDNNotSent(mdnNotSent)
             .build();
 
         
assertThat(setMessagesResponse).isEqualToComparingFieldByField(expected);


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

Reply via email to