james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [13/15] james-project git commit: JAMES-2255 Attachment from JMAP should use Number for number data
Date Fri, 05 Jan 2018 09:17:39 GMT
JAMES-2255 Attachment from JMAP should use Number for number data


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

Branch: refs/heads/master
Commit: 5708237599f9f5be7c6e1eb229e1671e72607b0d
Parents: 8e71c4f
Author: quynhn <qnguyen@linagora.com>
Authored: Tue Dec 12 13:59:16 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 16:11:46 2018 +0700

----------------------------------------------------------------------
 .../integration/GetMessageListMethodTest.java   |  2 +-
 .../org/apache/james/jmap/model/Attachment.java | 26 ++++++++++----------
 .../james/jmap/model/FilterCondition.java       | 18 +++++++-------
 .../org/apache/james/jmap/model/Number.java     |  4 +--
 .../apache/james/jmap/model/UploadResponse.java | 10 ++++----
 .../james/jmap/utils/FilterToSearchQuery.java   |  4 +--
 .../apache/james/jmap/model/AttachmentTest.java |  9 +++++--
 .../james/jmap/model/FilterConditionTest.java   |  3 ++-
 .../org/apache/james/jmap/model/NumberTest.java |  7 ++++++
 9 files changed, 48 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
index 119eea7..8ff2f6a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
@@ -1924,6 +1924,6 @@ public abstract class GetMessageListMethodTest {
             .statusCode(200)
             .body(NAME, equalTo("error"))
             .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
-            .body(ARGUMENTS + ".description", containsString("value should be positive and
less than 2^53 or empty"));
+            .body(ARGUMENTS + ".description", containsString("value should be positive and
less than 2^53"));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java
index 49081a4..37dfa7f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Attachment.java
@@ -41,11 +41,11 @@ public class Attachment {
         private BlobId blobId;
         private String type;
         private String name;
-        private Long size;
+        private Number size;
         private String cid;
         private boolean isInline;
-        private Long width;
-        private Long height;
+        private Number width;
+        private Number height;
 
         public Builder blobId(BlobId blobId) {
             this.blobId = blobId;
@@ -69,7 +69,7 @@ public class Attachment {
         }
 
         public Builder size(long size) {
-            this.size = size;
+            this.size = Number.fromLong(size);
             return this;
         }
 
@@ -90,12 +90,12 @@ public class Attachment {
         }
 
         public Builder width(long width) {
-            this.width = width;
+            this.width = Number.fromLong(width);
             return this;
         }
 
         public Builder height(long height) {
-            this.height = height;
+            this.height = Number.fromLong(height);
             return this;
         }
 
@@ -110,13 +110,13 @@ public class Attachment {
     private final BlobId blobId;
     private final String type;
     private final Optional<String> name;
-    private final long size;
+    private final Number size;
     private final Optional<String> cid;
     private final boolean isInline;
-    private final Optional<Long> width;
-    private final Optional<Long> height;
+    private final Optional<Number> width;
+    private final Optional<Number> height;
 
-    @VisibleForTesting Attachment(BlobId blobId, String type, Optional<String> name,
long size, Optional<String> cid, boolean isInline, Optional<Long> width, Optional<Long>
height) {
+    @VisibleForTesting Attachment(BlobId blobId, String type, Optional<String> name,
Number size, Optional<String> cid, boolean isInline, Optional<Number> width, Optional<Number>
height) {
         this.blobId = blobId;
         this.type = type;
         this.name = name;
@@ -139,7 +139,7 @@ public class Attachment {
         return name;
     }
 
-    public long getSize() {
+    public Number getSize() {
         return size;
     }
 
@@ -155,11 +155,11 @@ public class Attachment {
         return isInline && cid.isPresent();
     }
 
-    public Optional<Long> getWidth() {
+    public Optional<Number> getWidth() {
         return width;
     }
 
-    public Optional<Long> getHeight() {
+    public Optional<Number> getHeight() {
         return height;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
index f1e94ce..6b6cd43 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
@@ -46,8 +46,8 @@ public class FilterCondition implements Filter {
         private Optional<List<String>> notInMailboxes;
         private ZonedDateTime before;
         private ZonedDateTime after;
-        private Integer minSize;
-        private Integer maxSize;
+        private Number minSize;
+        private Number maxSize;
         private Boolean isFlagged;
         private Boolean isUnread;
         private Boolean isAnswered;
@@ -118,12 +118,12 @@ public class FilterCondition implements Filter {
         }
 
         public Builder minSize(int minSize) {
-            this.minSize = minSize;
+            this.minSize = Number.fromInt(minSize);
             return this;
         }
 
         public Builder maxSize(int maxSize) {
-            this.maxSize = maxSize;
+            this.maxSize = Number.fromInt(maxSize);
             return this;
         }
 
@@ -217,8 +217,8 @@ public class FilterCondition implements Filter {
     private final Optional<List<String>> notInMailboxes;
     private final Optional<ZonedDateTime> before;
     private final Optional<ZonedDateTime> after;
-    private final Optional<Integer> minSize;
-    private final Optional<Integer> maxSize;
+    private final Optional<Number> minSize;
+    private final Optional<Number> maxSize;
     private final Optional<Boolean> isFlagged;
     private final Optional<Boolean> isUnread;
     private final Optional<Boolean> isAnswered;
@@ -237,7 +237,7 @@ public class FilterCondition implements Filter {
     private final Optional<String> hasKeyword;
     private final Optional<String> notKeyword;
 
-    @VisibleForTesting FilterCondition(Optional<List<String>> inMailboxes, Optional<List<String>>
notInMailboxes, Optional<ZonedDateTime> before, Optional<ZonedDateTime> after,
Optional<Integer> minSize, Optional<Integer> maxSize,
+    @VisibleForTesting FilterCondition(Optional<List<String>> inMailboxes, Optional<List<String>>
notInMailboxes, Optional<ZonedDateTime> before, Optional<ZonedDateTime> after,
Optional<Number> minSize, Optional<Number> maxSize,
                                        Optional<Boolean> isFlagged, Optional<Boolean>
isUnread, Optional<Boolean> isAnswered, Optional<Boolean> isDraft, Optional<Boolean>
isForwarded,
                                        Optional<Boolean> hasAttachment,
                                        Optional<String> text, Optional<String>
from, Optional<String> to, Optional<String> cc, Optional<String> bcc, Optional<String>
subject,
@@ -284,11 +284,11 @@ public class FilterCondition implements Filter {
         return after;
     }
 
-    public Optional<Integer> getMinSize() {
+    public Optional<Number> getMinSize() {
         return minSize;
     }
 
-    public Optional<Integer> getMaxSize() {
+    public Optional<Number> getMaxSize() {
         return maxSize;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
index 378eee7..d4fc286 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Number.java
@@ -37,13 +37,13 @@ public class Number {
 
     public static Number fromInt(int value) {
         Preconditions.checkState(value >= ZERO_VALUE,
-            "value should be positive and less than 2^31 or empty");
+            "value should be positive and less than 2^31");
         return new Number(value);
     }
 
     public static Number fromLong(long value) {
         Preconditions.checkState(value >= ZERO_VALUE && value <= MAX_VALUE,
-            "value should be positive and less than 2^53 or empty");
+            "value should be positive and less than 2^53");
         return new Number(value);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UploadResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UploadResponse.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UploadResponse.java
index 1868122..269cb15 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UploadResponse.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UploadResponse.java
@@ -42,7 +42,7 @@ public class UploadResponse {
         private String accountId;
         private String blobId;
         private String type;
-        private Long size;
+        private Number size;
         private ZonedDateTime expires;
 
         public Builder accountId(String accountId) {
@@ -61,7 +61,7 @@ public class UploadResponse {
         }
 
         public Builder size(long size) {
-            this.size = size;
+            this.size = Number.fromOutboundLong(size);
             return this;
         }
 
@@ -81,10 +81,10 @@ public class UploadResponse {
     private final Optional<String> accountId;
     private final String blobId;
     private final String type;
-    private final Long size;
+    private final Number size;
     private final Optional<ZonedDateTime> expires;
 
-    @VisibleForTesting UploadResponse(Optional<String> accountId, String blobId, String
type, long size, Optional<ZonedDateTime> expires) {
+    @VisibleForTesting UploadResponse(Optional<String> accountId, String blobId, String
type, Number size, Optional<ZonedDateTime> expires) {
         this.accountId = accountId;
         this.blobId = blobId;
         this.type = type;
@@ -104,7 +104,7 @@ public class UploadResponse {
         return type;
     }
 
-    public long getSize() {
+    public Number getSize() {
         return size;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/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 da6fca8..af1abf0 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
@@ -77,8 +77,8 @@ public class FilterToSearchQuery {
         filter.getIsFlagged().ifPresent(isFlagged -> searchQuery.andCriteria(SearchQuery.flag(Flag.FLAGGED,
isFlagged)));
         filter.getIsUnread().ifPresent(isUnread -> searchQuery.andCriteria(SearchQuery.flag(Flag.SEEN,
!isUnread)));
         filter.getIsForwarded().ifPresent(isForwarded -> searchQuery.andCriteria(SearchQuery.flagSet(Keyword.FORWARDED.getFlagName(),
isForwarded)));
-        filter.getMaxSize().ifPresent(maxSize -> searchQuery.andCriteria(SearchQuery.sizeLessThan(maxSize)));
-        filter.getMinSize().ifPresent(minSize -> searchQuery.andCriteria(SearchQuery.sizeGreaterThan(minSize)));
+        filter.getMaxSize().ifPresent(maxSize -> searchQuery.andCriteria(SearchQuery.sizeLessThan(maxSize.asLong())));
+        filter.getMinSize().ifPresent(minSize -> searchQuery.andCriteria(SearchQuery.sizeGreaterThan(minSize.asLong())));
         filter.getHasAttachment().ifPresent(hasAttachment -> searchQuery.andCriteria(SearchQuery.hasAttachment(hasAttachment)));
         filter.getHasKeyword().ifPresent(hasKeyword -> {
             keywordQuery(hasKeyword, true).ifPresent(hasKeywordCriterion

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
index 0632dda..b2e9d81 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/AttachmentTest.java
@@ -53,7 +53,8 @@ public class AttachmentTest {
     
     @Test
     public void buildShouldWorkWhenMandatoryFieldsArePresent() {
-        Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.empty(),
123, Optional.empty(), false, Optional.empty(), Optional.empty());
+        Number attachmentSize = Number.fromLong(123);
+        Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.empty(),
attachmentSize, Optional.empty(), false, Optional.empty(), Optional.empty());
         Attachment tested = Attachment.builder()
             .blobId(BlobId.of("blobId"))
             .type("type")
@@ -64,7 +65,11 @@ public class AttachmentTest {
 
     @Test
     public void buildShouldWorkWithAllFieldsSet() {
-        Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.of("name"),
123, Optional.of("cid"), true, Optional.of(456L), Optional.of(789L));
+        Number attachmentSize = Number.fromLong(123);
+        Optional<Number> attachmentWidth = Optional.of(Number.fromLong(456L));
+        Optional<Number> attachmentHeight = Optional.of(Number.fromLong(789L));
+        Attachment expected = new Attachment(BlobId.of("blobId"), "type", Optional.of("name"),
attachmentSize, Optional.of("cid"), true,
+            attachmentWidth, attachmentHeight);
         Attachment tested = Attachment.builder()
             .blobId(BlobId.of("blobId"))
             .type("type")

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
index 8cac964..d482a42 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
@@ -99,7 +99,8 @@ public class FilterConditionTest {
         Optional<String> hasKeyword = Optional.of("$Draft");
         Optional<String> notKeyword = Optional.of("$Flagged");
 
-        FilterCondition expectedFilterCondition = new FilterCondition(Optional.of(ImmutableList.of("1")),
Optional.of(ImmutableList.of("2")), Optional.of(before), Optional.of(after), Optional.of(minSize),
Optional.of(maxSize),
+        FilterCondition expectedFilterCondition = new FilterCondition(Optional.of(ImmutableList.of("1")),
Optional.of(ImmutableList.of("2")), Optional.of(before), Optional.of(after),
+                Optional.of(Number.fromInt(minSize)), Optional.of(Number.fromInt(maxSize)),
                 Optional.of(isFlagged), Optional.of(isUnread), Optional.of(isAnswered), Optional.of(isDraft),
Optional.of(isForwarded), Optional.of(hasAttachment), Optional.of(text), Optional.of(from),
                 Optional.of(to), Optional.of(cc), Optional.of(bcc), Optional.of(subject),
Optional.of(body), Optional.of(attachments), Optional.of(header),
                 hasKeyword, notKeyword);

http://git-wip-us.apache.org/repos/asf/james-project/blob/57082375/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
index c76b993..06119ff 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/NumberTest.java
@@ -90,4 +90,11 @@ public class NumberTest {
         assertThat(number.ensureLessThan(11))
             .isEqualTo(number);
     }
+
+    @Test
+    public void fromIntShouldThrowWhenOver2Pow31Value() throws Exception {
+        assertThatThrownBy(() ->
+            Number.fromInt(Integer.MAX_VALUE + 1))
+            .isInstanceOf(IllegalStateException.class);
+    }
 }
\ No newline at end of file


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