james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/21] james-project git commit: JAMES-2044 SentDateCriterion is redundant
Date Wed, 07 Jun 2017 10:46:16 GMT
JAMES-2044 SentDateCriterion is redundant


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

Branch: refs/heads/master
Commit: 81ef4293dd6913133e0ffa1f4d3bf4bbc3fd0776
Parents: fc089b9
Author: benwa <btellier@linagora.com>
Authored: Mon Jun 5 12:02:40 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:34:32 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/model/SearchQuery.java | 50 ++------------------
 .../elasticsearch/query/CriterionConverter.java |  3 --
 .../lucene/search/LuceneMessageSearchIndex.java |  3 --
 .../mailbox/store/search/MessageSearches.java   | 30 ------------
 4 files changed, 4 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/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 1ae0042..9888f15 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
@@ -52,6 +52,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class SearchQuery implements Serializable {
     private static final long serialVersionUID = 1L;
+    private static final String DATE_HEADER_NAME = "Date";
 
     /**
      * The Resolution which should get used for {@link Date} searches
@@ -344,7 +345,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateAfter(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.AFTER, date, dateResolution));
+        return headerDateAfter(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -360,7 +361,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateOn(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.ON, date, dateResolution));
+        return headerDateOn(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -377,7 +378,7 @@ public class SearchQuery implements Serializable {
      * @return <code>Criterion</code>, not null
      */
     public static Criterion sentDateBefore(Date date, DateResolution dateResolution) {
-        return new SentDateCriterion(new DateOperator(DateComparator.BEFORE, date, dateResolution));
+        return headerDateBefore(DATE_HEADER_NAME, date, dateResolution);
     }
 
     /**
@@ -1254,49 +1255,6 @@ public class SearchQuery implements Serializable {
     }
 
     /**
-     * Filters on the sent date.
-     */
-    public static class SentDateCriterion extends Criterion {
-        private static final long serialVersionUID = 1L;
-
-        private final DateOperator operator;
-
-        public SentDateCriterion(DateOperator operator) {
-            this.operator = operator;
-        }
-
-        public DateOperator getOperator() {
-            return operator;
-        }
-
-        public HeaderCriterion toHeaderCriterion() {
-            return new HeaderCriterion("Date", operator);
-        }
-
-        @Override
-        public int hashCode() {
-            return Objects.hashCode(operator);
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj instanceof SentDateCriterion) {
-                SentDateCriterion that = (SentDateCriterion) obj;
-
-                return Objects.equal(this.operator, that.operator);
-            }
-            return false;
-        }
-
-        @Override
-        public String toString() {
-            return MoreObjects.toStringHelper(this)
-                .add("operator", operator)
-                .toString();
-        }
-    }
-
-    /**
      * Filters on the mod-sequence of the messages.
      */
     public static class ModSeqCriterion extends Criterion {

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 600c335..9e06c87 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -80,9 +80,6 @@ public class CriterionConverter {
         registerCriterionConverter(SearchQuery.InternalDateCriterion.class,
             criterion -> dateRangeFilter(JsonMessageConstants.DATE, criterion.getOperator()));
 
-        registerCriterionConverter(SearchQuery.SentDateCriterion.class,
-            criterion -> dateRangeFilter(JsonMessageConstants.SENT_DATE, criterion.getOperator()));
-
         registerCriterionConverter(SearchQuery.AttachmentCriterion.class, this::convertAttachmentCriterion);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 8326cf1..91b39a6 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1267,9 +1267,6 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
             return createConjunctionQuery(crit, inMailboxes, recentUids);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             return createModSeqQuery((SearchQuery.ModSeqCriterion) criterion);
-        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
-            SearchQuery.SentDateCriterion sentDateCriterion = (SearchQuery.SentDateCriterion)
criterion;
-            return createHeaderQuery(sentDateCriterion.toHeaderCriterion());
         }
         throw new UnsupportedSearchException();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/81ef4293/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index a58e925..6cee0d4 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -201,8 +201,6 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
             result = matches((SearchQuery.AttachmentCriterion) criterion, message);
         } else if (criterion instanceof SearchQuery.ModSeqCriterion) {
             result = matches((SearchQuery.ModSeqCriterion) criterion, message);
-        } else if (criterion instanceof SearchQuery.SentDateCriterion) {
-            result = matches((SearchQuery.SentDateCriterion) criterion, message);
         } else {
             throw new UnsupportedSearchException();
         }
@@ -652,32 +650,4 @@ public class MessageSearches implements Iterable<SimpleMessageSearchIndex.Search
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
     }
 
-    private boolean matches(SearchQuery.SentDateCriterion criterion, MailboxMessage message)
throws MailboxException {
-        SearchQuery.DateOperator operator = criterion.getOperator();
-        try {
-            return matchesSentDate(operator, message);
-        } catch (IOException e) {
-            throw new MailboxException("Can not read header Date", e);
-        } catch (ParseException e) {
-            throw new MailboxException("Can not parse header Date", e);
-        }
-    }
-
-    private boolean matchesSentDate(SearchQuery.DateOperator operator, MailboxMessage message)
throws MailboxException, IOException, ParseException {
-        Date date = operator.getDate();
-        DateResolution dateResolution = operator.getDateResultion();
-        Date sentDate = toISODate(headerValue("Date", message));
-        SearchQuery.DateComparator type = operator.getType();
-        switch (type) {
-            case ON:
-                return on(sentDate, date, dateResolution);
-            case BEFORE:
-                return before(sentDate, date, dateResolution);
-            case AFTER:
-                return after(sentDate, date, dateResolution);
-            default:
-                throw new UnsupportedSearchException();
-        }
-    }
-
 }


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