This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 49ed1a64bd12cbb136ba87ccc53c1d7fbeaa4cea
Author: Tran Tien Duc <[email protected]>
AuthorDate: Fri Nov 29 09:14:57 2019 +0700

    JAMES-2992 MessageFastView model
---
 .../draft/model/message/view/MessageFastView.java  | 113 +++++++++++++++++++++
 .../draft/model/message/view/MessageFullView.java  |  25 +----
 2 files changed, 116 insertions(+), 22 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastView.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastView.java
new file mode 100644
index 0000000..dfa6ce6
--- /dev/null
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastView.java
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.draft.model.message.view;
+
+import java.time.Instant;
+import java.util.Optional;
+
+import org.apache.james.jmap.api.model.Preview;
+import org.apache.james.jmap.draft.methods.JmapResponseWriterImpl;
+import org.apache.james.jmap.draft.model.BlobId;
+import org.apache.james.jmap.draft.model.Emailer;
+import org.apache.james.jmap.draft.model.Keywords;
+import org.apache.james.jmap.draft.model.Number;
+import org.apache.james.jmap.draft.model.PreviewDTO;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+
+import com.fasterxml.jackson.annotation.JsonFilter;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * This message view holds all Message properties expected to be fast.
+ */
+@JsonDeserialize(builder = MessageFastView.Builder.class)
+@JsonFilter(JmapResponseWriterImpl.PROPERTIES_FILTER)
+public class MessageFastView extends MessageHeaderView {
+
+    public static MessageFastView.Builder<? extends MessageFastView.Builder> 
builder() {
+        return new Builder();
+    }
+
+    @JsonPOJOBuilder(withPrefix = "")
+    public static class Builder<S extends MessageFastView.Builder<S>> extends 
MessageHeaderView.Builder<S> {
+        protected Optional<Preview> preview;
+
+        protected Builder() {
+            super();
+        }
+
+        public S preview(Preview preview) {
+            this.preview = Optional.of(preview);
+            return (S) this;
+        }
+
+        public S preview(Optional<Preview> preview) {
+            this.preview = preview;
+            return (S) this;
+        }
+
+        public MessageFastView build() {
+            checkState();
+            return new MessageFastView(id, blobId, threadId, mailboxIds, 
Optional.ofNullable(inReplyToMessageId),
+                headers, Optional.ofNullable(from),
+                to.build(), cc.build(), bcc.build(), replyTo.build(), subject, 
date, size, PreviewDTO.from(preview),
+                keywords.orElse(Keywords.DEFAULT_VALUE));
+        }
+
+        public void checkState() {
+            super.checkState();
+            Preconditions.checkState(preview != null, "'preview' is 
mandatory");
+        }
+    }
+
+
+    private final PreviewDTO preview;
+
+    @VisibleForTesting
+    MessageFastView(MessageId id,
+                    BlobId blobId,
+                    String threadId,
+                    ImmutableList<MailboxId> mailboxIds,
+                    Optional<String> inReplyToMessageId,
+                    ImmutableMap<String, String> headers,
+                    Optional<Emailer> from,
+                    ImmutableList<Emailer> to,
+                    ImmutableList<Emailer> cc,
+                    ImmutableList<Emailer> bcc,
+                    ImmutableList<Emailer> replyTo,
+                    String subject,
+                    Instant date,
+                    Number size,
+                    PreviewDTO preview,
+                    Keywords keywords) {
+        super(id, blobId, threadId, mailboxIds, inReplyToMessageId, headers, 
from, to, cc, bcc, replyTo, subject, date, size, keywords);
+        this.preview = preview;
+    }
+
+    public PreviewDTO getPreview() {
+        return preview;
+    }
+}
diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
index aac8eda..fc809c8 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFullView.java
@@ -25,7 +25,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.function.Predicate;
 
-import org.apache.james.jmap.api.model.Preview;
 import org.apache.james.jmap.draft.methods.JmapResponseWriterImpl;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
@@ -46,15 +45,14 @@ import com.google.common.collect.ImmutableMap;
 
 @JsonDeserialize(builder = MessageFullView.Builder.class)
 @JsonFilter(JmapResponseWriterImpl.PROPERTIES_FILTER)
-public class MessageFullView extends MessageHeaderView {
+public class MessageFullView extends MessageFastView {
 
     public static Builder builder() {
         return new Builder();
     }
 
     @JsonPOJOBuilder(withPrefix = "")
-    public static class Builder extends 
MessageHeaderView.Builder<MessageFullView.Builder> {
-        private Optional<Preview> preview;
+    public static class Builder extends 
MessageFastView.Builder<MessageFullView.Builder> {
         private Optional<String> textBody = Optional.empty();
         private Optional<String> htmlBody = Optional.empty();
         private final ImmutableList.Builder<Attachment> attachments;
@@ -66,16 +64,6 @@ public class MessageFullView extends MessageHeaderView {
             attachedMessages = ImmutableMap.builder();
         }
 
-        public Builder preview(Preview preview) {
-            this.preview = Optional.of(preview);
-            return this;
-        }
-
-        public Builder preview(Optional<Preview> preview) {
-            this.preview = preview;
-            return this;
-        }
-
         public Builder textBody(Optional<String> textBody) {
             this.textBody = textBody;
             return this;
@@ -110,7 +98,6 @@ public class MessageFullView extends MessageHeaderView {
 
         public void checkState(ImmutableList<Attachment> attachments, 
ImmutableMap<BlobId, SubMessage> attachedMessages) {
             super.checkState();
-            Preconditions.checkState(preview != null, "'preview' is 
mandatory");
             
Preconditions.checkState(areAttachedMessagesKeysInAttachments(attachments, 
attachedMessages), "'attachedMessages' keys must be in 'attachements'");
         }
     }
@@ -132,7 +119,6 @@ public class MessageFullView extends MessageHeaderView {
     }
 
     private final boolean hasAttachment;
-    private final PreviewDTO preview;
     private final Optional<String> textBody;
     private final Optional<String> htmlBody;
     private final ImmutableList<Attachment> attachments;
@@ -160,9 +146,8 @@ public class MessageFullView extends MessageHeaderView {
                     ImmutableList<Attachment> attachments,
                     ImmutableMap<BlobId, SubMessage> attachedMessages,
                     Keywords keywords) {
-        super(id, blobId, threadId, mailboxIds, inReplyToMessageId, headers, 
from, to, cc, bcc, replyTo, subject, date, size, keywords);
+        super(id, blobId, threadId, mailboxIds, inReplyToMessageId, headers, 
from, to, cc, bcc, replyTo, subject, date, size, preview, keywords);
         this.hasAttachment = hasAttachment;
-        this.preview = preview;
         this.textBody = textBody;
         this.htmlBody = htmlBody;
         this.attachments = attachments;
@@ -173,10 +158,6 @@ public class MessageFullView extends MessageHeaderView {
         return hasAttachment;
     }
 
-    public PreviewDTO getPreview() {
-        return preview;
-    }
-
     public Optional<String> getTextBody() {
         return textBody;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to