james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [17/19] james-project git commit: JAMES-2616 replace getSession() in MessageSearchIndex
Date Fri, 07 Dec 2018 01:10:40 GMT
JAMES-2616 replace getSession() in MessageSearchIndex


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

Branch: refs/heads/master
Commit: 9ce766797307ffd2754f370b97371fca8632e388
Parents: fd2005d
Author: tran tien duc <dtran@linagora.com>
Authored: Fri Nov 30 15:37:05 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Dec 7 07:52:51 2018 +0700

----------------------------------------------------------------------
 ...lasticSearchListeningMessageSearchIndex.java |  8 +++++---
 .../ElasticSearchIntegrationTest.java           |  3 ++-
 ...icSearchListeningMessageSearchIndexTest.java |  5 ++++-
 .../lucene/search/LuceneMessageSearchIndex.java | 10 ++++++----
 .../LuceneMailboxMessageSearchIndexTest.java    |  2 +-
 .../search/LuceneMessageSearchIndexTest.java    |  3 ++-
 .../META-INF/spring/mailbox-index-lucene.xml    |  1 +
 .../store/search/LazyMessageSearchIndex.java    |  2 +-
 .../search/ListeningMessageSearchIndex.java     | 20 +++++++++++++++-----
 .../host/ElasticSearchHostSystem.java           | 11 ++++++-----
 .../host/LuceneSearchHostSystem.java            |  2 +-
 11 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index ed008ef..2b76986 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -32,6 +32,7 @@ import javax.inject.Named;
 
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.UpdatedRepresentation;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManager.MessageCapabilities;
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailbox.MailboxSession;
@@ -68,9 +69,10 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
 
     @Inject
     public ElasticSearchListeningMessageSearchIndex(MessageMapperFactory factory,
-            @Named(MailboxElasticSearchConstants.InjectionNames.MAILBOX) ElasticSearchIndexer
indexer,
-            ElasticSearchSearcher searcher, MessageToElasticSearchJson messageToElasticSearchJson)
{
-        super(factory);
+                                                    @Named(MailboxElasticSearchConstants.InjectionNames.MAILBOX)
ElasticSearchIndexer indexer,
+                                                    ElasticSearchSearcher searcher, MessageToElasticSearchJson
messageToElasticSearchJson,
+                                                    MailboxManager mailboxManager) {
+        super(factory, mailboxManager);
         this.elasticSearchIndexer = indexer;
         this.messageToElasticSearchJson = messageToElasticSearchJson;
         this.searcher = searcher;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 4dc236e..db68d9d 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -113,7 +113,8 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new InMemoryId.Factory(), storeMailboxManager.getMessageIdFactory(),
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
                 MailboxElasticSearchConstants.MESSAGE_TYPE),
-            new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
+            new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES),
+            storeMailboxManager);
 
         messageIdManager = new StoreMessageIdManager(
             storeMailboxManager,

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index df7872c..9cba34b 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -34,6 +34,7 @@ import javax.mail.Flags;
 
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.UpdatedRepresentation;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageUid;
@@ -80,10 +81,12 @@ public class ElasticSearchListeningMessageSearchIndexTest {
         MessageMapperFactory mapperFactory = mock(MessageMapperFactory.class);
         messageToElasticSearchJson = mock(MessageToElasticSearchJson.class);
         ElasticSearchSearcher elasticSearchSearcher = mock(ElasticSearchSearcher.class);
+        MailboxManager mockMailboxManager = mock(MailboxManager.class);
 
         elasticSearchIndexer = mock(ElasticSearchIndexer.class);
         
-        testee = new ElasticSearchListeningMessageSearchIndex(mapperFactory, elasticSearchIndexer,
elasticSearchSearcher, messageToElasticSearchJson);
+        testee = new ElasticSearchListeningMessageSearchIndex(mapperFactory, elasticSearchIndexer,
elasticSearchSearcher,
+            messageToElasticSearchJson, mockMailboxManager);
         session = new MockMailboxSession(USERNAME);
         users = ImmutableList.of(session.getUser());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/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 964cdc8..9d091b9 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
@@ -366,9 +366,10 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
         MessageMapperFactory factory,
         MailboxId.Factory mailboxIdFactory,
         Directory directory,
-        MessageId.Factory messageIdFactory
+        MessageId.Factory messageIdFactory,
+        MailboxManager mailboxManager
     ) throws IOException {
-        this(factory, mailboxIdFactory, directory, false, true, messageIdFactory);
+        this(factory, mailboxIdFactory, directory, false, true, messageIdFactory, mailboxManager);
     }
 
     public LuceneMessageSearchIndex(
@@ -377,9 +378,10 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
             Directory directory,
             boolean dropIndexOnStart,
             boolean lenient,
-            MessageId.Factory messageIdFactory
+            MessageId.Factory messageIdFactory,
+            MailboxManager mailboxManager
     ) throws IOException {
-        super(factory);
+        super(factory, mailboxManager);
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
         this.directory = directory;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index fdcead1..5ea228c 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -102,7 +102,7 @@ public class LuceneMailboxMessageSearchIndexTest {
         id3 = factory.generate();
         id4 = factory.generate();
         id5 = factory.generate();
-        index = new LuceneMessageSearchIndex(null, new TestId.Factory(), new RAMDirectory(),
true, useLenient(), factory);
+        index = new LuceneMessageSearchIndex(null, new TestId.Factory(), new RAMDirectory(),
true, useLenient(), factory, null);
         index.setEnableSuffixMatch(true);
         Map<String, String> headersSubject = new HashMap<>();
         headersSubject.put("Subject", "test (fwd)");

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index b7ca934..b9eeaa6 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -49,7 +49,8 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
             storeMailboxManager.getQuotaRootResolver());
         LuceneMessageSearchIndex luceneMessageSearchIndex = new LuceneMessageSearchIndex(
             storeMailboxManager.getMapperFactory(), new InMemoryId.Factory(), new RAMDirectory(),
-            storeMailboxManager.getMessageIdFactory());
+            storeMailboxManager.getMessageIdFactory(),
+            storeMailboxManager);
         storeMailboxManager.setMessageSearchIndex(luceneMessageSearchIndex);
         storeMailboxManager.addGlobalListener(luceneMessageSearchIndex, new MockMailboxSession("admin"));
         this.messageSearchIndex = luceneMessageSearchIndex;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
index 1444ad6..31c5790 100644
--- a/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
+++ b/mailbox/spring/src/test/resources/META-INF/spring/mailbox-index-lucene.xml
@@ -35,6 +35,7 @@
         <constructor-arg index="1" ref="mailboxIdFactory"/>
         <constructor-arg index="2" type="org.apache.lucene.store.Directory" ref="fsDirectory"/>
         <constructor-arg index="3" ref="messageIdFactory"/>
+        <constructor-arg index="4" ref="mailboxmanager"/>
         <property name="enableSuffixMatch" value="true"/>
     </bean>
     <bean id="fsDirectory"  class="org.apache.lucene.store.FSDirectory" factory-method="open">

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index 320c8e0..766ffd6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -61,7 +61,7 @@ public class LazyMessageSearchIndex extends ListeningMessageSearchIndex
{
     
     
     public LazyMessageSearchIndex(ListeningMessageSearchIndex index) {
-        super(index.getFactory());
+        super(index.getFactory(), index.getMailboxManager());
         this.index = index;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index f194ad3..ff5ac8e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -47,9 +48,11 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
 
     public static final int UNLIMITED = -1;
     private final MessageMapperFactory factory;
+    private final MailboxManager mailboxManager;
 
-    public ListeningMessageSearchIndex(MessageMapperFactory factory) {
+    public ListeningMessageSearchIndex(MessageMapperFactory factory, MailboxManager mailboxManager)
{
         this.factory = factory;
+        this.mailboxManager = mailboxManager;
     }
 
     /**
@@ -60,17 +63,24 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
     protected MessageMapperFactory getFactory() {
         return factory;
     }
-    
-    
+
+    /**
+     * Return the {@link MailboxManager}
+     *
+     * @return mailboxManager
+     */
+    protected MailboxManager getMailboxManager() {
+        return mailboxManager;
+    }
+
     /**
      * Process the {@link org.apache.james.mailbox.Event} and update the index if
      * something relevant is received
      */
     @Override
     public void event(Event event) {
-        final MailboxSession session = event.getSession();
-
         try {
+            MailboxSession session = mailboxManager.createSystemSession(event.getUser().asString());
             if (event instanceof MessageEvent) {
                 if (event instanceof EventFactory.AddedImpl) {
                     EventFactory.AddedImpl added = (EventFactory.AddedImpl) event;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 058c0c9..ac854a4 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -97,6 +97,10 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
         InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
         InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
+        this.mailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver(),
+                authenticator,
+                authorizator);
 
         ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
@@ -110,12 +114,9 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
                 ElasticSearchSearcher.DEFAULT_SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE),
-            new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(),
IndexAttachments.YES));
+            new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(),
IndexAttachments.YES),
+            mailboxManager);
 
-        this.mailboxManager = new InMemoryIntegrationResources()
-            .createMailboxManager(new SimpleGroupMembershipResolver(),
-                authenticator,
-                authorizator);
         this.mailboxManager.setMessageSearchIndex(searchIndex);
         this.mailboxManager.addGlobalListener(searchIndex, new MockMailboxSession("admin"));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9ce76679/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
index 9161134..b33b896 100644
--- a/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/lucenesearch/src/test/java/org/apache/james/mpt/imapmailbox/lucenesearch/host/LuceneSearchHostSystem.java
@@ -116,7 +116,7 @@ public class LuceneSearchHostSystem extends JamesImapHostSystem {
                 rightManager);
 
             FSDirectory fsDirectory = FSDirectory.open(tempFile);
-            searchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(),
fsDirectory, messageIdFactory);
+            searchIndex = new LuceneMessageSearchIndex(mapperFactory, new InMemoryId.Factory(),
fsDirectory, messageIdFactory, mailboxManager);
             searchIndex.setEnableSuffixMatch(true);
             mailboxManager.setMessageSearchIndex(searchIndex);
 


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