james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/6] james-project git commit: JAMES-1947 Applicable flags should be updated when appendMessage, save or setFlags
Date Tue, 28 Feb 2017 03:38:15 GMT
JAMES-1947 Applicable flags should be updated when appendMessage, save or setFlags


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

Branch: refs/heads/master
Commit: 443d0a41153650d50bca8beccf9f64519f4c550b
Parents: 90d8c69
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Wed Feb 22 15:24:34 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 28 10:37:10 2017 +0700

----------------------------------------------------------------------
 .../CassandraMailboxSessionMapperFactory.java   | 12 ++--
 .../mail/CassandraIndexTableHandler.java        | 15 +++--
 .../cassandra/CassandraMailboxManagerTest.java  |  5 +-
 .../CassandraSubscriptionManagerTest.java       |  5 +-
 .../cassandra/CassandraTestSystemFixture.java   |  9 ++-
 .../mail/CassandraIndexTableHandlerTest.java    | 68 +++++++++++++++++++-
 .../CassandraMailboxManagerAttachmentTest.java  |  7 +-
 .../cassandra/mail/CassandraMapperProvider.java |  7 +-
 .../cassandra/host/CassandraHostSystem.java     | 10 ++-
 9 files changed, 116 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
index 9dde162..12746f9 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
@@ -24,6 +24,7 @@ import javax.inject.Named;
 
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.cassandra.mail.CassandraAnnotationMapper;
+import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentMapper;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraIndexTableHandler;
@@ -71,13 +72,15 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
     private final CassandraMailboxDAO mailboxDAO;
     private final CassandraMailboxPathDAO mailboxPathDAO;
     private final CassandraFirstUnseenDAO firstUnseenDAO;
+    private final CassandraApplicableFlagDAO applicableFlagDAO;
     private int maxRetry;
 
     @Inject
     public CassandraMailboxSessionMapperFactory(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider, Session session,
                                                 CassandraMessageDAO messageDAO, CassandraMessageIdDAO
messageIdDAO, CassandraMessageIdToImapUidDAO imapUidDAO,
                                                 CassandraMailboxCounterDAO mailboxCounterDAO,
CassandraMailboxRecentsDAO mailboxRecentsDAO, CassandraMailboxDAO mailboxDAO,
-                                                CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO, @Named(CassandraMailboxDAO.MAX_ACL_RETRY) Integer maxRetry) {
+                                                CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO, CassandraApplicableFlagDAO applicableFlagDAO,
+                                                @Named(CassandraMailboxDAO.MAX_ACL_RETRY)
Integer maxRetry) {
         this.uidProvider = uidProvider;
         this.modSeqProvider = modSeqProvider;
         this.session = session;
@@ -89,16 +92,17 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
         this.mailboxDAO = mailboxDAO;
         this.mailboxPathDAO = mailboxPathDAO;
         this.firstUnseenDAO = firstUnseenDAO;
-        this.indexTableHandler = new CassandraIndexTableHandler(mailboxRecentsDAO, mailboxCounterDAO,
this.firstUnseenDAO);
+        this.applicableFlagDAO = applicableFlagDAO;
+        this.indexTableHandler = new CassandraIndexTableHandler(mailboxRecentsDAO, mailboxCounterDAO,
this.firstUnseenDAO, applicableFlagDAO);
         this.maxRetry = maxRetry;
     }
 
     public CassandraMailboxSessionMapperFactory(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider, Session session,
                                                 CassandraMessageDAO messageDAO, CassandraMessageIdDAO
messageIdDAO, CassandraMessageIdToImapUidDAO imapUidDAO,
                                                 CassandraMailboxCounterDAO mailboxCounterDAO,
CassandraMailboxRecentsDAO mailboxRecentsDAO, CassandraMailboxDAO mailboxDAO,
-                                                CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO) {
+                                                CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO, CassandraApplicableFlagDAO applicableFlagDAO) {
         this(uidProvider, modSeqProvider, session, messageDAO, messageIdDAO, imapUidDAO,
mailboxCounterDAO,
-            mailboxRecentsDAO, mailboxDAO, mailboxPathDAO, firstUnseenDAO, DEFAULT_MAX_RETRY);
+            mailboxRecentsDAO, mailboxDAO, mailboxPathDAO, firstUnseenDAO, applicableFlagDAO,
DEFAULT_MAX_RETRY);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java
index a980b41..5ef6b85 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java
@@ -35,14 +35,17 @@ public class CassandraIndexTableHandler {
     private final CassandraMailboxRecentsDAO mailboxRecentDAO;
     private final CassandraMailboxCounterDAO mailboxCounterDAO;
     private final CassandraFirstUnseenDAO firstUnseenDAO;
+    private final CassandraApplicableFlagDAO applicableFlagDAO;
 
     @Inject
     public CassandraIndexTableHandler(CassandraMailboxRecentsDAO mailboxRecentDAO,
                                       CassandraMailboxCounterDAO mailboxCounterDAO,
-                                      CassandraFirstUnseenDAO firstUnseenDAO) {
+                                      CassandraFirstUnseenDAO firstUnseenDAO,
+                                      CassandraApplicableFlagDAO applicableFlagDAO) {
         this.mailboxRecentDAO = mailboxRecentDAO;
         this.mailboxCounterDAO = mailboxCounterDAO;
         this.firstUnseenDAO = firstUnseenDAO;
+        this.applicableFlagDAO = applicableFlagDAO;
     }
 
     public CompletableFuture<Void> updateIndexOnDelete(ComposedMessageIdWithMetaData
composedMessageIdWithMetaData, CassandraId mailboxId) {
@@ -54,17 +57,21 @@ public class CassandraIndexTableHandler {
     }
 
     public CompletableFuture<Void> updateIndexOnAdd(MailboxMessage message, CassandraId
mailboxId) {
+        Flags flags = message.createFlags();
+
         return CompletableFuture.allOf(
             updateFirstUnseenOnAdd(mailboxId, message.createFlags(), message.getUid()),
             addRecentOnSave(mailboxId, message),
-            incrementUnseenOnSave(mailboxId, message.createFlags()),
-            mailboxCounterDAO.incrementCount(mailboxId));
+            incrementUnseenOnSave(mailboxId, flags),
+            mailboxCounterDAO.incrementCount(mailboxId),
+            applicableFlagDAO.updateApplicableFlags(mailboxId, flags));
     }
 
     public CompletableFuture<Void> updateIndexOnFlagsUpdate(CassandraId mailboxId,
UpdatedFlags updatedFlags) {
         return CompletableFuture.allOf(manageUnseenMessageCountsOnFlagsUpdate(mailboxId,
updatedFlags),
             manageRecentOnFlagsUpdate(mailboxId, updatedFlags),
-            updateFirstUnseenOnFlagsUpdate(mailboxId, updatedFlags));
+            updateFirstUnseenOnFlagsUpdate(mailboxId, updatedFlags),
+            applicableFlagDAO.updateApplicableFlags(mailboxId, updatedFlags.getNewFlags()));
     }
 
     private CompletableFuture<Void> decrementUnseenOnDelete(CassandraId mailboxId,
Flags flags) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
index afc275a..25f3134 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
@@ -25,6 +25,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathDAO;
@@ -94,6 +95,7 @@ public class CassandraMailboxManagerTest {
             CassandraMailboxDAO mailboxDAO = new CassandraMailboxDAO(CASSANDRA.getConf(),
CASSANDRA.getTypesProvider(), MAX_ACL_RETRY);
             CassandraMailboxPathDAO mailboxPathDAO = new CassandraMailboxPathDAO(CASSANDRA.getConf(),
CASSANDRA.getTypesProvider());
             CassandraFirstUnseenDAO firstUnseenDAO = new CassandraFirstUnseenDAO(CASSANDRA.getConf());
+            CassandraApplicableFlagDAO applicableFlagDAO = new CassandraApplicableFlagDAO(CASSANDRA.getConf());
 
             CassandraMailboxSessionMapperFactory mapperFactory = new CassandraMailboxSessionMapperFactory(uidProvider,
                 modSeqProvider,
@@ -105,7 +107,8 @@ public class CassandraMailboxManagerTest {
                 mailboxRecentsDAO,
                 mailboxDAO,
                 mailboxPathDAO,
-                firstUnseenDAO);
+                firstUnseenDAO,
+                applicableFlagDAO);
 
             MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
             GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
index 0a3838d..8c0948d 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
@@ -24,6 +24,7 @@ import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.mailbox.AbstractSubscriptionManagerTest;
 import org.apache.james.mailbox.SubscriptionManager;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathDAO;
@@ -60,6 +61,7 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
         CassandraMailboxDAO mailboxDAO = null;
         CassandraMailboxPathDAO mailboxPathDAO = null;
         CassandraFirstUnseenDAO firstUnseenDAO = null;
+        CassandraApplicableFlagDAO applicableFlagDAO = null;
         return new CassandraSubscriptionManager(
             new CassandraMailboxSessionMapperFactory(
                 new CassandraUidProvider(cassandra.getConf()),
@@ -72,7 +74,8 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
                 mailboxRecentsDAO,
                 mailboxDAO,
                 mailboxPathDAO,
-                firstUnseenDAO)
+                firstUnseenDAO,
+                applicableFlagDAO)
         );
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
index 553d92b..30e4dac 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraTestSystemFixture.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathDAO;
@@ -35,6 +36,7 @@ import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
 import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAnnotationModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
@@ -63,7 +65,8 @@ public class CassandraTestSystemFixture {
         new CassandraUidModule(),
         new CassandraModSeqModule(),
         new CassandraAttachmentModule(),
-        new CassandraAnnotationModule()));
+        new CassandraAnnotationModule(),
+        new CassandraApplicableFlagsModule()));
     public static final int MOD_SEQ = 452;
     public static final int MAX_ACL_RETRY = 10;
 
@@ -77,6 +80,7 @@ public class CassandraTestSystemFixture {
         CassandraMessageDAO messageDAO = new CassandraMessageDAO(CASSANDRA.getConf(), CASSANDRA.getTypesProvider(),
messageIdFactory);
         CassandraMailboxCounterDAO mailboxCounterDAO = new CassandraMailboxCounterDAO(CASSANDRA.getConf());
         CassandraMailboxRecentsDAO mailboxRecentsDAO = new CassandraMailboxRecentsDAO(CASSANDRA.getConf());
+        CassandraApplicableFlagDAO applicableFlagDAO = new CassandraApplicableFlagDAO(CASSANDRA.getConf());
 
         CassandraMailboxDAO mailboxDAO = new CassandraMailboxDAO(CASSANDRA.getConf(), CASSANDRA.getTypesProvider(),
MAX_ACL_RETRY);
         CassandraMailboxPathDAO mailboxPathDAO = new CassandraMailboxPathDAO(CASSANDRA.getConf(),
CASSANDRA.getTypesProvider());
@@ -91,7 +95,8 @@ public class CassandraTestSystemFixture {
             mailboxRecentsDAO,
             mailboxDAO,
             mailboxPathDAO,
-            firstUnseenDAO);
+            firstUnseenDAO,
+            applicableFlagDAO);
     }
 
     public static CassandraMailboxManager createMailboxManager(CassandraMailboxSessionMapperFactory
mapperFactory) throws Exception{

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandlerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandlerTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandlerTest.java
index baca0aa..8605076 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandlerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandlerTest.java
@@ -26,12 +26,15 @@ import static org.mockito.Mockito.when;
 import java.util.Optional;
 
 import javax.mail.Flags;
+import javax.mail.Flags.Flag;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.cassandra.CassandraId;
 import org.apache.james.mailbox.cassandra.CassandraMessageId;
+import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxRecentsModule;
@@ -57,6 +60,7 @@ public class CassandraIndexTableHandlerTest {
     private CassandraCluster cassandra;
     private CassandraMailboxCounterDAO mailboxCounterDAO;
     private CassandraMailboxRecentsDAO mailboxRecentsDAO;
+    private CassandraApplicableFlagDAO applicableFlagDAO;
     private CassandraFirstUnseenDAO firstUnseenDAO;
     private CassandraIndexTableHandler testee;
     private Mailbox mailbox;
@@ -67,14 +71,16 @@ public class CassandraIndexTableHandlerTest {
             new CassandraModuleComposite(
                 new CassandraMailboxCounterModule(),
                 new CassandraMailboxRecentsModule(),
-                new CassandraFirstUnseenModule()));
+                new CassandraFirstUnseenModule(),
+                new CassandraApplicableFlagsModule()));
         cassandra.ensureAllTables();
 
         mailboxCounterDAO = new CassandraMailboxCounterDAO(cassandra.getConf());
         mailboxRecentsDAO = new CassandraMailboxRecentsDAO(cassandra.getConf());
         firstUnseenDAO = new CassandraFirstUnseenDAO(cassandra.getConf());
+        applicableFlagDAO = new CassandraApplicableFlagDAO(cassandra.getConf());
 
-        testee = new CassandraIndexTableHandler(mailboxRecentsDAO, mailboxCounterDAO, firstUnseenDAO);
+        testee = new CassandraIndexTableHandler(mailboxRecentsDAO, mailboxCounterDAO, firstUnseenDAO,
applicableFlagDAO);
 
         mailbox = new SimpleMailbox(new MailboxPath("#private", "user", "name"),
             UID_VALIDITY,
@@ -211,7 +217,7 @@ public class CassandraIndexTableHandlerTest {
         testee.updateIndexOnAdd(message, MAILBOX_ID).join();
 
         testee.updateIndexOnDelete(new ComposedMessageIdWithMetaData(
-            new ComposedMessageId(MAILBOX_ID, CASSANDRA_MESSAGE_ID, MESSAGE_UID),
+                new ComposedMessageId(MAILBOX_ID, CASSANDRA_MESSAGE_ID, MESSAGE_UID),
                 new Flags(Flags.Flag.RECENT),
                 MODSEQ),
             MAILBOX_ID).join();
@@ -483,4 +489,60 @@ public class CassandraIndexTableHandlerTest {
         Optional<MessageUid> actual = firstUnseenDAO.retrieveFirstUnread(MAILBOX_ID).join();
         assertThat(actual.isPresent()).isFalse();
     }
+
+    @Test
+    public void updateIndexOnAddShouldUpdateApplicableFlag() throws Exception {
+        Flags answeredFlag = new Flags(Flag.ANSWERED);
+        MailboxMessage message = mock(MailboxMessage.class);
+        when(message.createFlags()).thenReturn(answeredFlag);
+        when(message.getUid()).thenReturn(MESSAGE_UID);
+        testee.updateIndexOnAdd(message, MAILBOX_ID).join();
+
+        Flags applicableFlag = applicableFlagDAO.retrieveApplicableFlag(MAILBOX_ID).join().get();
+
+        assertThat(applicableFlag).isEqualTo(answeredFlag);
+    }
+
+    @Test
+    public void updateIndexOnFlagsUpdateShouldUnionApplicableFlag() throws Exception {
+        Flags answeredFlag = new Flags(Flag.ANSWERED);
+        MailboxMessage message = mock(MailboxMessage.class);
+        when(message.createFlags()).thenReturn(answeredFlag);
+        when(message.getUid()).thenReturn(MESSAGE_UID);
+        testee.updateIndexOnAdd(message, MAILBOX_ID).join();
+
+        testee.updateIndexOnFlagsUpdate(MAILBOX_ID, UpdatedFlags.builder()
+            .uid(MESSAGE_UID)
+            .newFlags(new Flags(Flag.DELETED))
+            .oldFlags(answeredFlag)
+            .modSeq(MODSEQ)
+            .build()).join();
+
+        Flags applicableFlag = applicableFlagDAO.retrieveApplicableFlag(MAILBOX_ID).join().get();
+
+        assertThat(applicableFlag).isEqualTo(new FlagsBuilder().add(Flag.ANSWERED, Flag.DELETED).build());
+    }
+
+    @Test
+    public void applicableFlagShouldKeepAllFlagsEvenTheMessageRemovesFlag() throws Exception
{
+        Flags messageFlags = new Flags(Flag.ANSWERED);
+        messageFlags.add(Flag.DELETED);
+        messageFlags.add(Flag.DRAFT);
+
+        MailboxMessage message = mock(MailboxMessage.class);
+        when(message.createFlags()).thenReturn(messageFlags);
+        when(message.getUid()).thenReturn(MESSAGE_UID);
+
+        testee.updateIndexOnAdd(message, MAILBOX_ID).join();
+
+        testee.updateIndexOnFlagsUpdate(MAILBOX_ID, UpdatedFlags.builder()
+            .uid(MESSAGE_UID)
+            .newFlags(new Flags())
+            .oldFlags(messageFlags)
+            .modSeq(MODSEQ)
+            .build()).join();
+
+        Flags applicableFlag = applicableFlagDAO.retrieveApplicableFlag(MAILBOX_ID).join().get();
+        assertThat(applicableFlag).isEqualTo(new FlagsBuilder().add(Flag.ANSWERED, Flag.DRAFT,
Flag.DELETED).build());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
index fb4ca45..dbcd3e3 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.cassandra.CassandraMailboxManager;
 import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
 import org.apache.james.mailbox.cassandra.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
@@ -54,7 +55,8 @@ public class CassandraMailboxManagerAttachmentTest extends AbstractMailboxManage
             new CassandraFirstUnseenModule(),
             new CassandraModSeqModule(),
             new CassandraUidModule(),
-            new CassandraAttachmentModule()));
+            new CassandraAttachmentModule(),
+            new CassandraApplicableFlagsModule()));
     public static final int MAX_ACL_RETRY = 10;
 
     private CassandraMailboxSessionMapperFactory mailboxSessionMapperFactory;
@@ -78,7 +80,8 @@ public class CassandraMailboxManagerAttachmentTest extends AbstractMailboxManage
                 new CassandraMailboxRecentsDAO(cassandra.getConf()),
                 mailboxDAO,
                 mailboxPathDAO,
-                firstUnseenDAO);
+                firstUnseenDAO,
+                new CassandraApplicableFlagDAO(cassandra.getConf()));
         Authenticator noAuthenticator = null;
         Authorizator noAuthorizator = null;
         mailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory, noAuthenticator,
noAuthorizator, new NoMailboxPathLocker(), new MessageParser(), messageIdFactory); 

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMapperProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMapperProvider.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMapperProvider.java
index 5a6d69f..5df92b0 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMapperProvider.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMapperProvider.java
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.cassandra.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.CassandraMessageId.Factory;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAnnotationModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
@@ -66,7 +67,8 @@ public class CassandraMapperProvider implements MapperProvider {
         new CassandraUidModule(),
         new CassandraAttachmentModule(),
         new CassandraAnnotationModule(),
-        new CassandraFirstUnseenModule()));
+        new CassandraFirstUnseenModule(),
+        new CassandraApplicableFlagsModule()));
     public static final int MAX_ACL_RETRY = 10;
 
     private final MessageUidProvider messageUidProvider;
@@ -112,7 +114,8 @@ public class CassandraMapperProvider implements MapperProvider {
             new CassandraMailboxRecentsDAO(cassandra.getConf()),
             mailboxDAO,
             mailboxPathDAO,
-            firstUnseenDAO);
+            firstUnseenDAO,
+            new CassandraApplicableFlagDAO(cassandra.getConf()));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/443d0a41/mpt/impl/imap-mailbox/cassandra/src/test/java/org/apache/james/mpt/imapmailbox/cassandra/host/CassandraHostSystem.java
----------------------------------------------------------------------
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 4b21a47..cc3a65f 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
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.cassandra.CassandraMailboxManager;
 import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
 import org.apache.james.mailbox.cassandra.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
+import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathDAO;
@@ -41,6 +42,7 @@ import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
 import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAnnotationModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraApplicableFlagsModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraFirstUnseenModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
@@ -91,7 +93,8 @@ public class CassandraHostSystem extends JamesImapHostSystem {
             new CassandraSubscriptionModule(),
             new CassandraQuotaModule(),
             new CassandraAttachmentModule(),
-            new CassandraAnnotationModule());
+            new CassandraAnnotationModule(),
+            new CassandraApplicableFlagsModule());
         cassandraClusterSingleton = CassandraCluster.create(mailboxModule);
         com.datastax.driver.core.Session session = cassandraClusterSingleton.getConf();
         CassandraModSeqProvider modSeqProvider = new CassandraModSeqProvider(session);
@@ -106,11 +109,12 @@ public class CassandraHostSystem extends JamesImapHostSystem {
         CassandraMailboxDAO mailboxDAO = new CassandraMailboxDAO(session, typesProvider,
MAX_ACL_RETRY);
         CassandraMailboxPathDAO mailboxPathDAO = new CassandraMailboxPathDAO(session, typesProvider);
         CassandraFirstUnseenDAO firstUnseenDAO = new CassandraFirstUnseenDAO(session);
+        CassandraApplicableFlagDAO applicableFlagDAO = new CassandraApplicableFlagDAO(session);
 
         CassandraMailboxSessionMapperFactory mapperFactory = new CassandraMailboxSessionMapperFactory(uidProvider,
modSeqProvider, 
                 session, messageDAO, messageIdDAO, imapUidDAO, mailboxCounterDAO, mailboxRecentsDAO,
mailboxDAO, mailboxPathDAO,
-                firstUnseenDAO);
-        
+                firstUnseenDAO, applicableFlagDAO);
+
         mailboxManager = new CassandraMailboxManager(mapperFactory, authenticator, authorizator,
new JVMMailboxPathLocker(), new MessageParser(), messageIdFactory);
         QuotaRootResolver quotaRootResolver = new DefaultQuotaRootResolver(mapperFactory);
 


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