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

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

commit f107618aca43e88dc69fec64992c12d87f1c6371
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Mon Dec 2 12:00:34 2019 +0700

    JAMES-2997 Add hasAttachment to MessageFastViewPrecomputedProperties
---
 .../CassandraMessageFastViewProjection.java        |  8 +++--
 .../CassandraMessageFastViewProjectionModule.java  | 18 ++++++-----
 .../CassandraMessageFastViewProjectionTable.java   |  1 +
 .../MessageFastViewPrecomputedProperties.java      | 36 +++++++++++++++++-----
 .../MessageFastViewProjectionContract.java         |  5 +++
 5 files changed, 52 insertions(+), 16 deletions(-)

diff --git 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
index 387b39f..47fa83d 100644
--- 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
+++ 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
@@ -23,6 +23,7 @@ import static 
com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
+import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.HAS_ATTACHMENT;
 import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.MESSAGE_ID;
 import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.PREVIEW;
 import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.TABLE_NAME;
@@ -61,7 +62,8 @@ public class CassandraMessageFastViewProjection implements 
MessageFastViewProjec
 
         this.storeStatement = session.prepare(insertInto(TABLE_NAME)
             .value(MESSAGE_ID, bindMarker(MESSAGE_ID))
-            .value(PREVIEW, bindMarker(PREVIEW)));
+            .value(PREVIEW, bindMarker(PREVIEW))
+            .value(HAS_ATTACHMENT, bindMarker(HAS_ATTACHMENT)));
 
         this.retrieveStatement = session.prepare(select()
             .from(TABLE_NAME)
@@ -74,7 +76,8 @@ public class CassandraMessageFastViewProjection implements 
MessageFastViewProjec
 
         return cassandraAsyncExecutor.executeVoid(storeStatement.bind()
             .setUUID(MESSAGE_ID, ((CassandraMessageId) messageId).get())
-            .setString(PREVIEW, 
precomputedProperties.getPreview().getValue()));
+            .setString(PREVIEW, precomputedProperties.getPreview().getValue())
+            .setBool(HAS_ATTACHMENT, precomputedProperties.hasAttachment()));
     }
 
     @Override
@@ -103,6 +106,7 @@ public class CassandraMessageFastViewProjection implements 
MessageFastViewProjec
     private MessageFastViewPrecomputedProperties fromRow(Row row) {
         return MessageFastViewPrecomputedProperties.builder()
             .preview(Preview.from(row.getString(PREVIEW)))
+            .hasAttachment(row.getBool(HAS_ATTACHMENT))
             .build();
     }
 }
diff --git 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjectionModule.java
 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjectionModule.java
index 5c56e9b..0b7df7d 100644
--- 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjectionModule.java
+++ 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjectionModule.java
@@ -19,23 +19,27 @@
 
 package org.apache.james.jmap.cassandra.projections;
 
+import static com.datastax.driver.core.DataType.cboolean;
 import static com.datastax.driver.core.DataType.text;
 import static com.datastax.driver.core.DataType.uuid;
+import static 
org.apache.james.backends.cassandra.utils.CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION;
+import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.HAS_ATTACHMENT;
+import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.MESSAGE_ID;
+import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.PREVIEW;
+import static 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable.TABLE_NAME;
 
 import org.apache.james.backends.cassandra.components.CassandraModule;
-import org.apache.james.backends.cassandra.utils.CassandraConstants;
-import 
org.apache.james.jmap.cassandra.projections.table.CassandraMessageFastViewProjectionTable;
 
 import com.datastax.driver.core.schemabuilder.SchemaBuilder;
 
 public interface CassandraMessageFastViewProjectionModule {
-    CassandraModule MODULE = 
CassandraModule.table(CassandraMessageFastViewProjectionTable.TABLE_NAME)
+    CassandraModule MODULE = CassandraModule.table(TABLE_NAME)
         .comment("Storing the JMAP preview property extracted from message 
bodies")
         .options(options -> options
-            .caching(SchemaBuilder.KeyCaching.ALL,
-                
SchemaBuilder.rows(CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION)))
+            .caching(SchemaBuilder.KeyCaching.ALL, 
SchemaBuilder.rows(DEFAULT_CACHED_ROW_PER_PARTITION)))
         .statement(statement -> statement
-            
.addPartitionKey(CassandraMessageFastViewProjectionTable.MESSAGE_ID, uuid())
-            .addColumn(CassandraMessageFastViewProjectionTable.PREVIEW, 
text()))
+            .addPartitionKey(MESSAGE_ID, uuid())
+            .addColumn(PREVIEW, text())
+            .addColumn(HAS_ATTACHMENT, cboolean()))
         .build();
 }
diff --git 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/table/CassandraMessageFastViewProjectionTable.java
 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/table/CassandraMessageFastViewProjectionTable.java
index 4035626..add0037 100644
--- 
a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/table/CassandraMessageFastViewProjectionTable.java
+++ 
b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/table/CassandraMessageFastViewProjectionTable.java
@@ -24,4 +24,5 @@ public interface CassandraMessageFastViewProjectionTable {
 
     String MESSAGE_ID = "messageId";
     String PREVIEW = "preview";
+    String HAS_ATTACHMENT = "hasAttachment";
 }
diff --git 
a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewPrecomputedProperties.java
 
b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewPrecomputedProperties.java
index ee2cdca..452f7fd 100644
--- 
a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewPrecomputedProperties.java
+++ 
b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewPrecomputedProperties.java
@@ -29,49 +29,71 @@ public class MessageFastViewPrecomputedProperties {
     public static class Builder {
         @FunctionalInterface
         public interface RequirePreview {
-            FinalStage preview(Preview preview);
+            RequireHasAttachment preview(Preview preview);
+        }
+
+        @FunctionalInterface
+        public interface RequireHasAttachment {
+            FinalStage hasAttachment(boolean hasAttachment);
+
+            default FinalStage hasAttachment() {
+                return hasAttachment(true);
+            }
+
+            default FinalStage noAttachments() {
+                return hasAttachment(false);
+            }
         }
 
         public static class FinalStage {
             private final Preview preview;
+            private final boolean hasAttachment;
 
-            private FinalStage(Preview preview) {
+            private FinalStage(Preview preview, boolean hasAttachment) {
+                this.hasAttachment = hasAttachment;
                 Preconditions.checkNotNull(preview, "'preview' cannot be 
null");
                 this.preview = preview;
             }
 
             public MessageFastViewPrecomputedProperties build() {
-                return new MessageFastViewPrecomputedProperties(preview);
+                return new MessageFastViewPrecomputedProperties(preview, 
hasAttachment);
             }
         }
     }
 
     public static Builder.RequirePreview builder() {
-        return preview -> new Builder.FinalStage(preview);
+        return preview -> hasAttachment -> new Builder.FinalStage(preview, 
hasAttachment);
     }
 
     private final Preview preview;
+    private final boolean hasAttachment;
 
-    private MessageFastViewPrecomputedProperties(Preview preview) {
+    private MessageFastViewPrecomputedProperties(Preview preview, boolean 
hasAttachment) {
         this.preview = preview;
+        this.hasAttachment = hasAttachment;
     }
 
     public Preview getPreview() {
         return preview;
     }
 
+    public boolean hasAttachment() {
+        return hasAttachment;
+    }
+
     @Override
     public final boolean equals(Object o) {
         if (o instanceof MessageFastViewPrecomputedProperties) {
             MessageFastViewPrecomputedProperties that = 
(MessageFastViewPrecomputedProperties) o;
 
-            return Objects.equals(this.preview, that.preview);
+            return Objects.equals(this.preview, that.preview)
+                && Objects.equals(this.hasAttachment, that.hasAttachment);
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hash(preview);
+        return Objects.hash(preview, hasAttachment);
     }
 }
diff --git 
a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionContract.java
 
b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionContract.java
index f752125..d2dfdfe 100644
--- 
a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionContract.java
+++ 
b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionContract.java
@@ -41,9 +41,11 @@ public interface MessageFastViewProjectionContract {
     Preview PREVIEW_2 = Preview.from("preview 2");
     MessageFastViewPrecomputedProperties 
MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES_1 = 
MessageFastViewPrecomputedProperties.builder()
         .preview(PREVIEW_1)
+        .hasAttachment()
         .build();
     MessageFastViewPrecomputedProperties 
MESSAGE_FAST_VIEW_PRECOMPUTED_PROPERTIES_2 = 
MessageFastViewPrecomputedProperties.builder()
         .preview(PREVIEW_2)
+        .noAttachments()
         .build();
 
     MessageFastViewProjection testee();
@@ -146,6 +148,7 @@ public interface MessageFastViewProjectionContract {
             .reactorOperation((thread, step) -> testee()
                 .store(messageIds.get(thread), 
MessageFastViewPrecomputedProperties.builder()
                     .preview(Preview.from(String.valueOf(step)))
+                    .hasAttachment()
                     .build()))
             .threadCount(threadCount)
             .operationCount(stepCount)
@@ -157,6 +160,7 @@ public interface MessageFastViewProjectionContract {
                     .block())
                 .isEqualTo(MessageFastViewPrecomputedProperties.builder()
                     .preview(Preview.from(String.valueOf(stepCount - 1)))
+                    .hasAttachment()
                     .build()));
     }
 
@@ -170,6 +174,7 @@ public interface MessageFastViewProjectionContract {
             .reactorOperation((thread, step) -> testee()
                 .store(messageId, 
MessageFastViewPrecomputedProperties.builder()
                     .preview(Preview.from(String.valueOf(step * threadCount + 
thread)))
+                    .hasAttachment()
                     .build()))
             .threadCount(threadCount)
             .operationCount(operationCount)


---------------------------------------------------------------------
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