james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject james-project git commit: JAMES-2094 Move and Copy message should not save message again
Date Thu, 13 Jul 2017 16:48:56 GMT
Repository: james-project
Updated Branches:
  refs/heads/master c4e25df08 -> 985ab8647


JAMES-2094 Move and Copy message should not save message again


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

Branch: refs/heads/master
Commit: 985ab8647cea28959ac1ce64322578f6c6eb6fa8
Parents: c4e25df
Author: quynhn <qnguyen@linagora.com>
Authored: Fri Jul 7 12:16:15 2017 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Jul 13 13:29:45 2017 +0200

----------------------------------------------------------------------
 .../mail/CassandraMessageIdMapper.java          | 17 +++++++
 .../cassandra/mail/CassandraMessageMapper.java  | 23 ++++++++--
 .../mailbox/store/StoreMessageIdManager.java    |  2 +-
 .../mailbox/store/mail/MessageIdMapper.java     |  2 +
 .../store/TestMailboxSessionMapperFactory.java  |  6 +++
 .../store/mail/model/MessageIdMapperTest.java   | 48 ++++++++++++++++++++
 6 files changed, 92 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
index 0f88959..0af8c74 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
@@ -166,6 +166,23 @@ public class CassandraMessageIdMapper implements MessageIdMapper {
     }
 
     @Override
+    public void copyInMailbox(MailboxMessage mailboxMessage) throws MailboxException {
+        CassandraId mailboxId = (CassandraId) mailboxMessage.getMailboxId();
+        mailboxMapper.findMailboxById(mailboxId);
+        CassandraMessageId messageId = (CassandraMessageId) mailboxMessage.getMessageId();
+        ComposedMessageIdWithMetaData composedMessageIdWithMetaData = ComposedMessageIdWithMetaData.builder()
+                .composedMessageId(new ComposedMessageId(mailboxId, messageId, mailboxMessage.getUid()))
+                .flags(mailboxMessage.createFlags())
+                .modSeq(mailboxMessage.getModSeq())
+                .build();
+        CompletableFuture.allOf(
+                        imapUidDAO.insert(composedMessageIdWithMetaData),
+                        messageIdDAO.insert(composedMessageIdWithMetaData))
+                .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(mailboxMessage,
mailboxId))
+                .join();
+    }
+
+    @Override
     public void delete(MessageId messageId, List<MailboxId> mailboxIds) {
         CassandraMessageId cassandraMessageId = (CassandraMessageId) messageId;
         mailboxIds.stream()

http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/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 b34f03c..e782127 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
@@ -267,6 +267,13 @@ public class CassandraMessageMapper implements MessageMapper {
     public MessageMetaData add(Mailbox mailbox, MailboxMessage message) throws MailboxException
{
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 
+        save(mailbox, addUidAndModseq(message, mailboxId))
+            .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
+            .join();
+        return new SimpleMessageMetaData(message);
+    }
+
+    private MailboxMessage addUidAndModseq(MailboxMessage message, CassandraId mailboxId)
throws MailboxException {
         CompletableFuture<Optional<MessageUid>> uidFuture = uidProvider.nextUid(mailboxId);
         CompletableFuture<Optional<Long>> modseqFuture = modSeqProvider.nextModSeq(mailboxId);
         CompletableFuture.allOf(uidFuture, modseqFuture).join();
@@ -276,10 +283,7 @@ public class CassandraMessageMapper implements MessageMapper {
         message.setModSeq(modseqFuture.join()
             .orElseThrow(() -> new MailboxException("Can not find a MODSEQ to save " +
message.getMessageId() + " in " + mailboxId)));
 
-        save(mailbox, message)
-            .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
-            .join();
-        return new SimpleMessageMetaData(message);
+        return message;
     }
 
     @Override
@@ -354,7 +358,7 @@ public class CassandraMessageMapper implements MessageMapper {
     @Override
     public MessageMetaData copy(Mailbox mailbox, MailboxMessage original) throws MailboxException
{
         original.setFlags(new FlagsBuilder().add(original.createFlags()).add(Flag.RECENT).build());
-        return add(mailbox, original);
+        return setInMailbox(mailbox, original);
     }
 
     @Override
@@ -371,6 +375,15 @@ public class CassandraMessageMapper implements MessageMapper {
             .build();
     }
 
+    private MessageMetaData setInMailbox(Mailbox mailbox, MailboxMessage message) throws
MailboxException {
+        CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
+
+        insertIds(addUidAndModseq(message, mailboxId), mailboxId)
+                .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message,
mailboxId))
+                .join();
+        return new SimpleMessageMetaData(message);
+    }
+
     private CompletableFuture<Void> save(Mailbox mailbox, MailboxMessage message) throws
MailboxException {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
         return messageDAOV2.save(message)

http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 7c883bb..e44c2c9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -239,7 +239,7 @@ public class StoreMessageIdManager implements MessageIdManager {
         MessageUid uid = mailboxSessionMapperFactory.getUidProvider().nextUid(mailboxSession,
mailboxMessage.getMailboxId());
         mailboxMessage.setModSeq(modSeq);
         mailboxMessage.setUid(uid);
-        messageIdMapper.save(mailboxMessage);
+        messageIdMapper.copyInMailbox(mailboxMessage);
     }
 
     private Function<MailboxMessage, MessageResult> messageResultConverter(final MessageResult.FetchGroup
fetchGroup) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
index 495a2cc..e517e99 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageIdMapper.java
@@ -40,6 +40,8 @@ public interface MessageIdMapper {
 
     void save(MailboxMessage mailboxMessage) throws MailboxNotFoundException, MailboxException;
 
+    void copyInMailbox(MailboxMessage mailboxMessage) throws MailboxNotFoundException, MailboxException;
+
     void delete(MessageId messageId);
 
     void delete(MessageId messageId, List<MailboxId> mailboxIds);

http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/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 d7e70bd..0c048b5 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
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.exception.SubscriptionException;
 import org.apache.james.mailbox.manager.MailboxManagerFixture;
 import org.apache.james.mailbox.model.MailboxACL;
@@ -180,6 +181,11 @@ public class TestMailboxSessionMapperFactory extends MailboxSessionMapperFactory
             }
 
             @Override
+            public void copyInMailbox(MailboxMessage mailboxMessage) throws MailboxNotFoundException,
MailboxException {
+                messages.add(mailboxMessage);
+            }
+
+            @Override
             public void delete(final MessageId messageId) {
                 messages.removeAll(
                     FluentIterable.from(messages)

http://git-wip-us.apache.org/repos/asf/james-project/blob/985ab864/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
index 308baa4..cb3ba8b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
@@ -210,6 +210,54 @@ public abstract class MessageIdMapperTest {
     }
 
     @Test
+    public void copyInMailboxShouldThrowWhenMailboxDoesntExist() throws Exception {
+        message1.setUid(mapperProvider.generateMessageUid());
+        message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
+        sut.save(message1);
+
+        SimpleMailbox notPersistedMailbox = new SimpleMailbox(new MailboxPath("#private",
"benwa", "mybox"), UID_VALIDITY);
+        notPersistedMailbox.setMailboxId(mapperProvider.generateId());
+
+        SimpleMailboxMessage message1InOtherMailbox = SimpleMailboxMessage.copy(notPersistedMailbox.getMailboxId(),
message1);
+        message1InOtherMailbox.setUid(mapperProvider.generateMessageUid());
+        message1InOtherMailbox.setModSeq(mapperProvider.generateModSeq(benwaWorkMailbox));
+
+        expectedException.expect(MailboxNotFoundException.class);
+        sut.copyInMailbox(message1InOtherMailbox);
+    }
+
+    @Test
+    public void copyInMailboxShouldSaveMessageInAnotherMailbox() throws Exception {
+        message1.setUid(mapperProvider.generateMessageUid());
+        message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
+        sut.save(message1);
+
+        SimpleMailboxMessage message1InOtherMailbox = SimpleMailboxMessage.copy(benwaWorkMailbox.getMailboxId(),
message1);
+        message1InOtherMailbox.setUid(mapperProvider.generateMessageUid());
+        message1InOtherMailbox.setModSeq(mapperProvider.generateModSeq(benwaWorkMailbox));
+        sut.copyInMailbox(message1InOtherMailbox);
+
+        List<MailboxId> mailboxes = sut.findMailboxes(message1.getMessageId());
+        assertThat(mailboxes).containsOnly(benwaInboxMailbox.getMailboxId(), benwaWorkMailbox.getMailboxId());
+    }
+
+    @Test
+    public void copyInMailboxShouldWorkWhenSavingTwoTimesWithSameMessageIdAndSameMailboxId()
throws Exception {
+        message1.setUid(mapperProvider.generateMessageUid());
+        message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
+        sut.save(message1);
+        SimpleMailboxMessage copiedMessage = SimpleMailboxMessage.copy(message1.getMailboxId(),
message1);
+        copiedMessage.setUid(mapperProvider.generateMessageUid());
+        copiedMessage.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
+
+        sut.copyInMailbox(copiedMessage);
+        sut.copyInMailbox(copiedMessage);
+
+        List<MailboxId> mailboxes = sut.findMailboxes(message1.getMessageId());
+        assertThat(mailboxes).isEqualTo(ImmutableList.of(benwaInboxMailbox.getMailboxId(),
benwaInboxMailbox.getMailboxId()));
+    }
+
+    @Test
     public void deleteShouldNotThrowWhenUnknownMessage() {
         sut.delete(message1.getMessageId());
     }


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