You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/08 08:00:41 UTC

[22/47] james-project git commit: MAILBOX-364 EventFactory should expose a builder for MailboxDeletion event

MAILBOX-364 EventFactory should expose a builder for MailboxDeletion event


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

Branch: refs/heads/master
Commit: 7ceb951cba15df620a63f28d5dfd313527aaa430
Parents: 886ad16
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 19 12:03:00 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 8 14:40:28 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/store/event/EventFactory.java | 53 +++++++++++++++-----
 .../store/event/MailboxEventDispatcher.java     |  8 ++-
 .../event/MailboxAnnotationListenerTest.java    | 18 +++----
 3 files changed, 56 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index e87f967..a05e561 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -51,7 +51,7 @@ public class EventFactory {
         protected User user;
         protected MailboxSession.SessionId sessionId;
 
-        abstract T backReference();
+        protected abstract T backReference();
 
         public T mailbox(Mailbox mailbox) {
             path(mailbox.generateAssociatedPath());
@@ -85,7 +85,7 @@ public class EventFactory {
             return backReference();
         }
 
-        void mailboxEventChecks() {
+        protected void mailboxEventChecks() {
             Preconditions.checkState(user != null, "Field `user` is compulsory");
             Preconditions.checkState(mailboxId != null, "Field `mailboxId` is compulsory");
             Preconditions.checkState(path != null, "Field `path` is compulsory");
@@ -95,7 +95,7 @@ public class EventFactory {
 
     public static class MailboxAddedBuilder extends MailboxEventBuilder<MailboxAddedBuilder> {
         @Override
-        MailboxAddedBuilder backReference() {
+        protected MailboxAddedBuilder backReference() {
             return this;
         }
 
@@ -106,6 +106,41 @@ public class EventFactory {
         }
     }
 
+    public static class MailboxDeletionBuilder extends MailboxEventBuilder<MailboxDeletionBuilder> {
+        private QuotaRoot quotaRoot;
+        private QuotaCount deletedMessageCount;
+        private QuotaSize totalDeletedSize;
+
+        @Override
+        protected MailboxDeletionBuilder backReference() {
+            return this;
+        }
+
+        public MailboxDeletionBuilder quotaRoot(QuotaRoot quotaRoot) {
+            this.quotaRoot = quotaRoot;
+            return this;
+        }
+
+        public MailboxDeletionBuilder deletedMessageCount(QuotaCount deletedMessageCount) {
+            this.deletedMessageCount = deletedMessageCount;
+            return this;
+        }
+
+        public MailboxDeletionBuilder totalDeletedSize(QuotaSize totalDeletedSize) {
+            this.totalDeletedSize = totalDeletedSize;
+            return this;
+        }
+
+        public MailboxListener.MailboxDeletion build() {
+            mailboxEventChecks();
+            Preconditions.checkState(quotaRoot != null, "Field `quotaRoot` is compulsory");
+            Preconditions.checkState(deletedMessageCount != null, "Field `deletedMessageCount` is compulsory");
+            Preconditions.checkState(totalDeletedSize != null, "Field `totalDeletedSize` is compulsory");
+
+            return new MailboxListener.MailboxDeletion(sessionId, user, path, quotaRoot, deletedMessageCount, totalDeletedSize, mailboxId);
+        }
+    }
+
     public static class FlagsUpdatedBuilder extends MailboxEventBuilder<FlagsUpdatedBuilder> {
         private final ImmutableList.Builder<UpdatedFlags> updatedFlags;
 
@@ -124,7 +159,7 @@ public class EventFactory {
         }
 
         @Override
-        FlagsUpdatedBuilder backReference() {
+        protected FlagsUpdatedBuilder backReference() {
             return this;
         }
 
@@ -165,14 +200,8 @@ public class EventFactory {
         return new MailboxListener.MailboxRenamed(sessionId, user, from, to.getMailboxId(), to.generateAssociatedPath());
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot,
-                                                          QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return mailboxDeleted(session.getSessionId(), session.getUser(), mailbox, quotaRoot, deletedMessageCount, totalDeletedSize);
-    }
-
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession.SessionId sessionId, User user, Mailbox mailbox, QuotaRoot quotaRoot,
-                                                          QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        return new MailboxListener.MailboxDeletion(sessionId, user, mailbox.generateAssociatedPath(), quotaRoot, deletedMessageCount, totalDeletedSize, mailbox.getMailboxId());
+    public MailboxDeletionBuilder mailboxDeleted() {
+        return new MailboxDeletionBuilder();
     }
 
     public MailboxAddedBuilder mailboxAdded() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index aabd204..ca4076f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -149,7 +149,13 @@ public class MailboxEventDispatcher {
      * MailboxListener will get triggered then
      */
     public void mailboxDeleted(MailboxSession session, Mailbox mailbox, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) {
-        event(eventFactory.mailboxDeleted(session, mailbox, quotaRoot, deletedMessageCount, totalDeletedSize));
+        event(eventFactory.mailboxDeleted()
+            .mailboxSession(session)
+            .mailbox(mailbox)
+            .quotaRoot(quotaRoot)
+            .deletedMessageCount(deletedMessageCount)
+            .totalDeletedSize(totalDeletedSize)
+            .build());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ceb951c/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 1ccca6a..cb6f7e1 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
@@ -42,8 +42,6 @@ import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -69,8 +67,6 @@ public class MailboxAnnotationListenerTest {
     @Mock private AnnotationMapper annotationMapper;
     @Mock private MailboxId mailboxId;
 
-    private Mailbox mailbox;
-    private EventFactory eventFactory;
     private MailboxAnnotationListener listener;
     private MailboxListener.MailboxEvent deleteEvent;
     private MailboxSession mailboxSession;
@@ -80,13 +76,15 @@ public class MailboxAnnotationListenerTest {
         MockitoAnnotations.initMocks(this);
         mailboxSession = MailboxSessionUtil.create("test");
         listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager);
-        eventFactory = new EventFactory();
-        mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), UID_VALIDITY, mailboxId);
 
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
-        QuotaCount quotaCount = QuotaCount.count(123);
-        QuotaSize quotaSize = QuotaSize.size(456);
-        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
+        deleteEvent = new EventFactory().mailboxDeleted()
+            .mailboxSession(mailboxSession)
+            .mailboxId(mailboxId)
+            .path(MailboxPath.forUser("user", "name"))
+            .quotaRoot(QuotaRoot.quotaRoot("root", Optional.empty()))
+            .deletedMessageCount(QuotaCount.count(123))
+            .totalDeletedSize(QuotaSize.size(456))
+            .build();
 
         when(mailboxManager.createSystemSession(deleteEvent.getUser().asString()))
             .thenReturn(mailboxSession);


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