james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/6] james-project git commit: JAMES-1947 MessageMapper should support method to getApplicableFlag
Date Tue, 28 Feb 2017 03:38:13 GMT
JAMES-1947 MessageMapper should support method to getApplicableFlag


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

Branch: refs/heads/master
Commit: f7321c9fc64d5c68df28120d6513bd5ca796ae4f
Parents: adc2e3b
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Thu Feb 23 16:00:10 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 28 10:37:10 2017 +0700

----------------------------------------------------------------------
 .../mailbox/caching/CachingMessageMapper.java   |  7 ++
 .../cassandra/mail/CassandraMessageMapper.java  | 11 ++-
 .../mailbox/hbase/mail/HBaseMessageMapper.java  | 15 +++-
 .../mailbox/jcr/mail/JCRMessageMapper.java      | 13 +++
 .../mailbox/jpa/mail/JPAMessageMapper.java      |  7 ++
 .../jpa/mail/TransactionalMessageMapper.java    |  6 ++
 .../maildir/mail/MaildirMessageMapper.java      |  8 ++
 .../inmemory/mail/InMemoryMessageMapper.java    |  8 +-
 .../store/mail/AbstractMessageMapper.java       |  2 +-
 .../james/mailbox/store/mail/MessageMapper.java |  7 +-
 .../mail/utils/ApplicableFlagCalculator.java    | 71 ++++++++++++++++
 .../StoreMailboxMessageResultIteratorTest.java  |  8 +-
 .../store/TestMailboxSessionMapperFactory.java  |  5 --
 .../utils/ApplicableFlagCalculatorTest.java     | 89 ++++++++++++++++++++
 14 files changed, 246 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
index bc4443b..33433f0 100644
--- a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
+++ b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
@@ -1,8 +1,11 @@
 package org.apache.james.mailbox.caching;
+
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.mail.Flags;
+
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxCounters;
@@ -141,4 +144,8 @@ public class CachingMessageMapper implements MessageMapper {
         throw new UnsupportedOperationException("Move is not yet supported");
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        return underlying.getApplicableFlag(mailbox);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 1a93e26..639d6ed 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -78,6 +78,7 @@ public class CassandraMessageMapper implements MessageMapper {
     private final CassandraMessageIdToImapUidDAO imapUidDAO;
     private final CassandraMailboxCounterDAO mailboxCounterDAO;
     private final CassandraMailboxRecentsDAO mailboxRecentDAO;
+    private final CassandraApplicableFlagDAO applicableFlagDAO;
     private final CassandraIndexTableHandler indexTableHandler;
     private final CassandraFirstUnseenDAO firstUnseenDAO;
     private final AttachmentLoader attachmentLoader;
@@ -85,7 +86,7 @@ public class CassandraMessageMapper implements MessageMapper {
     public CassandraMessageMapper(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider,
                                   MailboxSession mailboxSession, int maxRetries, CassandraAttachmentMapper
attachmentMapper,
                                   CassandraMessageDAO messageDAO, CassandraMessageIdDAO messageIdDAO,
CassandraMessageIdToImapUidDAO imapUidDAO,
-                                  CassandraMailboxCounterDAO mailboxCounterDAO, CassandraMailboxRecentsDAO
mailboxRecentDAO,
+                                  CassandraMailboxCounterDAO mailboxCounterDAO, CassandraMailboxRecentsDAO
mailboxRecentDAO, CassandraApplicableFlagDAO applicableFlagDAO,
                                   CassandraIndexTableHandler indexTableHandler, CassandraFirstUnseenDAO
firstUnseenDAO) {
         this.uidProvider = uidProvider;
         this.modSeqProvider = modSeqProvider;
@@ -99,6 +100,7 @@ public class CassandraMessageMapper implements MessageMapper {
         this.indexTableHandler = indexTableHandler;
         this.firstUnseenDAO = firstUnseenDAO;
         this.attachmentLoader = new AttachmentLoader(attachmentMapper);
+        this.applicableFlagDAO = applicableFlagDAO;
     }
 
     @Override
@@ -271,6 +273,13 @@ public class CassandraMessageMapper implements MessageMapper {
         return uidProvider.lastUid(mailboxSession, mailbox);
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        return applicableFlagDAO.retrieveApplicableFlag((CassandraId) mailbox.getMailboxId())
+            .join()
+            .orElse(new Flags());
+    }
+
     private CompletableFuture<Void> save(Mailbox mailbox, MailboxMessage message) throws
MailboxException {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
         return messageDAO.save(message)

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
index 5d52cee..791130e 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
@@ -82,6 +82,7 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 import org.apache.james.mailbox.store.transaction.NonTransactionalMapper;
 
 import com.google.common.base.Optional;
@@ -612,10 +613,22 @@ public class HBaseMessageMapper extends NonTransactionalMapper implements
Messag
         return modSeqProvider.highestModSeq(mailboxSession, mailbox);
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        int maxBatchSize = -1;
+        boolean flaggedForDelete = true;
+        try {
+            return new ApplicableFlagCalculator(findMessagesInMailbox((HBaseId) mailbox.getMailboxId(),
maxBatchSize, flaggedForDelete))
+                .computeApplicableFlags();
+        } catch (IOException e) {
+            throw new MailboxException("Search of all message failed in mailbox " + mailbox.getName(),
e);
+        }
+    }
+
     /**
      * Save the {@link MailboxMessage} for the given {@link Mailbox} and return the {@link
MessageMetaData}
      *
-     * @param mailbox
+     * @param mailboxId
      * @param message
      * @return metaData
      * @throws MailboxException

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
index 38d2387..ee2e506 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java
@@ -35,6 +35,7 @@ import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
+import javax.mail.Flags;
 
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.util.ISO9075;
@@ -54,6 +55,7 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 
 /**
  * JCR implementation of a {@link MessageMapper}. The implementation store each
@@ -525,6 +527,17 @@ public class JCRMessageMapper extends AbstractMessageMapper implements
JCRImapCo
         }
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        int maxBatchSize = -1;
+        try {
+            return new ApplicableFlagCalculator(findMessagesInMailbox(mailbox, maxBatchSize))
+                .computeApplicableFlags();
+        } catch (RepositoryException e) {
+            throw new MailboxException("Unable to get message from in mailbox " + mailbox,
e);
+        }
+    }
+
     /**
      * Return the path to the mailbox. This path is escaped to be able to use it
      * in xpath queries

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
index 532a8be..7d0d9a7 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
@@ -52,6 +52,7 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 import org.apache.openjpa.persistence.ArgumentException;
 
 import com.google.common.base.Optional;
@@ -286,6 +287,12 @@ public class JPAMessageMapper extends JPATransactionalMapper implements
MessageM
         return messageMetadataMapper.getHighestModSeq(mailbox);
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        return new ApplicableFlagCalculator(findMessagesInMailbox((JPAId) mailbox.getMailboxId(),
-1))
+            .computeApplicableFlags();
+    }
+
     private MessageMetaData copy(Mailbox mailbox, MessageUid uid, long modSeq, MailboxMessage
original)
             throws MailboxException {
         MailboxMessage copy;

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
index ce61d43..6396f9b 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
@@ -23,6 +23,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.mail.Flags;
+
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -163,4 +165,8 @@ public class TransactionalMessageMapper implements MessageMapper {
         return messageMapper.getHighestModSeq(mailbox);
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        return messageMapper.getApplicableFlag(mailbox);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
index 4867dde..9a8d766 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java
@@ -52,6 +52,7 @@ import org.apache.james.mailbox.store.mail.AbstractMessageMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 
 public class MaildirMessageMapper extends AbstractMessageMapper {
 
@@ -348,6 +349,13 @@ public class MaildirMessageMapper extends AbstractMessageMapper {
 
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        int maxValue = -1;
+        return new ApplicableFlagCalculator(findMessagesInMailboxBetweenUIDs(mailbox, null,
MessageUid.MIN_VALUE, null, maxValue))
+            .computeApplicableFlags();
+    }
+
     /**
      * @see org.apache.james.mailbox.store.transaction.TransactionalMapper#endRequest()
      */

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
index 9d2a5a6..aacc35b 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java
@@ -43,9 +43,9 @@ import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
 
 public class InMemoryMessageMapper extends AbstractMessageMapper {
-
     private final Map<InMemoryId, Map<MessageUid, MailboxMessage>> mailboxByUid;
     private static final int INITIAL_SIZE = 256;
 
@@ -158,6 +158,12 @@ public class InMemoryMessageMapper extends AbstractMessageMapper {
         return filteredResult;
     }
 
+    @Override
+    public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+        return new ApplicableFlagCalculator(getMembershipByUidForId((InMemoryId) mailbox.getMailboxId()).values())
+            .computeApplicableFlags();
+    }
+
     public void deleteAll() {
         mailboxByUid.clear();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
index 17aa4a8..93e27c6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
@@ -71,7 +71,7 @@ public abstract class AbstractMessageMapper extends TransactionalMapper
implemen
             .unseen(countUnseenMessagesInMailbox(mailbox))
             .build();
     }
-    
+
     @Override
     public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator
flagsUpdateCalculator, MessageRange set) throws MailboxException {
         final List<UpdatedFlags> updatedFlags = new ArrayList<UpdatedFlags>();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
index 0d1b9f3..fa32c7b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
@@ -22,9 +22,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.mail.Flags;
+
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxCounters;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -167,7 +170,9 @@ public interface MessageMapper extends Mapper {
      * Return the higest mod-sequence which were used for storing a MailboxMessage in the
{@link Mailbox}
      */
     long getHighestModSeq(Mailbox mailbox) throws MailboxException;
-    
+
+    Flags getApplicableFlag(Mailbox mailbox) throws MailboxException;
+
     /**
      * Specify what data needs to get filled in a {@link MailboxMessage} before returning
it
      * 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculator.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculator.java
new file mode 100644
index 0000000..24a99bc
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculator.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.FluentIterable;
+
+public class ApplicableFlagCalculator {
+    private static Function<MailboxMessage, Flags> toFlags() {
+        return new Function<MailboxMessage, Flags>() {
+            @Override
+            public Flags apply(MailboxMessage mailboxMessage) {
+                return mailboxMessage.createFlags();
+            }
+        };
+    }
+
+    private final Iterable<MailboxMessage> mailboxMessages;
+
+    public ApplicableFlagCalculator(Iterable<MailboxMessage> mailboxMessages) {
+        Preconditions.checkNotNull(mailboxMessages);
+        this.mailboxMessages = mailboxMessages;
+    }
+
+    public Flags computeApplicableFlags() {
+        List<Flags> messageFlags = FluentIterable.from(mailboxMessages)
+            .transform(toFlags())
+            .toList();
+        return getFlags(messageFlags);
+    }
+
+    private Flags getFlags(List<Flags> messageFlags) {
+        Flags flags = new Flags();
+
+        for (Flags flag : messageFlags) {
+            flags.add(flag);
+        }
+
+        flags.remove(Flag.RECENT);
+        flags.remove(Flag.USER);
+
+        return flags;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
index 3fdbbe4..a96a6de 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
@@ -32,14 +32,15 @@ import java.util.Set;
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
+import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
@@ -180,6 +181,11 @@ public class StoreMailboxMessageResultIteratorTest {
             throw new UnsupportedOperationException();
 
         }
+
+        @Override
+        public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
+            throw new NotImplementedException();
+        }
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
index 4804e98..d7e70bd 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
@@ -210,11 +210,6 @@ public class TestMailboxSessionMapperFactory extends MailboxSessionMapperFactory
                 }
                 return builder.build();
             }
-
-            @Override
-            public Flags getApplicableFlag(MailboxId mailboxId) throws MailboxException {
-                return null;
-            }
         };
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7321c9f/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculatorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculatorTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculatorTest.java
new file mode 100644
index 0000000..2912692
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/utils/ApplicableFlagCalculatorTest.java
@@ -0,0 +1,89 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.ImmutableList;
+
+public class ApplicableFlagCalculatorTest {
+
+    private static final String USER_FLAGS_VALUE = "UserFlags";
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void constructorShouldThrowWhenNull() throws Exception {
+        expectedException.expect(NullPointerException.class);
+        new ApplicableFlagCalculator(null);
+    }
+
+    @Test
+    public void unionFlagsShouldWelWhenEmpty() throws Exception {
+        ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(ImmutableList.<MailboxMessage>of());
+
+        assertThat(calculator.computeApplicableFlags()).isEqualTo(new Flags());
+    }
+
+    @Test
+    public void unionFlagsShouldUnionAllMessageFlagsExceptRecentAndUser() throws Exception
{
+        List<MailboxMessage> mailboxMessages = ImmutableList.of(
+            createMessage(new Flags(Flag.ANSWERED)),
+            createMessage(new Flags(Flag.DELETED)),
+            createMessage(new Flags(Flag.USER)),
+            createMessage(new Flags(Flag.RECENT)),
+            createMessage(new FlagsBuilder().add(Flag.ANSWERED)
+                .add(USER_FLAGS_VALUE)
+                .build()));
+
+        ApplicableFlagCalculator calculator = new ApplicableFlagCalculator(mailboxMessages);
+
+        assertThat(calculator.computeApplicableFlags()).isEqualTo(new FlagsBuilder()
+            .add(Flag.ANSWERED, Flag.DELETED)
+            .add(USER_FLAGS_VALUE)
+            .build());
+    }
+
+    private MailboxMessage createMessage(Flags messageFlags) {
+        String content = "Any content";
+        int bodyStart = 10;
+        return new SimpleMailboxMessage(new DefaultMessageId(), new Date(), content.length(),
bodyStart,
+            new SharedByteArrayInputStream(content.getBytes()), messageFlags, new PropertyBuilder(),
TestId.of(1));
+    }
+
+}
\ No newline at end of file


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