james-server-dev mailing list archives

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


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

Branch: refs/heads/master
Commit: 2cc43bc1fbdc79f83e8e851427f26afda6eb2e2d
Parents: 9ac7d7a
Author: tran tien duc <dtran@linagora.com>
Authored: Fri Nov 30 11:48:55 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Dec 7 07:52:50 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/StoreMailboxManager.java      |  2 +-
 .../store/event/MailboxAnnotationListener.java        | 11 ++++++++---
 .../store/event/MailboxAnnotationListenerTest.java    | 14 +++++++++-----
 3 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/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 a8fda79..7f3d040 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
@@ -248,7 +248,7 @@ public class StoreMailboxManager implements MailboxManager {
             moveBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE);
         }
         if (hasCapability(MailboxCapabilities.Annotation)) {
-            this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory),
session);
+            this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory,
this), session);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
index a1ba834..e016361 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
@@ -24,6 +24,8 @@ import javax.inject.Inject;
 
 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.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxId;
@@ -34,11 +36,13 @@ import org.slf4j.LoggerFactory;
 
 public class MailboxAnnotationListener implements MailboxListener {
     private static final Logger logger = LoggerFactory.getLogger(MailboxAnnotationListener.class);
-    private MailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private final MailboxManager mailboxManager;
 
     @Inject
-    public MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory)
{
+    public MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory,
MailboxManager mailboxManager) {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+        this.mailboxManager = mailboxManager;
     }
     
     @Override
@@ -50,7 +54,8 @@ public class MailboxAnnotationListener implements MailboxListener {
     public void event(Event event) {
         if (event instanceof EventFactory.MailboxDeletionImpl) {
             try {
-                AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(event.getSession());
+                MailboxSession mailboxSession = mailboxManager.createSystemSession(event.getUser().asString());
+                AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(mailboxSession);
                 MailboxId mailboxId = ((EventFactory.MailboxDeletionImpl) event).getMailbox().getMailboxId();
 
                 deleteRelatedAnnotations(mailboxId, annotationMapper);

http://git-wip-us.apache.org/repos/asf/james-project/blob/2cc43bc1/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 69a1257..2f77a8b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -31,6 +31,7 @@ import java.util.Optional;
 import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxAnnotation;
@@ -63,6 +64,7 @@ public class MailboxAnnotationListenerTest {
     public static final int UID_VALIDITY = 145;
     public static final TestId MAILBOX_ID = TestId.of(45);
 
+    @Mock private MailboxManager mailboxManager;
     @Mock private MailboxSessionMapperFactory mailboxSessionMapperFactory;
     @Mock private AnnotationMapper annotationMapper;
     @Mock private MailboxId mailboxId;
@@ -77,7 +79,7 @@ public class MailboxAnnotationListenerTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         mailboxSession = new MockMailboxSession("test");
-        listener = new MailboxAnnotationListener(mailboxSessionMapperFactory);
+        listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager);
         eventFactory = new EventFactory();
         mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, mailboxId);
 
@@ -86,7 +88,9 @@ public class MailboxAnnotationListenerTest {
         QuotaSize quotaSize = QuotaSize.size(456);
         deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount,
quotaSize);
 
-        when(mailboxSessionMapperFactory.getAnnotationMapper(eq(deleteEvent.getSession()))).thenReturn(annotationMapper);
+        when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
+            .thenReturn(mailboxSession);
+        when(mailboxSessionMapperFactory.getAnnotationMapper(eq(mailboxSession))).thenReturn(annotationMapper);
     }
 
     @Test
@@ -104,7 +108,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
 
         verifyNoMoreInteractions(mailboxSessionMapperFactory);
@@ -118,7 +122,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY));
@@ -135,7 +139,7 @@ public class MailboxAnnotationListenerTest {
 
         listener.event(deleteEvent);
 
-        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(deleteEvent.getSession()));
+        verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
         verify(annotationMapper).getAllAnnotations(eq(mailboxId));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
         verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY));


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