This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c75ecc3ab507b6be71d53e200a445428e25eb94b
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Mon Jan 20 10:46:25 2020 +0700

    JAMES-2997 step #13 StoreMessageIdManager should rely on StoreRightManager
    
    This enables cutting a dependency loop:
    
    searchIndex -> AttachmentLoader -> AttachmentManager -> MessageIdManager
    -> MailboxManager -> SearchIndex
    
    Note also that InMemoryIntegrationResources needs to instanciate 
PreDeletionHooks earlier.
---
 .../manager/InMemoryIntegrationResources.java      | 74 ++++++++++++++--------
 .../store/search/SimpleMessageSearchIndexTest.java |  2 +-
 .../james/mailbox/store/StoreMessageIdManager.java | 12 ++--
 .../cassandra/host/CassandraHostSystem.java        | 10 ++-
 4 files changed, 64 insertions(+), 34 deletions(-)

diff --git 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 7d702ff..61e0c8f 100644
--- 
a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ 
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -23,7 +23,9 @@ import java.util.Collection;
 import java.util.Optional;
 import java.util.function.Function;
 
+import org.apache.james.mailbox.AttachmentContentLoader;
 import org.apache.james.mailbox.MessageIdManager;
+import org.apache.james.mailbox.SessionProvider;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
@@ -124,12 +126,12 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
         }
 
         interface RequireSearchIndex {
-            RequirePreDeletionHooks 
searchIndex(Function<MailboxManagerPreInstanciationStage, MessageSearchIndex> 
searchIndex);
+            RequirePreDeletionHooks 
searchIndex(Function<MailboxManagerSearchIndexStage, MessageSearchIndex> 
searchIndex);
 
-            RequirePreDeletionHooks 
listeningSearchIndex(Function<MailboxManagerPreInstanciationStage, 
ListeningMessageSearchIndex> searchIndex);
+            RequirePreDeletionHooks 
listeningSearchIndex(Function<MailboxManagerSearchIndexStage, 
ListeningMessageSearchIndex> searchIndex);
 
             default RequirePreDeletionHooks scanningSearchIndex() {
-                return searchIndex(stage -> new 
SimpleMessageSearchIndex(stage.mapperFactory, stage.mapperFactory, new 
DefaultTextExtractor(), null));
+                return searchIndex(stage -> new 
SimpleMessageSearchIndex(stage.mapperFactory, stage.mapperFactory, new 
DefaultTextExtractor(), stage.attachmentContentLoader));
             }
         }
 
@@ -204,7 +206,7 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
         private Optional<Function<BaseQuotaComponentsStage, QuotaManager>> 
quotaManager;
         private Optional<Integer> limitAnnotationSize;
         private Optional<MessageParser> messageParser;
-        private Optional<Function<MailboxManagerPreInstanciationStage, 
MessageSearchIndex>> searchIndexFactory;
+        private Optional<Function<MailboxManagerSearchIndexStage, 
MessageSearchIndex>> searchIndexFactory;
         private 
ImmutableSet.Builder<Function<MailboxManagerPreInstanciationStage, 
PreDeletionHook>> preDeletionHooksFactories;
         private ImmutableList.Builder<MailboxListener.GroupMailboxListener> 
listenersToBeRegistered;
 
@@ -265,13 +267,13 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
         }
 
         @Override
-        public Builder 
searchIndex(Function<MailboxManagerPreInstanciationStage, MessageSearchIndex> 
searchIndex) {
+        public Builder searchIndex(Function<MailboxManagerSearchIndexStage, 
MessageSearchIndex> searchIndex) {
             this.searchIndexFactory = Optional.of(searchIndex);
             return this;
         }
 
         @Override
-        public Builder 
listeningSearchIndex(Function<MailboxManagerPreInstanciationStage, 
ListeningMessageSearchIndex> searchIndex) {
+        public Builder 
listeningSearchIndex(Function<MailboxManagerSearchIndexStage, 
ListeningMessageSearchIndex> searchIndex) {
             this.searchIndexFactory = Optional.of(stage -> {
                 ListeningMessageSearchIndex listeningMessageSearchIndex = 
searchIndex.apply(stage);
                 listenersToBeRegistered.add(listeningMessageSearchIndex);
@@ -309,28 +311,38 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
             ListeningCurrentQuotaUpdater listeningCurrentQuotaUpdater = new 
ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, eventBus, 
quotaManager);
             QuotaComponents quotaComponents = new 
QuotaComponents(maxQuotaManager, quotaManager, quotaRootResolver);
 
+            InMemoryMessageId.Factory messageIdFactory = new 
InMemoryMessageId.Factory();
+
             MailboxManagerPreInstanciationStage preInstanciationStage = new 
MailboxManagerPreInstanciationStage(mailboxSessionMapperFactory, 
sessionProvider);
-            MessageSearchIndex index = 
searchIndexFactory.get().apply(preInstanciationStage);
+            PreDeletionHooks hooks = createHooks(preInstanciationStage);
+            StoreMessageIdManager messageIdManager = new 
StoreMessageIdManager(storeRightManager, mailboxSessionMapperFactory,
+                eventBus, messageIdFactory, quotaManager, quotaRootResolver, 
hooks);
+
+            StoreAttachmentManager attachmentManager = new 
StoreAttachmentManager(mailboxSessionMapperFactory, messageIdManager);
+            MailboxManagerSearchIndexStage searchIndexStage = new 
MailboxManagerSearchIndexStage(mailboxSessionMapperFactory, sessionProvider, 
attachmentManager);
+            MessageSearchIndex index = 
searchIndexFactory.get().apply(searchIndexStage);
 
             InMemoryMailboxManager manager = new InMemoryMailboxManager(
                 mailboxSessionMapperFactory,
                 sessionProvider,
                 new JVMMailboxPathLocker(),
                 messageParser.get(),
-                new InMemoryMessageId.Factory(),
+                messageIdFactory,
                 eventBus,
                 annotationManager,
                 storeRightManager,
                 quotaComponents,
                 index,
-                createHooks(preInstanciationStage));
+                hooks);
 
             eventBus.register(listeningCurrentQuotaUpdater);
             eventBus.register(new 
MailboxAnnotationListener(mailboxSessionMapperFactory, sessionProvider));
 
             listenersToBeRegistered.build().forEach(eventBus::register);
 
-            return new InMemoryIntegrationResources(manager, 
storeRightManager, new InMemoryMessageId.Factory(), currentQuotaManager, 
quotaRootResolver, maxQuotaManager, quotaManager, index, eventBus);
+            StoreBlobManager blobManager = new 
StoreBlobManager(attachmentManager, messageIdManager, messageIdFactory);
+
+            return new InMemoryIntegrationResources(manager, 
storeRightManager, messageIdFactory, currentQuotaManager, quotaRootResolver, 
maxQuotaManager, quotaManager, messageIdManager, index, eventBus, blobManager);
         }
 
         private PreDeletionHooks 
createHooks(MailboxManagerPreInstanciationStage preInstanciationStage) {
@@ -378,6 +390,30 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
         }
     }
 
+    public static class MailboxManagerSearchIndexStage {
+        private final InMemoryMailboxSessionMapperFactory mapperFactory;
+        private final SessionProvider sessionProvider;
+        private final AttachmentContentLoader attachmentContentLoader;
+
+        MailboxManagerSearchIndexStage(InMemoryMailboxSessionMapperFactory 
mapperFactory, SessionProvider sessionProvider, AttachmentContentLoader 
attachmentContentLoader) {
+            this.mapperFactory = mapperFactory;
+            this.sessionProvider = sessionProvider;
+            this.attachmentContentLoader = attachmentContentLoader;
+        }
+
+        public InMemoryMailboxSessionMapperFactory getMapperFactory() {
+            return mapperFactory;
+        }
+
+        public SessionProvider getSessionProvider() {
+            return sessionProvider;
+        }
+
+        public AttachmentContentLoader getAttachmentContentLoader() {
+            return attachmentContentLoader;
+        }
+    }
+
     private final InMemoryMailboxManager mailboxManager;
     private final StoreRightManager storeRightManager;
     private final MessageId.Factory messageIdFactory;
@@ -390,7 +426,7 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
     private final EventBus eventBus;
     private final StoreBlobManager blobManager;
 
-    InMemoryIntegrationResources(InMemoryMailboxManager mailboxManager, 
StoreRightManager storeRightManager, MessageId.Factory messageIdFactory, 
InMemoryCurrentQuotaManager currentQuotaManager, DefaultUserQuotaRootResolver 
defaultUserQuotaRootResolver, InMemoryPerUserMaxQuotaManager maxQuotaManager, 
QuotaManager quotaManager, MessageSearchIndex searchIndex, EventBus eventBus) {
+    InMemoryIntegrationResources(InMemoryMailboxManager mailboxManager, 
StoreRightManager storeRightManager, MessageId.Factory messageIdFactory, 
InMemoryCurrentQuotaManager currentQuotaManager, DefaultUserQuotaRootResolver 
defaultUserQuotaRootResolver, InMemoryPerUserMaxQuotaManager maxQuotaManager, 
QuotaManager quotaManager, StoreMessageIdManager storeMessageIdManager, 
MessageSearchIndex searchIndex, EventBus eventBus, StoreBlobManager 
blobManager) {
         this.mailboxManager = mailboxManager;
         this.storeRightManager = storeRightManager;
         this.messageIdFactory = messageIdFactory;
@@ -398,22 +434,10 @@ public class InMemoryIntegrationResources implements 
IntegrationResources<StoreM
         this.defaultUserQuotaRootResolver = defaultUserQuotaRootResolver;
         this.maxQuotaManager = maxQuotaManager;
         this.quotaManager = quotaManager;
+        this.storeMessageIdManager = storeMessageIdManager;
         this.searchIndex = searchIndex;
         this.eventBus = eventBus;
-
-        this.storeMessageIdManager = new StoreMessageIdManager(
-            mailboxManager,
-            mailboxManager.getMapperFactory(),
-            mailboxManager.getEventBus(),
-            messageIdFactory,
-            quotaManager,
-            defaultUserQuotaRootResolver,
-            mailboxManager.getPreDeletionHooks());
-
-        this.blobManager = new StoreBlobManager(
-            new StoreAttachmentManager((InMemoryMailboxSessionMapperFactory) 
mailboxManager.getMapperFactory(), storeMessageIdManager),
-            storeMessageIdManager,
-            messageIdFactory);
+        this.blobManager = blobManager;
     }
 
     public DefaultUserQuotaRootResolver getDefaultUserQuotaRootResolver() {
diff --git 
a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
 
b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index 4cadd0e..40a9152 100644
--- 
a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ 
b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -40,7 +40,7 @@ class SimpleMessageSearchIndexTest extends 
AbstractMessageSearchIndexTest {
                 preInstanciationStage.getMapperFactory(),
                 preInstanciationStage.getMapperFactory(),
                 new PDFTextExtractor(),
-                null))
+                preInstanciationStage.getAttachmentContentLoader()))
             .noPreDeletionHooks()
             .storeQuotaManager()
             .build();
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 7e37bf8..cb90c15 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -30,13 +30,13 @@ import java.util.function.Predicate;
 import javax.inject.Inject;
 import javax.mail.Flags;
 
-import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.MetadataWithMailboxId;
 import org.apache.james.mailbox.ModSeq;
+import org.apache.james.mailbox.RightManager;
 import org.apache.james.mailbox.events.EventBus;
 import org.apache.james.mailbox.events.MailboxIdRegistrationKey;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -91,7 +91,7 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 
     private static final Logger LOGGER = 
LoggerFactory.getLogger(StoreMessageIdManager.class);
 
-    private final MailboxManager mailboxManager;
+    private final RightManager rightManager;
     private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
     private final EventBus eventBus;
     private final MessageId.Factory messageIdFactory;
@@ -100,10 +100,10 @@ public class StoreMessageIdManager implements 
MessageIdManager {
     private final PreDeletionHooks preDeletionHooks;
 
     @Inject
-    public StoreMessageIdManager(MailboxManager mailboxManager, 
MailboxSessionMapperFactory mailboxSessionMapperFactory,
+    public StoreMessageIdManager(RightManager rightManager, 
MailboxSessionMapperFactory mailboxSessionMapperFactory,
                                  EventBus eventBus, MessageId.Factory 
messageIdFactory,
                                  QuotaManager quotaManager, QuotaRootResolver 
quotaRootResolver, PreDeletionHooks preDeletionHooks) {
-        this.mailboxManager = mailboxManager;
+        this.rightManager = rightManager;
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
         this.eventBus = eventBus;
         this.messageIdFactory = messageIdFactory;
@@ -372,7 +372,7 @@ public class StoreMessageIdManager implements 
MessageIdManager {
         MailboxMapper mailboxMapper = 
mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
 
         for (MailboxId mailboxId : mailboxIds) {
-            boolean shouldPreserveFlags = mailboxManager.myRights(mailboxId, 
mailboxSession).contains(Right.Write);
+            boolean shouldPreserveFlags = rightManager.myRights(mailboxId, 
mailboxSession).contains(Right.Write);
             SimpleMailboxMessage copy =
                 SimpleMailboxMessage.from(mailboxMessage)
                     .mailboxId(mailboxId)
@@ -422,7 +422,7 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 
 
     private Predicate<MailboxId> hasRightsOnMailbox(MailboxSession session, 
Right... rights) {
-        return Throwing.predicate((MailboxId mailboxId) -> 
mailboxManager.myRights(mailboxId, session).contains(rights))
+        return Throwing.predicate((MailboxId mailboxId) -> 
rightManager.myRights(mailboxId, session).contains(rights))
             .fallbackTo(any -> false);
     }
 
diff --git 
a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
 
b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
index f79b732..4cb76d0 100644
--- 
a/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
+++ 
b/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
@@ -47,7 +47,9 @@ import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.MailboxManagerConfiguration;
 import org.apache.james.mailbox.store.PreDeletionHooks;
 import org.apache.james.mailbox.store.SessionProviderImpl;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
+import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.StoreRightManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
@@ -109,11 +111,15 @@ public class CassandraHostSystem extends 
JamesImapHostSystem {
         ListeningCurrentQuotaUpdater quotaUpdater = new 
ListeningCurrentQuotaUpdater(currentQuotaManager, quotaRootResolver, eventBus, 
quotaManager);
         QuotaComponents quotaComponents = new 
QuotaComponents(perUserMaxQuotaManager, quotaManager, quotaRootResolver);
 
-        MessageSearchIndex index = new SimpleMessageSearchIndex(mapperFactory, 
mapperFactory, new DefaultTextExtractor(), null);
+        StoreMessageIdManager messageIdManager = new 
StoreMessageIdManager(storeRightManager, mapperFactory, eventBus, 
messageIdFactory, quotaManager, quotaRootResolver, 
PreDeletionHooks.NO_PRE_DELETION_HOOK);
+        StoreAttachmentManager attachmentManager = new 
StoreAttachmentManager(mapperFactory, messageIdManager);
+
+        MessageSearchIndex index = new SimpleMessageSearchIndex(mapperFactory, 
mapperFactory, new DefaultTextExtractor(), attachmentManager);
 
         mailboxManager = new CassandraMailboxManager(mapperFactory, 
sessionProvider,
             new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory,
-            eventBus, annotationManager, storeRightManager, quotaComponents, 
index, MailboxManagerConfiguration.DEFAULT, 
PreDeletionHooks.NO_PRE_DELETION_HOOK);
+            eventBus, annotationManager, storeRightManager, quotaComponents, 
index, MailboxManagerConfiguration.DEFAULT,
+            PreDeletionHooks.NO_PRE_DELETION_HOOK);
 
         eventBus.register(quotaUpdater);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to