james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [2/2] james-project git commit: JAMES-1818 Expose multimailboxes search in MailboxManager and remove the import from getMessageList
Date Mon, 29 Aug 2016 14:38:14 GMT
JAMES-1818 Expose multimailboxes search in MailboxManager and remove the import from getMessageList


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

Branch: refs/heads/master
Commit: 709cd707f6456820fee4449dfd4f8927935bc8a2
Parents: f26081d
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Mon Aug 29 16:12:10 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Mon Aug 29 16:12:10 2016 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxManager.java    | 15 +++++++++++++
 .../mailbox/store/StoreMailboxManager.java      |  9 ++++++++
 .../base/MailboxEventAnalyserTest.java          |  6 +++++
 .../jmap/methods/GetMessageListMethod.java      |  7 ++----
 .../FirstUserConnectionFilterThreadTest.java    |  9 ++++++++
 .../routes/UserMailboxesRoutesTest.java         | 23 ++++++++++----------
 6 files changed, 53 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index 926074b..2eac8c3 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -19,8 +19,10 @@
 
 package org.apache.james.mailbox;
 
+import java.util.Collection;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.james.mailbox.exception.BadCredentialsException;
@@ -30,10 +32,12 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.slf4j.Logger;
 
@@ -209,6 +213,17 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport
{
     List<MailboxMetaData> search(MailboxQuery expression, MailboxSession session) throws
MailboxException;
 
     /**
+     * Searches for messages matching the given query.
+     * 
+     * @param expression
+     *            not null
+     * @param session
+     *            the context for this call, not null
+     * @throws MailboxException
+     */
+    Map<MailboxId, Collection<Long>> search(MultimailboxesSearchQuery expression,
MailboxSession session) throws MailboxException;
+
+    /**
      * Does the given mailbox exist?
      * 
      * @param mailboxPath

http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 7f5bd28..e3ae3c1 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -20,10 +20,12 @@
 package org.apache.james.mailbox.store;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 
@@ -48,11 +50,13 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxMetaData.Selectability;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
@@ -597,6 +601,11 @@ public class StoreMailboxManager implements MailboxManager {
         return results;
     }
 
+    @Override
+    public Map<MailboxId, Collection<Long>> search(MultimailboxesSearchQuery
expression, MailboxSession session) throws MailboxException {
+        return index.search(session, expression);
+    }
+
     public boolean belongsToNamespaceAndUser(MailboxPath base, Mailbox mailbox) {
         if (mailbox.getUser() == null) {
             return  base.getUser() == null

http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 1e8dfa2..7ea9e0f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -66,6 +66,7 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.model.MessageResultIterator;
 import org.apache.james.mailbox.model.MimeDescriptor;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.junit.Test;
@@ -404,6 +405,11 @@ public class MailboxEventAnalyserTest {
                 List<MailboxAnnotation> mailboxAnnotations) throws MailboxException
{
         }
 
+        @Override
+        public Map<MailboxId, Collection<Long>> search(MultimailboxesSearchQuery
expression, MailboxSession session) throws MailboxException {
+            return null;
+        }
+
     };
     
     private final class MyMailboxSession implements MailboxSession {

http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
index 5fb1dae..911aa9f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
@@ -54,7 +54,6 @@ import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
-import org.apache.james.mailbox.store.search.MessageSearchIndex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,18 +76,16 @@ public class GetMessageListMethod implements Method {
     private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messageList");
 
     private final MailboxManager mailboxManager;
-    private final MessageSearchIndex messageSearchIndex;
     private final int maximumLimit;
     private final GetMessagesMethod getMessagesMethod;
     private final MailboxUtils mailboxUtils;
     private final Factory mailboxIdFactory;
 
     @Inject
-    @VisibleForTesting public GetMessageListMethod(MailboxManager mailboxManager, MessageSearchIndex
messageSearchIndex,
+    @VisibleForTesting public GetMessageListMethod(MailboxManager mailboxManager,
             @Named(MAXIMUM_LIMIT) int maximumLimit, GetMessagesMethod getMessagesMethod,
MailboxUtils mailboxUtils, MailboxId.Factory mailboxIdFactory) {
 
         this.mailboxManager = mailboxManager;
-        this.messageSearchIndex = messageSearchIndex;
         this.maximumLimit = maximumLimit;
         this.getMessagesMethod = getMessagesMethod;
         this.mailboxUtils = mailboxUtils;
@@ -123,7 +120,7 @@ public class GetMessageListMethod implements Method {
         GetMessageListResponse.Builder builder = GetMessageListResponse.builder();
         try {
             MultimailboxesSearchQuery searchQuery = convertToSearchQuery(messageListRequest);
-            Map<MailboxId, Collection<Long>> searchResults = messageSearchIndex.search(mailboxSession,
searchQuery);
+            Map<MailboxId, Collection<Long>> searchResults = mailboxManager.search(searchQuery,
mailboxSession);
             
             aggregateResults(mailboxSession, searchResults).entries().stream()
                 .sorted(comparatorFor(messageListRequest))

http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
index 8b4c273..641aa4f 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
@@ -18,8 +18,10 @@
  ****************************************************************/
 package org.apache.james.jmap;
 
+import java.util.Collection;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.james.mailbox.MailboxListener;
@@ -33,10 +35,12 @@ import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
 import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.store.SimpleMailboxSession;
 import org.apache.james.user.lib.mock.InMemoryUsersRepository;
 import org.junit.Test;
@@ -229,6 +233,11 @@ public class FirstUserConnectionFilterThreadTest {
         public boolean hasCapability(MailboxCapabilities capability) {
             return false;
         }
+
+        @Override
+        public Map<MailboxId, Collection<Long>> search(MultimailboxesSearchQuery
expression, MailboxSession session) throws MailboxException {
+            return null;
+        }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/709cd707/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 212bc3e..78198b3 100644
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.SimpleMailboxMetaData;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -549,7 +550,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnDelete() throws
Exception {
-            when(mailboxManager.search(any(), any())).thenReturn(ImmutableList.of(new SimpleMailboxMetaData(new
MailboxPath("#private", USERNAME, MAILBOX_NAME), '.')));
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(ImmutableList.of(new
SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, MAILBOX_NAME), '.')));
             doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
 
             when()
@@ -560,7 +561,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnSearch() throws
Exception {
-            when(mailboxManager.search(any(), any())).thenThrow(new RuntimeException());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new RuntimeException());
 
             when()
                 .delete(MAILBOX_NAME)
@@ -570,7 +571,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnDelete()
throws Exception {
-            when(mailboxManager.search(any(), any())).thenReturn(ImmutableList.of(new SimpleMailboxMetaData(new
MailboxPath("#private", USERNAME, MAILBOX_NAME), '.')));
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(ImmutableList.of(new
SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, MAILBOX_NAME), '.')));
             doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
 
             when()
@@ -581,7 +582,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnSearch()
throws Exception {
-            when(mailboxManager.search(any(), any())).thenThrow(new MailboxException());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new MailboxException());
 
             when()
                 .delete(MAILBOX_NAME)
@@ -601,7 +602,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenListingMailboxes()
throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(), any());
+            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class),
any());
 
             when()
                 .delete()
@@ -611,7 +612,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnMailboxExceptionWhenListingMailboxes()
throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(), any());
+            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class),
any());
 
             when()
                 .delete()
@@ -622,7 +623,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenRemovingMailboxes()
throws Exception {
-            when(mailboxManager.search(any(), any())).thenReturn(ImmutableList.of(new SimpleMailboxMetaData(new
MailboxPath("#private", USERNAME, "any"), '.')));
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(ImmutableList.of(new
SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), '.')));
             doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
 
             when()
@@ -633,7 +634,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldReturnOkOnMailboxNotFoundExceptionWhenRemovingMailboxes()
throws Exception {
-            when(mailboxManager.search(any(), any())).thenReturn(ImmutableList.of(new SimpleMailboxMetaData(new
MailboxPath("#private", USERNAME, "any"), '.')));
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(ImmutableList.of(new
SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), '.')));
             doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(),
any());
 
             when()
@@ -644,7 +645,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void deleteShouldReturnInternalErrorOnMailboxExceptionWhenRemovingMailboxes()
throws Exception {
-            when(mailboxManager.search(any(), any())).thenReturn(ImmutableList.of(new SimpleMailboxMetaData(new
MailboxPath("#private", USERNAME, "any"), '.')));
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(ImmutableList.of(new
SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), '.')));
             doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
 
             when()
@@ -675,7 +676,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void getMailboxesShouldGenerateInternalErrorOnUnknownException() throws Exception
{
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(), any());
+            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class),
any());
 
             when()
                 .get()
@@ -685,7 +686,7 @@ public class UserMailboxesRoutesTest {
 
         @Test
         public void getMailboxesShouldGenerateInternalErrorOnUnknownMailboxException() throws
Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(), any());
+            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class),
any());
 
             when()
                 .get()


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