james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [13/13] james-project git commit: JAMES-1929 JMAP wiring for GetMessageList::hasAttachment filter
Date Wed, 15 Feb 2017 00:01:31 GMT
JAMES-1929 JMAP wiring for GetMessageList::hasAttachment filter


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

Branch: refs/heads/master
Commit: 46feedcea1b9f609279dc12c33921c5036c9bcb6
Parents: 9fb956b
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Feb 8 16:44:07 2017 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Feb 15 06:59:46 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java | 12 +++++--
 .../james/jmap/utils/FilterToSearchQuery.java   | 24 ++++++--------
 .../jmap/utils/FilterToSearchQueryTest.java     | 33 ++++++++++++++------
 3 files changed, 44 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/46feedce/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
index 80764a5..0c2203b 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/SearchQuery.java
@@ -593,12 +593,20 @@ public class SearchQuery implements Serializable {
         return result;
     }
 
+    public static Criterion hasAttachment(boolean value) {
+        if (value) {
+            return new AttachmentCriterion(BooleanOperator.set());
+        } else {
+            return new AttachmentCriterion(BooleanOperator.unset());
+        }
+    }
+
     public static Criterion hasAttachment() {
-        return new AttachmentCriterion(BooleanOperator.set());
+        return hasAttachment(true);
     }
 
     public static Criterion hasNoAttachment() {
-        return new AttachmentCriterion(BooleanOperator.unset());
+        return hasAttachment(false);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/46feedce/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
index db7b485..d30c692 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/FilterToSearchQuery.java
@@ -23,7 +23,6 @@ import java.util.Date;
 
 import javax.mail.Flags.Flag;
 
-import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.model.Filter;
 import org.apache.james.jmap.model.FilterCondition;
 import org.apache.james.jmap.model.FilterOperator;
@@ -32,7 +31,6 @@ import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.Criterion;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
 
-import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
 
@@ -52,17 +50,15 @@ public class FilterToSearchQuery {
 
     private SearchQuery convertCondition(FilterCondition filter) {
         SearchQuery searchQuery = new SearchQuery();
-        filter.getText().ifPresent(text -> {
-            searchQuery.andCriteria(
-                    SearchQuery.or(ImmutableList.of(
-                            SearchQuery.address(AddressType.From, text),
-                            SearchQuery.address(AddressType.To, text),
-                            SearchQuery.address(AddressType.Cc, text),
-                            SearchQuery.address(AddressType.Bcc, text),
-                            SearchQuery.headerContains("Subject", text),
-                            SearchQuery.bodyContains(text)))
-                    );
-        });
+        filter.getText().ifPresent(text -> searchQuery.andCriteria(
+                SearchQuery.or(ImmutableList.of(
+                        SearchQuery.address(AddressType.From, text),
+                        SearchQuery.address(AddressType.To, text),
+                        SearchQuery.address(AddressType.Cc, text),
+                        SearchQuery.address(AddressType.Bcc, text),
+                        SearchQuery.headerContains("Subject", text),
+                        SearchQuery.bodyContains(text)))
+                ));
         filter.getFrom().ifPresent(from -> searchQuery.andCriteria(SearchQuery.address(AddressType.From,
from)));
         filter.getTo().ifPresent(to -> searchQuery.andCriteria(SearchQuery.address(AddressType.To,
to)));
         filter.getCc().ifPresent(cc -> searchQuery.andCriteria(SearchQuery.address(AddressType.Cc,
cc)));
@@ -71,7 +67,6 @@ public class FilterToSearchQuery {
         filter.getBody().ifPresent(body ->  searchQuery.andCriteria(SearchQuery.bodyContains(body)));
         filter.getAfter().ifPresent(after -> searchQuery.andCriteria(SearchQuery.internalDateAfter(Date.from(after.toInstant()),
DateResolution.Second)));
         filter.getBefore().ifPresent(before -> searchQuery.andCriteria(SearchQuery.internalDateBefore(Date.from(before.toInstant()),
DateResolution.Second)));
-        filter.getHasAttachment().ifPresent(Throwing.consumer(hasAttachment -> { throw
new NotImplementedException(); } ));
         filter.getHeader().ifPresent(header -> searchQuery.andCriteria(SearchQuery.headerContains(header.getName(),
header.getValue().orElse(null))));
         filter.getIsAnswered().ifPresent(isAnswered -> searchQuery.andCriteria(SearchQuery.flagIsSet(Flag.ANSWERED)));
         filter.getIsDraft().ifPresent(isDraft -> searchQuery.andCriteria(SearchQuery.flagIsSet(Flag.DRAFT)));
@@ -79,6 +74,7 @@ public class FilterToSearchQuery {
         filter.getIsUnread().ifPresent(isUnread -> searchQuery.andCriteria(SearchQuery.flagIsUnSet(Flag.SEEN)));
         filter.getMaxSize().ifPresent(maxSize -> searchQuery.andCriteria(SearchQuery.sizeLessThan(maxSize)));
         filter.getMinSize().ifPresent(minSize -> searchQuery.andCriteria(SearchQuery.sizeGreaterThan(minSize)));
+        filter.getHasAttachment().ifPresent(hasAttachment -> searchQuery.andCriteria(SearchQuery.hasAttachment(hasAttachment)));
         return searchQuery;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/46feedce/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
index 41cfb39..6b3f6bf 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/FilterToSearchQueryTest.java
@@ -27,7 +27,6 @@ import java.util.Date;
 
 import javax.mail.Flags.Flag;
 
-import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.jmap.model.Filter;
 import org.apache.james.jmap.model.FilterCondition;
 import org.apache.james.jmap.model.FilterOperator;
@@ -97,6 +96,30 @@ public class FilterToSearchQueryTest {
     }
 
     @Test
+    public void filterConditionShouldMapWhenHasAttachment() {
+        SearchQuery expectedSearchQuery = new SearchQuery();
+        expectedSearchQuery.andCriteria(SearchQuery.hasAttachment());
+
+        SearchQuery searchQuery = new FilterToSearchQuery().convert(FilterCondition.builder()
+            .hasAttachment(true)
+            .build());
+
+        assertThat(searchQuery).isEqualTo(expectedSearchQuery);
+    }
+
+    @Test
+    public void filterConditionShouldMapWhenHasNoAttachment() {
+        SearchQuery expectedSearchQuery = new SearchQuery();
+        expectedSearchQuery.andCriteria(SearchQuery.hasNoAttachment());
+
+        SearchQuery searchQuery = new FilterToSearchQuery().convert(FilterCondition.builder()
+            .hasAttachment(false)
+            .build());
+
+        assertThat(searchQuery).isEqualTo(expectedSearchQuery);
+    }
+
+    @Test
     public void filterConditionShouldMapWhenBcc() {
         String bcc = "blindcopy@james.org";
         SearchQuery expectedSearchQuery = new SearchQuery();
@@ -181,14 +204,6 @@ public class FilterToSearchQueryTest {
     }
 
     @Test
-    public void filterConditionShouldThrowWhenHasAttachment() {
-        assertThatThrownBy(() -> new FilterToSearchQuery().convert(FilterCondition.builder()
-                .hasAttachment(true)
-                .build()))
-            .isInstanceOf(NotImplementedException.class);
-    }
-
-    @Test
     public void filterConditionShouldMapWhenIsAnswered() {
         SearchQuery expectedSearchQuery = new SearchQuery();
         expectedSearchQuery.andCriteria(SearchQuery.flagIsSet(Flag.ANSWERED));


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