james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [04/17] james-project git commit: JAMES-1818 Make GetMailboxesMethod to not use store api
Date Mon, 29 Aug 2016 13:28:01 GMT
JAMES-1818 Make GetMailboxesMethod to not use store api


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

Branch: refs/heads/master
Commit: 10cbc71b8dec6d6f0c1c685488cdbef43ffad315
Parents: 5405aa8
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Aug 17 14:45:50 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200

----------------------------------------------------------------------
 .../apache/james/mailbox/MessageManager.java    |  6 +++++
 .../mailbox/store/StoreMessageManager.java      |  5 ++++
 .../base/MailboxEventAnalyserTest.java          |  4 +++
 .../apache/james/jmap/utils/MailboxUtils.java   | 26 +++++++++-----------
 .../jmap/methods/GetMailboxesMethodTest.java    |  2 +-
 .../james/jmap/utils/MailboxUtilsTest.java      | 12 ++++-----
 6 files changed, 34 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
index f62e759..2c6d8f0 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
@@ -30,6 +30,7 @@ import javax.mail.Flags;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.UnsupportedCriteriaException;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -165,6 +166,11 @@ public interface MessageManager {
 
 
     /**
+     * Gets the id of the referenced mailbox
+     */
+    MailboxId getId();
+    
+    /**
      * Gets current meta data for the mailbox.<br>
      * Consolidates common calls together to allow improved performance.<br>
      * The meta-data returned should be immutable and represent the current

http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 7e57f85..f0452db 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -51,6 +51,7 @@ import org.apache.james.mailbox.exception.ReadOnlyException;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -833,4 +834,8 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
     protected MailboxACL getResolvedMailboxACL(MailboxSession mailboxSession) throws UnsupportedRightException
{
         return aclResolver.applyGlobalACL(mailbox.getACL(), new GroupFolderResolver(mailboxSession).isGroupFolder(mailbox));
     }
+    
+    public MailboxId getId() {
+        return mailbox.getMailboxId();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/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 29a6643..01e6d68 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
@@ -56,6 +56,7 @@ 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;
@@ -321,6 +322,9 @@ public class MailboxEventAnalyserTest {
 
                 }
                 
+                public MailboxId getId() {
+                    return null;
+                }
             };
         }
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
index 849e959..6197c9c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.slf4j.Logger;
@@ -61,12 +62,12 @@ public class MailboxUtils {
     public Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession
mailboxSession) {
         try {
             Optional<Role> role = Role.from(mailboxPath.getName());
-            MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailboxPath, mailboxSession);
-            String mailboxId = getMailboxId(mailboxPath, mailboxSession);
+            MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+            MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailbox, mailboxSession);
             return Optional.ofNullable(Mailbox.builder()
-                    .id(mailboxId)
+                    .id(mailbox.getId().serialize())
                     .name(getName(mailboxPath, mailboxSession))
-                    .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession))
+                    .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).map(MailboxId::serialize).orElse(null))
                     .role(role)
                     .unreadMessages(mailboxMetaData.getUnseenCount())
                     .totalMessages(mailboxMetaData.getMessageCount())
@@ -78,16 +79,13 @@ public class MailboxUtils {
         }
     }
 
-    private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws
MailboxException {
-        return mailboxMapperFactory.getMailboxMapper(mailboxSession)
-                .findMailboxByPath(mailboxPath)
-                .getMailboxId()
-                .serialize();
+    private MessageManager.MetaData getMailboxMetaData(MessageManager messageManager, MailboxSession
mailboxSession) throws MailboxException {
+        return messageManager.getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
     }
 
-    private MessageManager.MetaData getMailboxMetaData(MailboxPath mailboxPath, MailboxSession
mailboxSession) throws MailboxException {
+    private MailboxId getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession)
throws MailboxException {
         return mailboxManager.getMailbox(mailboxPath, mailboxSession)
-                .getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
+                .getId();
     }
 
     @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession)
{
@@ -112,13 +110,13 @@ public class MailboxUtils {
                 .findFirst();
     }
 
-    @VisibleForTesting String getParentIdFromMailboxPath(MailboxPath mailboxPath, MailboxSession
mailboxSession) throws MailboxException {
+    @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath,
MailboxSession mailboxSession) throws MailboxException {
         List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter());
         if (levels.size() <= 1) {
-            return null;
+            return Optional.empty();
         }
         MailboxPath parent = levels.get(levels.size() - 2);
-        return getMailboxId(parent, mailboxSession);
+        return Optional.of(getMailboxId(parent, mailboxSession));
     }
 
     public Optional<Mailbox> mailboxFromMailboxId(String mailboxId, MailboxSession
mailboxSession) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index e5af08c..a8af679 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -109,7 +109,7 @@ public class GetMailboxesMethodTest {
         MailboxManager mockedMailboxManager = mock(MailboxManager.class);
         when(mockedMailboxManager.list(any()))
             .thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name")));
-        when(mockedMailboxManager.getMailbox(any(), any()))
+        when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any()))
             .thenThrow(new MailboxException());
         GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxUtils);
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
index 4f10a04..e233e9d 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
@@ -128,8 +128,8 @@ public class MailboxUtilsTest {
         MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
 
-        String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).isNull();
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).isEmpty();
     }
 
     @Test
@@ -143,8 +143,8 @@ public class MailboxUtilsTest {
         MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.mailbox");
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
 
-        String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).isEqualTo(parentId.serialize());
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).contains(parentId);
     }
 
     @Test
@@ -160,8 +160,8 @@ public class MailboxUtilsTest {
 
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
 
-        String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).isEqualTo(parentId.serialize());
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).contains(parentId);
     }
 
     @Test


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