james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [07/10] james-project git commit: MAILBOX-351 ReIndexer should allow to reIndex single message per MailboxId
Date Thu, 29 Nov 2018 03:53:21 GMT
MAILBOX-351 ReIndexer should allow to reIndex single message per MailboxId


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

Branch: refs/heads/master
Commit: 5e04df0550ae7226899ebfe882ec06ed6cf2d977
Parents: 1bd2c29
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Nov 23 15:39:44 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 29 10:52:45 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/indexer/ReIndexer.java |  2 +
 .../mailbox/tools/indexer/ReIndexerImpl.java    | 13 +++++-
 .../tools/indexer/ReIndexerPerformer.java       |  7 +---
 .../indexer/SingleMessageReindexingTask.java    | 28 ++++++++-----
 .../mailbox/tools/indexer/ThrowsReIndexer.java  |  6 ++-
 .../tools/indexer/ReIndexerImplTest.java        | 42 ++++++++++++++++++++
 6 files changed, 80 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
index 5d4dd3a..837ba38 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
@@ -38,4 +38,6 @@ public interface ReIndexer {
 
     Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException;
 
+    Task reIndex(MailboxId mailboxId, MessageUid uid) throws MailboxException;
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index d1c7b9e..761a6cb 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -80,7 +80,16 @@ public class ReIndexerImpl implements ReIndexer {
     }
 
     @Override
-    public Task reIndex(MailboxPath path, MessageUid uid) {
-        return new SingleMessageReindexingTask(reIndexerPerformer, path, uid);
+    public Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
+        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
+        return new SingleMessageReindexingTask(reIndexerPerformer, mailbox, uid);
+    }
+
+    @Override
+    public Task reIndex(MailboxId mailboxId, MessageUid uid) throws MailboxException {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
+        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+        return new SingleMessageReindexingTask(reIndexerPerformer, mailbox, uid);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index 552ddca..4e49f33 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -31,7 +31,6 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 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.MessageRange;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
@@ -99,10 +98,8 @@ public class ReIndexerPerformer {
         }
     }
 
-    Task.Result handleMessageReIndexing(MailboxPath path, MessageUid uid) throws MailboxException
{
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser());
-        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
-            .findMailboxByPath(path);
+    Task.Result handleMessageReIndexing(Mailbox mailbox, MessageUid uid) throws MailboxException
{
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(mailbox.getUser());
 
         return handleMessageReIndexing(mailboxSession, mailbox, uid);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
index 501ee6f..ef6aa07 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
@@ -25,25 +25,32 @@ import javax.inject.Inject;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SingleMessageReindexingTask implements Task {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SingleMessageReindexingTask.class);
 
     public static final String MESSAGE_RE_INDEXING = "messageReIndexing";
 
     public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation
{
-        private final MailboxPath mailboxPath;
+        private final Mailbox mailbox;
         private final MessageUid uid;
 
-        AdditionalInformation(MailboxPath mailboxPath, MessageUid uid) {
-            this.mailboxPath = mailboxPath;
+        AdditionalInformation(Mailbox mailbox, MessageUid uid) {
+            this.mailbox = mailbox;
             this.uid = uid;
         }
 
         public String getMailboxPath() {
-            return mailboxPath.asString();
+            return mailbox.generateAssociatedPath().asString();
+        }
+
+        public String getMailboxId() {
+            return mailbox.getMailboxId().serialize();
         }
 
         public long getUid() {
@@ -52,23 +59,24 @@ public class SingleMessageReindexingTask implements Task {
     }
 
     private final ReIndexerPerformer reIndexerPerformer;
-    private final MailboxPath path;
+    private final Mailbox mailbox;
     private final MessageUid uid;
     private final AdditionalInformation additionalInformation;
 
     @Inject
-    public SingleMessageReindexingTask(ReIndexerPerformer reIndexerPerformer, MailboxPath
path, MessageUid uid) {
+    public SingleMessageReindexingTask(ReIndexerPerformer reIndexerPerformer, Mailbox mailbox,
MessageUid uid) {
         this.reIndexerPerformer = reIndexerPerformer;
-        this.path = path;
+        this.mailbox = mailbox;
         this.uid = uid;
-        this.additionalInformation = new AdditionalInformation(path, uid);
+        this.additionalInformation = new AdditionalInformation(mailbox, uid);
     }
 
     @Override
     public Result run() {
         try {
-            return reIndexerPerformer.handleMessageReIndexing(path, uid);
+            return reIndexerPerformer.handleMessageReIndexing(mailbox, uid);
         } catch (MailboxException e) {
+            LOGGER.warn("Error encounteres while reindexing {} {} : {}", mailbox.getMailboxId(),
mailbox.generateAssociatedPath(), uid, e);
             return Result.PARTIAL;
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
index f5016a1..5a5173b 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
@@ -28,7 +28,6 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
 
 public class ThrowsReIndexer implements ReIndexer {
-
     @Override
     public Task reIndex(MailboxPath path) throws MailboxException {
         throw new MailboxException("Not implemented");
@@ -53,4 +52,9 @@ public class ThrowsReIndexer implements ReIndexer {
     public Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException {
         throw new MailboxException("Not implemented");
     }
+
+    @Override
+    public Task reIndex(MailboxId mailboxId, MessageUid uid) throws MailboxException {
+        throw new MailboxException("Not implemented");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5e04df05/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
index 70a74ca..1f187d3 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
@@ -161,6 +162,47 @@ public class ReIndexerImplTest {
     }
 
     @Test
+    void messageReIndexUsingMailboxIdShouldBeWellPerformed() throws Exception {
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
+        ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession)
+            .appendMessage(
+                MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
+                systemSession);
+
+        reIndexer.reIndex(mailboxId, createdMessage.getUid()).run();
+        ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class);
+        ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class);
+
+        verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(),
messageCaptor.capture());
+        verifyNoMoreInteractions(messageSearchIndex);
+
+        assertThat(mailboxCaptor.getValue()).matches(mailbox -> mailbox.getMailboxId().equals(mailboxId));
+        assertThat(messageCaptor.getValue()).matches(message -> message.getMailboxId().equals(mailboxId)
+            && message.getUid().equals(createdMessage.getUid()));
+    }
+
+    @Test
+    void messageReIndexUsingMailboxIdShouldDoNothingWhenUidNotFound() throws Exception {
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
+        MessageUid uid = MessageUid.of(36);
+
+        reIndexer.reIndex(mailboxId, uid).run();
+
+        verifyNoMoreInteractions(messageSearchIndex);
+    }
+
+    @Test
+    void messageReIndexUsingMailboxIdShouldFailWhenMailboxNotFound() {
+        MailboxId mailboxId = InMemoryId.of(42);
+        MessageUid uid = MessageUid.of(36);
+
+        assertThatThrownBy(() -> reIndexer.reIndex(mailboxId, uid))
+            .isInstanceOf(MailboxNotFoundException.class);
+    }
+
+    @Test
     void mailboxIdReIndexShouldBeWellPerformed() throws Exception {
         MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
         MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).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