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 2018/12/19 04:10:27 UTC
[01/13] james-project git commit: MAILBOX-359 Remove never used
factory method in SimpleMailboxMetaData
Repository: james-project
Updated Branches:
refs/heads/master c0b581165 -> c739d3aec
MAILBOX-359 Remove never used factory method in SimpleMailboxMetaData
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/89917a80
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/89917a80
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/89917a80
Branch: refs/heads/master
Commit: 89917a80718f98db584211ecb005261d293205d2
Parents: c0b5811
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 17 10:55:53 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:20 2018 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/store/SimpleMailboxMetaData.java | 9 ---------
1 file changed, 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/89917a80/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
index 1c8dca8..a3d63bd 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
@@ -25,19 +25,10 @@ import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
public class SimpleMailboxMetaData implements MailboxMetaData, Comparable<MailboxMetaData> {
-
- public static MailboxMetaData createNoSelect(MailboxPath path, MailboxId mailboxId, char delimiter) {
- return new SimpleMailboxMetaData(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NOSELECT);
- }
-
private final MailboxPath path;
-
private final char delimiter;
-
private final Children inferiors;
-
private final Selectability selectability;
-
private final MailboxId mailboxId;
public SimpleMailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/13] james-project git commit: MAILBOX-359 Remove MailMessage
constructor of SimpleMessageMetaData
Posted by bt...@apache.org.
MAILBOX-359 Remove MailMessage constructor of SimpleMessageMetaData
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ecb6258c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ecb6258c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ecb6258c
Branch: refs/heads/master
Commit: ecb6258c479cf06c60016d81874664b5653b61d6
Parents: 1c3c3e5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Sat Dec 15 10:54:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:58:07 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/cassandra/mail/CassandraMessageMapper.java | 7 +++----
.../org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java | 7 +++----
.../james/mailbox/maildir/mail/MaildirMessageMapper.java | 5 ++---
.../james/mailbox/inmemory/mail/InMemoryMessageMapper.java | 5 ++---
.../james/mailbox/spamassassin/SpamAssassinListenerTest.java | 5 ++---
.../org/apache/james/mailbox/store/SimpleMessageMetaData.java | 5 -----
.../org/apache/james/mailbox/store/StoreMessageIdManager.java | 4 ++--
.../org/apache/james/mailbox/store/StoreMessageManager.java | 2 +-
.../james/mailbox/store/event/MailboxEventDispatcher.java | 3 +--
.../apache/james/mailbox/store/mail/model/MailboxMessage.java | 2 +-
.../james/mailbox/store/MessageIdManagerTestSystem.java | 2 +-
11 files changed, 18 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 300e7ef..59d9a1e 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
@@ -47,7 +47,6 @@ import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.UpdatedFlags;
import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -210,7 +209,7 @@ public class CassandraMessageMapper implements MessageMapper {
.collect(JamesCollectors.chunker(cassandraConfiguration.getExpungeChunkSize()))
.map(uidChunk -> expungeUidChunk(mailboxId, uidChunk))
.flatMap(CompletableFuture::join)
- .collect(Guavate.toImmutableMap(MailboxMessage::getUid, SimpleMessageMetaData::new));
+ .collect(Guavate.toImmutableMap(MailboxMessage::getUid, MailboxMessage::metaData));
}
private CompletableFuture<Stream<SimpleMailboxMessage>> expungeUidChunk(CassandraId mailboxId, Collection<MessageUid> uidChunk) {
@@ -260,7 +259,7 @@ public class CassandraMessageMapper implements MessageMapper {
save(mailbox, addUidAndModseq(message, mailboxId))
.thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
.join();
- return new SimpleMessageMetaData(message);
+ return message.metaData();
}
private MailboxMessage addUidAndModseq(MailboxMessage message, CassandraId mailboxId) throws MailboxException {
@@ -372,7 +371,7 @@ public class CassandraMessageMapper implements MessageMapper {
insertIds(addUidAndModseq(message, mailboxId), mailboxId)
.thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
.join();
- return new SimpleMessageMetaData(message);
+ return message.metaData();
}
private CompletableFuture<Void> save(Mailbox mailbox, MailboxMessage message) throws MailboxException {
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 88ffb5a..a42f7bb 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
@@ -45,7 +45,6 @@ import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageRange.Type;
import org.apache.james.mailbox.model.UpdatedFlags;
import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageUtils;
import org.apache.james.mailbox.store.mail.MessageUtils.MessageChangedFlags;
@@ -322,12 +321,12 @@ public class JPAMessageMapper extends JPATransactionalMapper implements MessageM
((AbstractJPAMailboxMessage) message).setMailbox(currentMailbox);
getEntityManager().persist(message);
- return new SimpleMessageMetaData(message);
+ return message.metaData();
} else {
JPAMailboxMessage persistData = new JPAMailboxMessage(currentMailbox, message.getUid(), message.getModSeq(), message);
persistData.setFlags(message.createFlags());
getEntityManager().persist(persistData);
- return new SimpleMessageMetaData(persistData);
+ return persistData.metaData();
}
} catch (PersistenceException | ArgumentException e) {
@@ -381,7 +380,7 @@ public class JPAMessageMapper extends JPATransactionalMapper implements MessageM
private Map<MessageUid, MessageMetaData> createMetaData(List<MailboxMessage> uids) {
final Map<MessageUid, MessageMetaData> data = new HashMap<>();
for (MailboxMessage m : uids) {
- data.put(m.getUid(), new SimpleMessageMetaData(m));
+ data.put(m.getUid(), m.metaData());
}
return data;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 2bd14db..d7e916a 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
@@ -47,7 +47,6 @@ import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageRange.Type;
import org.apache.james.mailbox.model.UpdatedFlags;
import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
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;
@@ -234,7 +233,7 @@ public class MaildirMessageMapper extends AbstractMessageMapper {
Map<MessageUid, MessageMetaData> uids = new HashMap<>();
for (MailboxMessage m : results) {
MessageUid uid = m.getUid();
- uids.put(uid, new SimpleMessageMetaData(m));
+ uids.put(uid, m.metaData());
delete(mailbox, m);
}
@@ -312,7 +311,7 @@ public class MaildirMessageMapper extends AbstractMessageMapper {
uid = folder.appendMessage(mailboxSession, newMessageFile.getName());
message.setUid(uid);
message.setModSeq(newMessageFile.lastModified());
- return new SimpleMessageMetaData(message);
+ return message.metaData();
} catch (MailboxException e) {
throw new MailboxException("Failure while save MailboxMessage " + message + " in Mailbox " + mailbox, e);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 a31b931..edcd7ae 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
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.mail.AbstractMessageMapper;
import org.apache.james.mailbox.store.mail.ModSeqProvider;
import org.apache.james.mailbox.store.mail.UidProvider;
@@ -145,7 +144,7 @@ public class InMemoryMessageMapper extends AbstractMessageMapper {
while (it.hasNext()) {
MailboxMessage member = it.next();
if (member.isDeleted()) {
- filteredResult.put(member.getUid(), new SimpleMessageMetaData(member));
+ filteredResult.put(member.getUid(), member.metaData());
delete(mailbox, member);
}
@@ -189,7 +188,7 @@ public class InMemoryMessageMapper extends AbstractMessageMapper {
copy.setModSeq(message.getModSeq());
getMembershipByUidForMailbox(mailbox).put(message.getUid(), copy);
- return new SimpleMessageMetaData(message);
+ return message.metaData();
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index dba49a6..0496ac5 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -47,7 +47,6 @@ import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageMoves;
import org.apache.james.mailbox.model.TestMessageId;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.mailbox.store.event.EventFactory;
@@ -238,7 +237,7 @@ public class SpamAssassinListenerTest {
public void eventShouldCallSpamAssassinHamLearningWhenTheMessageIsAddedInInbox() throws Exception {
SimpleMailboxMessage message = createMessage(inbox);
- ImmutableSortedMap<MessageUid, MessageMetaData> sortedMap = ImmutableSortedMap.of(UID, new SimpleMessageMetaData(message));
+ ImmutableSortedMap<MessageUid, MessageMetaData> sortedMap = ImmutableSortedMap.of(UID, message.metaData());
MailboxListener.Added addedEvent = new EventFactory().added(
MAILBOX_SESSION, sortedMap, inbox);
@@ -253,7 +252,7 @@ public class SpamAssassinListenerTest {
MailboxListener.Added addedEvent = new EventFactory().added(
MAILBOX_SESSION,
- ImmutableSortedMap.of(UID, new SimpleMessageMetaData(message)),
+ ImmutableSortedMap.of(UID, message.metaData()),
mailbox1);
listener.event(addedEvent);
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
index ae1566f..61e2f54 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
@@ -26,7 +26,6 @@ import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import com.google.common.base.Objects;
@@ -48,10 +47,6 @@ public class SimpleMessageMetaData implements MessageMetaData {
this.messageId = messageId;
}
- public SimpleMessageMetaData(MailboxMessage message) {
- this(message.getUid(), message.getModSeq(), message.createFlags(), message.getFullContentOctets(), message.getInternalDate(), message.getMessageId());
- }
-
@Override
public Flags getFlags() {
return flags;
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 23db5b5..907d675 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
@@ -86,7 +86,7 @@ public class StoreMessageIdManager implements MessageIdManager {
}
private static MetadataWithMailboxId toMetadataWithMailboxId(MailboxMessage message) {
- return new MetadataWithMailboxId(new SimpleMessageMetaData(message), message.getMailboxId());
+ return new MetadataWithMailboxId(message.metaData(), message.getMailboxId());
}
public static ImmutableSet<MailboxId> toMailboxIds(List<MailboxMessage> mailboxMessages) {
@@ -286,7 +286,7 @@ public class StoreMessageIdManager implements MessageIdManager {
private void removeMessageFromMailboxes(MailboxMessage message, Set<MailboxId> mailboxesToRemove, MailboxSession mailboxSession) throws MailboxException {
MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
- SimpleMessageMetaData eventPayload = new SimpleMessageMetaData(message);
+ MessageMetaData eventPayload = message.metaData();
for (MailboxId mailboxId: mailboxesToRemove) {
messageIdMapper.delete(message.getMessageId(), mailboxesToRemove);
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 58f0d08..76595af 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -720,7 +720,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
while (originalRows.hasNext()) {
final MailboxMessage originalMessage = originalRows.next();
- originalRowsCopy.add(new SimpleMessageMetaData(originalMessage));
+ originalRowsCopy.add(originalMessage.metaData());
MessageMetaData data = messageMapper.execute(
() -> messageMapper.move(getMailboxEntity(), originalMessage));
movedRows.add(data);
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/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 1ebe27e..139c807 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
@@ -44,7 +44,6 @@ import org.apache.james.mailbox.model.MessageMoves;
import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -89,7 +88,7 @@ public class MailboxEventDispatcher {
}
public void added(MailboxSession session, Mailbox mailbox, MailboxMessage mailboxMessage) {
- SimpleMessageMetaData messageMetaData = new SimpleMessageMetaData(mailboxMessage);
+ MessageMetaData messageMetaData = mailboxMessage.metaData();
SortedMap<MessageUid, MessageMetaData> metaDataMap = ImmutableSortedMap.<MessageUid, MessageMetaData>naturalOrder()
.put(messageMetaData.getUid(), messageMetaData)
.build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
index e9e13ad..2842356 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
@@ -129,7 +129,7 @@ public interface MailboxMessage extends Message, Comparable<MailboxMessage> {
Flags createFlags();
default MessageMetaData metaData() {
- return new SimpleMessageMetaData(this);
+ return new SimpleMessageMetaData(getUid(), getModSeq(), createFlags(), getFullContentOctets(), getInternalDate(), getMessageId());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/ecb6258c/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index 21de9e1..f195e92 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -81,7 +81,7 @@ public class MessageIdManagerTestSystem {
Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
MailboxMessage message = createMessage(mailboxId, flags, messageId, uid);
mapperFactory.getMessageMapper(mailboxSession).add(mailbox, message);
- mailboxManager.getEventDispatcher().added(mailboxSession, new SimpleMessageMetaData(message), mailbox);
+ mailboxManager.getEventDispatcher().added(mailboxSession, message.metaData(), mailbox);
return messageId;
} catch (Exception e) {
throw new RuntimeException(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/13] james-project git commit: MAILBOX-359 Rework MailboxMetaData
equals, hashCode & toString
Posted by bt...@apache.org.
MAILBOX-359 Rework MailboxMetaData equals, hashCode & toString
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/86f03be8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86f03be8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86f03be8
Branch: refs/heads/master
Commit: 86f03be81dd6a5951e4b5ff8a1047671e0d0a48e
Parents: c25596d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 18 11:35:15 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:21 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/model/MailboxMetaData.java | 41 ++++++++------------
1 file changed, 16 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f03be8/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
index 355beb8..3d014c5 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
@@ -19,8 +19,12 @@
package org.apache.james.mailbox.model;
+import java.util.Objects;
+
import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
+import com.google.common.base.MoreObjects;
+
/**
* Returned by the list method of MailboxRepository and others
*/
@@ -120,37 +124,24 @@ public class MailboxMetaData implements Comparable<MailboxMetaData> {
@Override
public String toString() {
- return "ListResult: " + path;
+ return MoreObjects.toStringHelper(this)
+ .add("path", path)
+ .toString();
}
@Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((path == null) ? 0 : path.hashCode());
- return result;
+ public final boolean equals(Object o) {
+ if (o instanceof MailboxMetaData) {
+ MailboxMetaData that = (MailboxMetaData) o;
+
+ return Objects.equals(this.path, that.path);
+ }
+ return false;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final MailboxMetaData other = (MailboxMetaData) obj;
- if (path == null) {
- if (other.path != null) {
- return false;
- }
- } else if (!path.equals(other.path)) {
- return false;
- }
- return true;
+ public final int hashCode() {
+ return Objects.hash(path);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/13] james-project git commit: MAILBOX-359 Implement
MailboxMetaData::unselectableMailbox as a static method
Posted by bt...@apache.org.
MAILBOX-359 Implement MailboxMetaData::unselectableMailbox as a static method
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6000b488
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6000b488
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6000b488
Branch: refs/heads/master
Commit: 6000b488d66ce1ac7771d9d0f6e6b2f53f28436e
Parents: 86f03be
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 18 11:48:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:21 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/mailbox/model/MailboxMetaData.java | 9 ++++-----
.../org/apache/james/jmap/model/MailboxFactoryTest.java | 2 +-
.../james/webadmin/routes/UserMailboxesRoutesTest.java | 10 +++++-----
3 files changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6000b488/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
index 3d014c5..040a8ef 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
@@ -61,18 +61,17 @@ public class MailboxMetaData implements Comparable<MailboxMetaData> {
HAS_NO_CHILDREN
}
+ public static MailboxMetaData unselectableMailbox(MailboxPath path, MailboxId mailboxId, char delimiter) {
+ return new MailboxMetaData(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
+ }
+
private final MailboxPath path;
private final char delimiter;
private final Children inferiors;
private final Selectability selectability;
private final MailboxId mailboxId;
- public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
- this(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
- }
-
public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter, Children inferiors, Selectability selectability) {
- super();
this.path = path;
this.mailboxId = mailboxId;
this.delimiter = delimiter;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6000b488/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
index d213045..0f508a7 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
@@ -173,7 +173,7 @@ public class MailboxFactoryTest {
mailboxManager.createMailbox(mailboxPath, mailboxSession);
Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath,
- Optional.of(ImmutableList.of(new MailboxMetaData(parentMailboxPath, parentId, DELIMITER))),
+ Optional.of(ImmutableList.of(MailboxMetaData.unselectableMailbox(parentMailboxPath, parentId, DELIMITER))),
mailboxSession);
assertThat(id).contains(parentId);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6000b488/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 1c60d93..562b293 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -774,7 +774,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new MailboxMetaData(
+ MailboxMetaData.unselectableMailbox(
MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
@@ -800,7 +800,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new MailboxMetaData(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
+ MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -856,7 +856,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -870,7 +870,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -884,7 +884,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/13] james-project git commit: MAILBOX-362 Group all non event
DTOs to DTOs scala file
Posted by bt...@apache.org.
MAILBOX-362 Group all non event DTOs to DTOs scala file
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8eaf1f64
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8eaf1f64
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8eaf1f64
Branch: refs/heads/master
Commit: 8eaf1f6416ffd1432c98f53857b5a9147f1840de
Parents: 892f95a
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:07:23 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:53 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/event/json/DTOs.scala | 54 ++++++++++++++++++++
.../james/event/json/EventSerializer.scala | 54 +++++---------------
2 files changed, 68 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8eaf1f64/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
new file mode 100644
index 0000000..8d8af9e
--- /dev/null
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
@@ -0,0 +1,54 @@
+/****************************************************************
+ * 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.event.json
+
+import org.apache.james.core.quota.QuotaValue
+import org.apache.james.mailbox.model.{MailboxPath => JavaMailboxPath, Quota => JavaQuota}
+
+import scala.collection.JavaConverters._
+
+object DTOs {
+ object MailboxPath {
+ def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = MailboxPath(
+ Option(javaMailboxPath.getNamespace),
+ Option(javaMailboxPath.getUser),
+ javaMailboxPath.getName)
+ }
+
+ object Quota {
+ def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): Quota[T] = Quota(
+ used = java.getUsed,
+ limit = java.getLimit,
+ limits = java.getLimitByScope.asScala.toMap)
+ }
+
+ case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
+ def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
+ }
+
+ case class Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
+ def toJava: JavaQuota[T] =
+ JavaQuota.builder[T]
+ .used(used)
+ .computedLimit(limit)
+ .limitsByScope(limits.asJava)
+ .build()
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8eaf1f64/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 9c89b58..544859b 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -25,40 +25,19 @@ import java.util.Optional
import julienrf.json.derived
import org.apache.james.core.quota.{QuotaCount, QuotaSize, QuotaValue}
import org.apache.james.core.{Domain, User}
+import org.apache.james.event.json.DTOs.{MailboxPath, Quota}
import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, MailboxDeletion => JavaMailboxDeletion, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
import org.apache.james.mailbox.MailboxSession.SessionId
-import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, MailboxPath => JavaMailboxPath, Quota => JavaQuota}
+import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, Quota => JavaQuota}
import org.apache.james.mailbox.{Event => JavaEvent}
import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsString, JsSuccess, Json, OFormat, Reads, Writes}
-import scala.collection.JavaConverters._
-
private sealed trait Event {
def toJava: JavaEvent
}
private object DTO {
- object MailboxPath {
- def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = DTO.MailboxPath(
- Option(javaMailboxPath.getNamespace),
- Option(javaMailboxPath.getUser),
- javaMailboxPath.getName)
- }
-
- case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
- def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
- }
-
- case class Quota[T <: QuotaValue[T]](used: T, limit: T, limits: Map[JavaQuota.Scope, T]) {
- def toJava: JavaQuota[T] =
- JavaQuota.builder[T]
- .used(used)
- .computedLimit(limit)
- .limitsByScope(limits.asJava)
- .build()
- }
-
case class QuotaUsageUpdatedEvent(user: User, quotaRoot: QuotaRoot, countQuota: Quota[QuotaCount],
sizeQuota: Quota[QuotaSize], time: Instant) extends Event {
override def toJava: JavaEvent = new JavaQuotaUsageUpdatedEvent(user, quotaRoot, countQuota.toJava, sizeQuota.toJava, time)
@@ -81,20 +60,15 @@ private object DTO {
}
private object ScalaConverter {
- private def toScala[T <: QuotaValue[T]](java: JavaQuota[T]): DTO.Quota[T] = DTO.Quota(
- used = java.getUsed,
- limit = java.getLimit,
- limits = java.getLimitByScope.asScala.toMap)
-
private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
user = event.getUser,
quotaRoot = event.getQuotaRoot,
- countQuota = toScala(event.getCountQuota),
- sizeQuota = toScala(event.getSizeQuota),
+ countQuota = Quota.toScala(event.getCountQuota),
+ sizeQuota = Quota.toScala(event.getSizeQuota),
time = event.getInstant)
private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
- mailboxPath = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
mailboxId = event.getMailboxId,
user = event.getUser,
sessionId = event.getSessionId)
@@ -102,15 +76,15 @@ private object ScalaConverter {
private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
sessionId = event.getSessionId,
user = event.getUser,
- path = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ path = MailboxPath.fromJava(event.getMailboxPath),
mailboxId = event.getMailboxId,
- newPath = DTO.MailboxPath.fromJava(event.getNewPath))
+ newPath = MailboxPath.fromJava(event.getNewPath))
private def toScala(event: JavaMailboxDeletion): DTO.MailboxDeletion = DTO.MailboxDeletion(
sessionId = event.getSessionId,
user = event.getUser,
quotaRoot = event.getQuotaRoot,
- path = DTO.MailboxPath.fromJava(event.getMailboxPath),
+ path = MailboxPath.fromJava(event.getMailboxPath),
deletedMessageCount = event.getDeletedMessageCount,
totalDeletedSize = event.getTotalDeletedSize,
mailboxId = event.getMailboxId)
@@ -129,9 +103,9 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
implicit val quotaRootWrites: Writes[QuotaRoot] = quotaRoot => JsString(quotaRoot.getValue)
implicit val quotaValueWrites: Writes[QuotaValue[_]] = value => if (value.isUnlimited) JsNull else JsNumber(value.asLong())
implicit val quotaScopeWrites: Writes[JavaQuota.Scope] = value => JsString(value.name)
- implicit val quotaCountWrites: Writes[DTO.Quota[QuotaCount]] = Json.writes[DTO.Quota[QuotaCount]]
- implicit val quotaSizeWrites: Writes[DTO.Quota[QuotaSize]] = Json.writes[DTO.Quota[QuotaSize]]
- implicit val mailboxPathWrites: Writes[DTO.MailboxPath] = Json.writes[DTO.MailboxPath]
+ implicit val quotaCountWrites: Writes[Quota[QuotaCount]] = Json.writes[Quota[QuotaCount]]
+ implicit val quotaSizeWrites: Writes[Quota[QuotaSize]] = Json.writes[Quota[QuotaSize]]
+ implicit val mailboxPathWrites: Writes[MailboxPath] = Json.writes[MailboxPath]
implicit val mailboxIdWrites: Writes[MailboxId] = value => JsString(value.serialize())
implicit val sessionIdWrites: Writes[SessionId] = value => JsNumber(value.getValue)
@@ -176,9 +150,9 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
}
- implicit val quotaCReads: Reads[DTO.Quota[QuotaCount]] = Json.reads[DTO.Quota[QuotaCount]]
- implicit val quotaSReads: Reads[DTO.Quota[QuotaSize]] = Json.reads[DTO.Quota[QuotaSize]]
- implicit val mailboxPathReads: Reads[DTO.MailboxPath] = Json.reads[DTO.MailboxPath]
+ implicit val quotaCReads: Reads[Quota[QuotaCount]] = Json.reads[Quota[QuotaCount]]
+ implicit val quotaSReads: Reads[Quota[QuotaSize]] = Json.reads[Quota[QuotaSize]]
+ implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[MailboxPath]
implicit val eventOFormat: OFormat[Event] = derived.oformat()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/13] james-project git commit: MAILBOX-359 A MailboxMessage should
give its MessageMetaData
Posted by bt...@apache.org.
MAILBOX-359 A MailboxMessage should give its MessageMetaData
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ef2c68c7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ef2c68c7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ef2c68c7
Branch: refs/heads/master
Commit: ef2c68c71731c0fe18ca06c5161b186daec37118
Parents: e25c247
Author: Benoit Tellier <bt...@linagora.com>
Authored: Sat Dec 15 10:05:10 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:56:44 2018 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/store/mail/model/MailboxMessage.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ef2c68c7/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
index 556ee4b..e9e13ad 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
@@ -23,6 +23,8 @@ import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.store.SimpleMessageMetaData;
/**
* A MIME message, consisting of meta-data (including MIME headers)
@@ -126,5 +128,8 @@ public interface MailboxMessage extends Message, Comparable<MailboxMessage> {
*/
Flags createFlags();
+ default MessageMetaData metaData() {
+ return new SimpleMessageMetaData(this);
+ }
}
\ 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
[03/13] james-project git commit: MAILBOX-359 POJOify MailboxMetaData
Posted by bt...@apache.org.
MAILBOX-359 POJOify MailboxMetaData
That way, the Mailbox API is all we need to instanciate this POJO
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c25596df
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c25596df
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c25596df
Branch: refs/heads/master
Commit: c25596dfdba4c970dcd1de1638f18b29d68825fa
Parents: 89917a8
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 17 11:06:40 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:21 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/model/MailboxMetaData.java | 98 +++++++++++++--
.../mailbox/store/SimpleMailboxMetaData.java | 120 -------------------
.../mailbox/store/StoreMailboxManager.java | 4 +-
.../james/imap/processor/ListProcessor.java | 33 +----
.../james/jmap/model/MailboxFactoryTest.java | 4 +-
.../routes/UserMailboxesRoutesTest.java | 12 +-
6 files changed, 101 insertions(+), 170 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
index 14d1ee7..355beb8 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
@@ -19,21 +19,24 @@
package org.apache.james.mailbox.model;
+import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
+
/**
* Returned by the list method of MailboxRepository and others
*/
-public interface MailboxMetaData {
-
+public class MailboxMetaData implements Comparable<MailboxMetaData> {
/** RFC3501 Selectability flag */
- enum Selectability {
+ public enum Selectability {
NONE, MARKED, UNMARKED, NOSELECT
}
/**
* Indicates whether this mailbox allows children and - if so - whether it
* has any.
+ *
+ * See <code>\Noinferiors</code> as per RFC3501.
*/
- enum Children {
+ public enum Children {
/**
* No children allowed.
*/
@@ -54,31 +57,104 @@ public interface MailboxMetaData {
HAS_NO_CHILDREN
}
+ private final MailboxPath path;
+ private final char delimiter;
+ private final Children inferiors;
+ private final Selectability selectability;
+ private final MailboxId mailboxId;
+
+ public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
+ this(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
+ }
+
+ public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter, Children inferiors, Selectability selectability) {
+ super();
+ this.path = path;
+ this.mailboxId = mailboxId;
+ this.delimiter = delimiter;
+ this.inferiors = inferiors;
+ this.selectability = selectability;
+ }
+
+
/**
* Gets the inferiors status of this mailbox.
- *
+ *
+ * Is this mailbox <code>\Noinferiors</code> as per RFC3501.
+ *
* @return not null
*/
- Children inferiors();
+ public final Children inferiors() {
+ return inferiors;
+ }
/**
* Gets the RFC3501 Selectability flag.
*/
- Selectability getSelectability();
+ public final Selectability getSelectability() {
+ return selectability;
+ }
/**
* Return the delimiter
*
* @return delimiter
*/
- char getHierarchyDelimiter();
+ public char getHierarchyDelimiter() {
+ return delimiter;
+ }
+
/**
* Return the MailboxPath
*
* @return path
*/
- MailboxPath getPath();
-
- MailboxId getId();
+ public MailboxPath getPath() {
+ return path;
+ }
+
+ public MailboxId getId() {
+ return mailboxId;
+ }
+
+ @Override
+ public String toString() {
+ return "ListResult: " + path;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final MailboxMetaData other = (MailboxMetaData) obj;
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int compareTo(MailboxMetaData o) {
+ return StandardMailboxMetaDataComparator.order(this, o);
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
deleted file mode 100644
index a3d63bd..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************
- * 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;
-
-import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-
-public class SimpleMailboxMetaData implements MailboxMetaData, Comparable<MailboxMetaData> {
- private final MailboxPath path;
- private final char delimiter;
- private final Children inferiors;
- private final Selectability selectability;
- private final MailboxId mailboxId;
-
- public SimpleMailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
- this(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
- }
-
- public SimpleMailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter, Children inferiors, Selectability selectability) {
- super();
- this.path = path;
- this.mailboxId = mailboxId;
- this.delimiter = delimiter;
- this.inferiors = inferiors;
- this.selectability = selectability;
- }
-
- /**
- * Is this mailbox <code>\Noinferiors</code> as per RFC3501.
- *
- * @return true if marked, false otherwise
- */
- @Override
- public final Children inferiors() {
- return inferiors;
- }
-
- /**
- * Gets the RFC3501 Selectability flag.
- */
- @Override
- public final Selectability getSelectability() {
- return selectability;
- }
-
- @Override
- public char getHierarchyDelimiter() {
- return delimiter;
- }
-
- @Override
- public MailboxPath getPath() {
- return path;
- }
-
- @Override
- public MailboxId getId() {
- return mailboxId;
- }
-
- @Override
- public String toString() {
- return "ListResult: " + path;
- }
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((path == null) ? 0 : path.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final SimpleMailboxMetaData other = (SimpleMailboxMetaData) obj;
- if (path == null) {
- if (other.path != null) {
- return false;
- }
- } else if (!path.equals(other.path)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int compareTo(MailboxMetaData o) {
- return StandardMailboxMetaDataComparator.order(this, o);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/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 45b4fbc..cbe6425 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
@@ -713,8 +713,8 @@ public class StoreMailboxManager implements MailboxManager {
return mailboxMapper.findNonPersonalMailboxes(session.getUser().asString(), right).stream();
}
- private SimpleMailboxMetaData toMailboxMetadata(MailboxSession session, List<Mailbox> mailboxes, Mailbox mailbox) {
- return new SimpleMailboxMetaData(
+ private MailboxMetaData toMailboxMetadata(MailboxSession session, List<Mailbox> mailboxes, Mailbox mailbox) {
+ return new MailboxMetaData(
mailbox.generateAssociatedPath(),
mailbox.getMailboxId(),
getDelimiter(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index ec66922..e0569c1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -119,36 +119,11 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
isRelative = true;
}
// Get the mailbox for the reference name.
- final MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
+ MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
+ MailboxId mailboxId = null;
results = new ArrayList<>(1);
- results.add(new MailboxMetaData() {
-
- @Override
- public Children inferiors() {
- return Children.CHILDREN_ALLOWED_BUT_UNKNOWN;
- }
-
- @Override
- public Selectability getSelectability() {
- return Selectability.NOSELECT;
- }
-
- @Override
- public char getHierarchyDelimiter() {
- return mailboxSession.getPathDelimiter();
- }
-
- @Override
- public MailboxPath getPath() {
- return rootPath;
- }
-
- @Override
- public MailboxId getId() {
- return null; //Will not be call in ListProcessor scope
- }
-
- });
+ results.add(new MailboxMetaData(rootPath, mailboxId, mailboxSession.getPathDelimiter(),
+ MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NOSELECT));
} else {
// If the mailboxPattern is fully qualified, ignore the
// reference name.
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
index d9244ac..d213045 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
@@ -30,11 +30,11 @@ import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
import org.apache.james.mailbox.manager.ManagerTestResources;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.quota.MaxQuotaManager;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.assertj.core.api.JUnitSoftAssertions;
import org.junit.Before;
@@ -173,7 +173,7 @@ public class MailboxFactoryTest {
mailboxManager.createMailbox(mailboxPath, mailboxSession);
Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath,
- Optional.of(ImmutableList.of(new SimpleMailboxMetaData(parentMailboxPath, parentId, DELIMITER))),
+ Optional.of(ImmutableList.of(new MailboxMetaData(parentMailboxPath, parentId, DELIMITER))),
mailboxSession);
assertThat(id).contains(parentId);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 4081afd..1c60d93 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -43,9 +43,9 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.search.MailboxQuery;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.webadmin.WebAdminServer;
@@ -774,7 +774,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(
+ new MailboxMetaData(
MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
@@ -800,7 +800,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
+ new MailboxMetaData(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -856,7 +856,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -870,7 +870,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -884,7 +884,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/13] james-project git commit: MAILBOX-362 Alphabetically order
EventSerializer.scala
Posted by bt...@apache.org.
MAILBOX-362 Alphabetically order EventSerializer.scala
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e25c2472
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e25c2472
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e25c2472
Branch: refs/heads/master
Commit: e25c24720979ac665cb6d41475454a296ca77092
Parents: 2d5abee
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:18:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:56:44 2018 +0700
----------------------------------------------------------------------
.../james/event/json/EventSerializer.scala | 83 ++++++++++----------
1 file changed, 41 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e25c2472/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 7dcffbc..5a14668 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -37,20 +37,14 @@ private sealed trait Event {
}
private object DTO {
-
- case class QuotaUsageUpdatedEvent(user: User, quotaRoot: QuotaRoot, countQuota: Quota[QuotaCount],
- sizeQuota: Quota[QuotaSize], time: Instant) extends Event {
- override def toJava: JavaEvent = new JavaQuotaUsageUpdatedEvent(user, quotaRoot, countQuota.toJava, sizeQuota.toJava, time)
+ case class MailboxACLUpdated(sessionId: SessionId, user: User, mailboxPath: MailboxPath, aclDiff: ACLDiff, mailboxId: MailboxId) extends Event {
+ override def toJava: JavaEvent = new JavaMailboxACLUpdated(sessionId, user, mailboxPath.toJava, aclDiff.toJava, mailboxId)
}
case class MailboxAdded(mailboxPath: MailboxPath, mailboxId: MailboxId, user: User, sessionId: SessionId) extends Event {
override def toJava: JavaEvent = new JavaMailboxAdded(sessionId, user, mailboxPath.toJava, mailboxId)
}
- case class MailboxRenamed(sessionId: SessionId, user: User, path: MailboxPath, mailboxId: MailboxId, newPath: MailboxPath) extends Event {
- override def toJava: JavaEvent = new JavaMailboxRenamed(sessionId, user, path.toJava, mailboxId, newPath.toJava)
- }
-
case class MailboxDeletion(sessionId: SessionId, user: User, path: MailboxPath, quotaRoot: QuotaRoot,
deletedMessageCount: QuotaCount, totalDeletedSize: QuotaSize, mailboxId: MailboxId) extends Event {
override def toJava: JavaEvent = new JavaMailboxDeletion(sessionId, user, path.toJava, quotaRoot, deletedMessageCount,
@@ -58,18 +52,23 @@ private object DTO {
mailboxId)
}
- case class MailboxACLUpdated(sessionId: SessionId, user: User, mailboxPath: MailboxPath, aclDiff: ACLDiff, mailboxId: MailboxId) extends Event {
- override def toJava: JavaEvent = new JavaMailboxACLUpdated(sessionId, user, mailboxPath.toJava, aclDiff.toJava, mailboxId)
+ case class MailboxRenamed(sessionId: SessionId, user: User, path: MailboxPath, mailboxId: MailboxId, newPath: MailboxPath) extends Event {
+ override def toJava: JavaEvent = new JavaMailboxRenamed(sessionId, user, path.toJava, mailboxId, newPath.toJava)
+ }
+
+ case class QuotaUsageUpdatedEvent(user: User, quotaRoot: QuotaRoot, countQuota: Quota[QuotaCount],
+ sizeQuota: Quota[QuotaSize], time: Instant) extends Event {
+ override def toJava: JavaEvent = new JavaQuotaUsageUpdatedEvent(user, quotaRoot, countQuota.toJava, sizeQuota.toJava, time)
}
}
private object ScalaConverter {
- private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
+ private def toScala(event: JavaMailboxACLUpdated): DTO.MailboxACLUpdated = DTO.MailboxACLUpdated(
+ sessionId = event.getSessionId,
user = event.getUser,
- quotaRoot = event.getQuotaRoot,
- countQuota = Quota.toScala(event.getCountQuota),
- sizeQuota = Quota.toScala(event.getSizeQuota),
- time = event.getInstant)
+ mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
+ aclDiff = ACLDiff.fromJava(event.getAclDiff),
+ mailboxId = event.getMailboxId)
private def toScala(event: JavaMailboxAdded): DTO.MailboxAdded = DTO.MailboxAdded(
mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
@@ -77,13 +76,6 @@ private object ScalaConverter {
user = event.getUser,
sessionId = event.getSessionId)
- private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
- sessionId = event.getSessionId,
- user = event.getUser,
- path = MailboxPath.fromJava(event.getMailboxPath),
- mailboxId = event.getMailboxId,
- newPath = MailboxPath.fromJava(event.getNewPath))
-
private def toScala(event: JavaMailboxDeletion): DTO.MailboxDeletion = DTO.MailboxDeletion(
sessionId = event.getSessionId,
user = event.getUser,
@@ -93,19 +85,26 @@ private object ScalaConverter {
totalDeletedSize = event.getTotalDeletedSize,
mailboxId = event.getMailboxId)
- private def toScala(event: JavaMailboxACLUpdated): DTO.MailboxACLUpdated = DTO.MailboxACLUpdated(
+ private def toScala(event: JavaMailboxRenamed): DTO.MailboxRenamed = DTO.MailboxRenamed(
sessionId = event.getSessionId,
user = event.getUser,
- mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
- aclDiff = ACLDiff.fromJava(event.getAclDiff),
- mailboxId = event.getMailboxId)
+ path = MailboxPath.fromJava(event.getMailboxPath),
+ mailboxId = event.getMailboxId,
+ newPath = MailboxPath.fromJava(event.getNewPath))
+
+ private def toScala(event: JavaQuotaUsageUpdatedEvent): DTO.QuotaUsageUpdatedEvent = DTO.QuotaUsageUpdatedEvent(
+ user = event.getUser,
+ quotaRoot = event.getQuotaRoot,
+ countQuota = Quota.toScala(event.getCountQuota),
+ sizeQuota = Quota.toScala(event.getSizeQuota),
+ time = event.getInstant)
def toScala(javaEvent: JavaEvent): Event = javaEvent match {
- case e: JavaQuotaUsageUpdatedEvent => toScala(e)
+ case e: JavaMailboxACLUpdated => toScala(e)
case e: JavaMailboxAdded => toScala(e)
- case e: JavaMailboxRenamed => toScala(e)
case e: JavaMailboxDeletion => toScala(e)
- case e: JavaMailboxACLUpdated => toScala(e)
+ case e: JavaMailboxRenamed => toScala(e)
+ case e: JavaQuotaUsageUpdatedEvent => toScala(e)
case _ => throw new RuntimeException("no Scala convertion known")
}
}
@@ -132,25 +131,21 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
case JsString(rightsAsString) => JsSuccess(JavaMailboxACL.Rfc4314Rights.deserialize(rightsAsString))
case _ => JsError()
}
- implicit val userReads: Reads[User] = {
- case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
- case _ => JsError()
- }
implicit val mailboxIdReads: Reads[MailboxId] = {
case JsString(serializedMailboxId) => JsSuccess(mailboxIdFactory.fromString(serializedMailboxId))
case _ => JsError()
}
- implicit val sessionIdReads: Reads[SessionId] = {
- case JsNumber(id) => JsSuccess(SessionId.of(id.longValue()))
+ implicit val quotaCountReads: Reads[QuotaCount] = {
+ case JsNumber(count) => JsSuccess(QuotaCount.count(count.toLong))
+ case JsNull => JsSuccess(QuotaCount.unlimited())
case _ => JsError()
}
implicit val quotaRootReads: Reads[QuotaRoot] = {
case JsString(quotaRoot) => JsSuccess(QuotaRoot.quotaRoot(quotaRoot, Optional.empty[Domain]))
case _ => JsError()
}
- implicit val quotaCountReads: Reads[QuotaCount] = {
- case JsNumber(count) => JsSuccess(QuotaCount.count(count.toLong))
- case JsNull => JsSuccess(QuotaCount.unlimited())
+ implicit val quotaScopeReads: Reads[JavaQuota.Scope] = {
+ case JsString(value) => JsSuccess(JavaQuota.Scope.valueOf(value))
case _ => JsError()
}
implicit val quotaSizeReads: Reads[QuotaSize] = {
@@ -158,8 +153,12 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
case JsNull => JsSuccess(QuotaSize.unlimited())
case _ => JsError()
}
- implicit val quotaScopeReads: Reads[JavaQuota.Scope] = {
- case JsString(value) => JsSuccess(JavaQuota.Scope.valueOf(value))
+ implicit val sessionIdReads: Reads[SessionId] = {
+ case JsNumber(id) => JsSuccess(SessionId.of(id.longValue()))
+ case _ => JsError()
+ }
+ implicit val userReads: Reads[User] = {
+ case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
case _ => JsError()
}
@@ -183,10 +182,10 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
}
+ implicit val aclDiffReads: Reads[ACLDiff] = Json.reads[ACLDiff]
+ implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[MailboxPath]
implicit val quotaCReads: Reads[Quota[QuotaCount]] = Json.reads[Quota[QuotaCount]]
implicit val quotaSReads: Reads[Quota[QuotaSize]] = Json.reads[Quota[QuotaSize]]
- implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[MailboxPath]
- implicit val aclDiffReads: Reads[ACLDiff] = Json.reads[ACLDiff]
implicit val eventOFormat: OFormat[Event] = derived.oformat()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/13] james-project git commit: MAILBOX-363 Line breaks in
StoreMessageResultIterator
Posted by bt...@apache.org.
MAILBOX-363 Line breaks in StoreMessageResultIterator
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c739d3ae
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c739d3ae
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c739d3ae
Branch: refs/heads/master
Commit: c739d3aecda4cd7b781694d7e9bb35e8df04923f
Parents: b16d06f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 18 17:17:28 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:58:07 2018 +0700
----------------------------------------------------------------------
.../store/StoreMessageResultIterator.java | 678 ++++++++++---------
1 file changed, 340 insertions(+), 338 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c739d3ae/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
index 664d91c..cbcf8ae 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
@@ -1,338 +1,340 @@
-/****************************************************************
- * 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;
-
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Objects;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Content;
-import org.apache.james.mailbox.model.Headers;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageAttachment;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MessageRange.Type;
-import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.model.MessageResult.FetchGroup;
-import org.apache.james.mailbox.model.MessageResultIterator;
-import org.apache.james.mailbox.model.MimeDescriptor;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class StoreMessageResultIterator implements MessageResultIterator {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(StoreMessageResultIterator.class);
-
- private Iterator<MailboxMessage> next = null;
- private MailboxException exception;
- private final Mailbox mailbox;
- private final FetchGroup group;
- private final MessageUid from;
- private MessageUid cursor;
- private final MessageUid to;
- private final BatchSizes batchSizes;
- private final Type type;
- private final MessageMapper mapper;
- private final FetchType ftype;
-
- public StoreMessageResultIterator(MessageMapper mapper, Mailbox mailbox, MessageRange range, BatchSizes batchSizes, org.apache.james.mailbox.model.MessageResult.FetchGroup group) {
- this.mailbox = mailbox;
- this.group = group;
- this.mapper = mapper;
- this.from = range.getUidFrom();
- this.cursor = this.from;
- this.to = range.getUidTo();
- this.batchSizes = batchSizes;
- this.type = range.getType();
- this.ftype = getFetchType(group);
- LOGGER.debug("batchSizes used: {}", batchSizes);
- }
-
- /**
- * Use the passed {@link FetchGroup} and calculate the right
- * {@link FetchType} for it
- *
- * @param group
- * @return fetchType
- */
- private static FetchType getFetchType(FetchGroup group) {
- int content = group.content();
- boolean headers = false;
- boolean body = false;
- boolean full = false;
-
- if ((content & FetchGroup.HEADERS) > 0) {
- headers = true;
- content -= FetchGroup.HEADERS;
- }
- if (group.getPartContentDescriptors().size() > 0) {
- full = true;
- }
- if ((content & FetchGroup.BODY_CONTENT) > 0) {
- body = true;
- content -= FetchGroup.BODY_CONTENT;
- }
-
- if ((content & FetchGroup.FULL_CONTENT) > 0) {
- full = true;
- content -= FetchGroup.FULL_CONTENT;
- }
-
- if ((content & FetchGroup.MIME_DESCRIPTOR) > 0) {
- // If we need the mimedescriptor we MAY need the full content later
- // too.
- // This gives us no other choice then request it
- full = true;
- content -= FetchGroup.MIME_DESCRIPTOR;
- }
- if (full || (body && headers)) {
- return FetchType.Full;
- } else if (body) {
- return FetchType.Body;
- } else if (headers) {
- return FetchType.Headers;
- } else {
- return FetchType.Metadata;
- }
- }
-
- @Override
- public boolean hasNext() {
- if (cursor.compareTo(to) > 0) {
- return false;
- }
-
- if (next == null || !next.hasNext()) {
- try {
- readBatch();
- } catch (MailboxException e) {
- this.exception = e;
- return false;
- }
- }
-
- return next.hasNext();
- }
-
- private void readBatch() throws MailboxException {
- MessageRange range;
- switch (type) {
- default:
- case ALL:
- // In case of all, we start on cursor and don't specify a to
- range = MessageRange.from(cursor);
- break;
- case FROM:
- range = MessageRange.from(cursor);
- break;
- case ONE:
- range = MessageRange.one(cursor);
- break;
- case RANGE:
- range = MessageRange.range(cursor, to);
- break;
- }
- next = mapper.findInMailbox(mailbox, range, ftype, batchSizeFromFetchType(ftype));
- }
-
- private int batchSizeFromFetchType(FetchType fetchType) {
- switch (fetchType) {
- case Metadata:
- return batchSizes.getFetchMetadata();
- case Headers:
- return batchSizes.getFetchHeaders();
- case Body:
- return batchSizes.getFetchBody();
- case Full:
- return batchSizes.getFetchFull();
- }
- throw new RuntimeException("Unknown fetchTpe: " + fetchType);
- }
-
- @Override
- public MessageResult next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- final MailboxMessage message = next.next();
- MessageResult result;
- try {
- result = ResultUtils.loadMessageResult(message, group);
- cursor = result.messageMetaData().getUid();
- } catch (MailboxException e) {
- result = new UnloadedMessageResult(message, e);
- }
-
- cursor = cursor.next();
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Read only");
- }
-
- @Override
- public MailboxException getException() {
- return exception;
- }
-
- private static final class UnloadedMessageResult implements MessageResult {
- private final MailboxException exception;
-
- private final MessageMetaData messageMetaData;
- private final MessageId messageId;
- private final MailboxId mailboxId;
-
- public UnloadedMessageResult(MailboxMessage message, MailboxException exception) {
- messageMetaData = message.metaData();
- mailboxId = message.getMailboxId();
- messageId = message.getMessageId();
- this.exception = exception;
- }
-
- @Override
- public MessageMetaData messageMetaData() {
- return messageMetaData;
- }
-
- @Override
- public MessageUid getUid() {
- return messageMetaData().getUid();
- }
-
- @Override
- public MessageId getMessageId() {
- return messageMetaData().getMessageId();
- }
-
- @Override
- public Date getInternalDate() {
- return messageMetaData().getInternalDate();
- }
-
- @Override
- public Flags getFlags() {
- return messageMetaData().getFlags();
- }
-
- @Override
- public long getModSeq() {
- return messageMetaData().getModSeq();
- }
-
- @Override
- public long getSize() {
- return messageMetaData().getSize();
- }
-
- @Override
- public MailboxId getMailboxId() {
- return mailboxId;
- }
-
- @Override
- public Content getFullContent() throws MailboxException {
- throw exception;
- }
-
- @Override
- public Content getBody() throws MailboxException {
- throw exception;
- }
-
- @Override
- public int compareTo(MessageResult that) {
- return getUid().compareTo(that.getUid());
- }
-
- @Override
- public final boolean equals(Object o) {
- if (o instanceof UnloadedMessageResult) {
- UnloadedMessageResult that = (UnloadedMessageResult) o;
-
- return Objects.equals(this.exception, that.exception)
- && Objects.equals(this.messageMetaData, that.messageMetaData)
- && Objects.equals(this.messageId, that.messageId)
- && Objects.equals(this.mailboxId, that.mailboxId);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hash(exception, messageMetaData, messageId, mailboxId);
- }
-
- @Override
- public Content getFullContent(MimePath path) throws MailboxException {
- throw exception;
- }
-
- @Override
- public Iterator<Header> iterateHeaders(MimePath path) throws MailboxException {
- throw exception;
- }
-
- @Override
- public Iterator<Header> iterateMimeHeaders(MimePath path) throws MailboxException {
- throw exception;
- }
-
- @Override
- public Content getBody(MimePath path) throws MailboxException {
- throw exception;
- }
-
- @Override
- public Content getMimeBody(MimePath path) throws MailboxException {
- throw exception;
- }
-
- @Override
- public MimeDescriptor getMimeDescriptor() throws MailboxException {
- throw exception;
- }
-
- @Override
- public Headers getHeaders() throws MailboxException {
- throw exception;
- }
-
- @Override
- public List<MessageAttachment> getAttachments() throws MailboxException {
- throw exception;
- }
-
- }
-
-}
+/****************************************************************
+ * 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;
+
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Objects;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Content;
+import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.MessageRange.Type;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.MessageResult.FetchGroup;
+import org.apache.james.mailbox.model.MessageResultIterator;
+import org.apache.james.mailbox.model.MimeDescriptor;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StoreMessageResultIterator implements MessageResultIterator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(StoreMessageResultIterator.class);
+
+ private Iterator<MailboxMessage> next = null;
+ private MailboxException exception;
+ private final Mailbox mailbox;
+ private final FetchGroup group;
+ private final MessageUid from;
+ private MessageUid cursor;
+ private final MessageUid to;
+ private final BatchSizes batchSizes;
+ private final Type type;
+ private final MessageMapper mapper;
+ private final FetchType ftype;
+
+ public StoreMessageResultIterator(MessageMapper mapper, Mailbox mailbox, MessageRange range, BatchSizes batchSizes, org.apache.james.mailbox.model.MessageResult.FetchGroup group) {
+ this.mailbox = mailbox;
+ this.group = group;
+ this.mapper = mapper;
+ this.from = range.getUidFrom();
+ this.cursor = this.from;
+ this.to = range.getUidTo();
+ this.batchSizes = batchSizes;
+ this.type = range.getType();
+ this.ftype = getFetchType(group);
+ LOGGER.debug("batchSizes used: {}", batchSizes);
+ }
+
+ /**
+ * Use the passed {@link FetchGroup} and calculate the right
+ * {@link FetchType} for it
+ *
+ * @param group
+ * @return fetchType
+ */
+ private static FetchType getFetchType(FetchGroup group) {
+ int content = group.content();
+ boolean headers = false;
+ boolean body = false;
+ boolean full = false;
+
+ if ((content & FetchGroup.HEADERS) > 0) {
+ headers = true;
+ content -= FetchGroup.HEADERS;
+ }
+ if (group.getPartContentDescriptors().size() > 0) {
+ full = true;
+ }
+ if ((content & FetchGroup.BODY_CONTENT) > 0) {
+ body = true;
+ content -= FetchGroup.BODY_CONTENT;
+ }
+
+ if ((content & FetchGroup.FULL_CONTENT) > 0) {
+ full = true;
+ content -= FetchGroup.FULL_CONTENT;
+ }
+
+ if ((content & FetchGroup.MIME_DESCRIPTOR) > 0) {
+ // If we need the mimedescriptor we MAY need the full content later
+ // too.
+ // This gives us no other choice then request it
+ full = true;
+ content -= FetchGroup.MIME_DESCRIPTOR;
+ }
+ if (full || (body && headers)) {
+ return FetchType.Full;
+ } else if (body) {
+ return FetchType.Body;
+ } else if (headers) {
+ return FetchType.Headers;
+ } else {
+ return FetchType.Metadata;
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (cursor.compareTo(to) > 0) {
+ return false;
+ }
+
+ if (next == null || !next.hasNext()) {
+ try {
+ readBatch();
+ } catch (MailboxException e) {
+ this.exception = e;
+ return false;
+ }
+ }
+
+ return next.hasNext();
+ }
+
+ private void readBatch() throws MailboxException {
+ MessageRange range;
+ switch (type) {
+ default:
+ case ALL:
+ // In case of all, we start on cursor and don't specify a to
+ range = MessageRange.from(cursor);
+ break;
+ case FROM:
+ range = MessageRange.from(cursor);
+ break;
+ case ONE:
+ range = MessageRange.one(cursor);
+ break;
+ case RANGE:
+ range = MessageRange.range(cursor, to);
+ break;
+ }
+ next = mapper.findInMailbox(mailbox, range, ftype, batchSizeFromFetchType(ftype));
+ }
+
+ private int batchSizeFromFetchType(FetchType fetchType) {
+ switch (fetchType) {
+ case Metadata:
+ return batchSizes.getFetchMetadata();
+ case Headers:
+ return batchSizes.getFetchHeaders();
+ case Body:
+ return batchSizes.getFetchBody();
+ case Full:
+ return batchSizes.getFetchFull();
+ }
+ throw new RuntimeException("Unknown fetchTpe: " + fetchType);
+ }
+
+ @Override
+ public MessageResult next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ final MailboxMessage message = next.next();
+ MessageResult result;
+ try {
+ result = ResultUtils.loadMessageResult(message, group);
+ cursor = result.getUid();
+ } catch (MailboxException e) {
+ result = new UnloadedMessageResult(message, e);
+ }
+
+ cursor = cursor.next();
+ return result;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Read only");
+ }
+
+ @Override
+ public MailboxException getException() {
+ return exception;
+ }
+
+ private static final class UnloadedMessageResult implements MessageResult {
+ private final MailboxException exception;
+
+ private final MessageMetaData messageMetaData;
+ private final MessageId messageId;
+ private final MailboxId mailboxId;
+
+ public UnloadedMessageResult(MailboxMessage message, MailboxException exception) {
+ messageMetaData = message.metaData();
+ mailboxId = message.getMailboxId();
+ messageId = message.getMessageId();
+ this.exception = exception;
+ }
+
+ @Override
+ public MessageMetaData messageMetaData() {
+ return messageMetaData;
+ }
+
+ @Override
+ public MessageUid getUid() {
+ return messageMetaData().getUid();
+ }
+
+ @Override
+ public MessageId getMessageId() {
+ return messageMetaData().getMessageId();
+ }
+
+ @Override
+ public Date getInternalDate() {
+ return messageMetaData().getInternalDate();
+ }
+
+ @Override
+ public Flags getFlags() {
+ return messageMetaData().getFlags();
+ }
+
+ @Override
+ public long getModSeq() {
+ return messageMetaData().getModSeq();
+ }
+
+ @Override
+ public long getSize() {
+ return messageMetaData().getSize();
+ }
+
+ @Override
+ public MailboxId getMailboxId() {
+ return mailboxId;
+ }
+
+ @Override
+ public Content getFullContent() throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Content getBody() throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public int compareTo(MessageResult that) {
+ return getUid().compareTo(that.getUid());
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof UnloadedMessageResult) {
+ UnloadedMessageResult that = (UnloadedMessageResult) o;
+
+ return Objects.equals(exception, that.exception)
+ && Objects.equals(this.getInternalDate(), that.getInternalDate())
+ && Objects.equals(this.getSize(), that.getSize())
+ && Objects.equals(this.getUid(), that.getUid())
+ && Objects.equals(this.getFlags(), that.getFlags())
+ && Objects.equals(this.getModSeq(), that.getModSeq())
+ && Objects.equals(this.messageId, that.messageId);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(exception, getInternalDate(), getSize(), getUid(), getFlags(), getModSeq(), messageId);
+ }
+
+ @Override
+ public Content getFullContent(MimePath path) throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Iterator<Header> iterateHeaders(MimePath path) throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Iterator<Header> iterateMimeHeaders(MimePath path) throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Content getBody(MimePath path) throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Content getMimeBody(MimePath path) throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public MimeDescriptor getMimeDescriptor() throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Headers getHeaders() throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public List<MessageAttachment> getAttachments() throws MailboxException {
+ throw exception;
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/13] james-project git commit: MAILBOX-359 POJOify MessageMetaData
& remove SimpleMessageMetaData
Posted by bt...@apache.org.
MAILBOX-359 POJOify MessageMetaData & remove SimpleMessageMetaData
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b16d06f0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b16d06f0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b16d06f0
Branch: refs/heads/master
Commit: b16d06f0a8ea9e583f71203c6ff3b62ca8aaec60
Parents: ecb6258
Author: Benoit Tellier <bt...@linagora.com>
Authored: Sat Dec 15 10:59:12 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:58:07 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/model/MessageMetaData.java | 72 +++++++++++----
.../mailbox/store/SimpleMessageMetaData.java | 93 --------------------
.../store/mail/model/MailboxMessage.java | 3 +-
.../store/AbstractCombinationManagerTest.java | 3 +-
.../AbstractMessageIdManagerSideEffectTest.java | 2 +-
.../store/mail/model/MetadataMapAssertTest.java | 9 +-
.../quota/ListeningCurrentQuotaUpdaterTest.java | 10 +--
.../base/MailboxEventAnalyserTest.java | 5 +-
.../processor/base/SelectedMailboxImplTest.java | 3 +-
9 files changed, 73 insertions(+), 127 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageMetaData.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageMetaData.java
index 6f629fc..03b26f3 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageMetaData.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageMetaData.java
@@ -24,23 +24,35 @@ import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
-public interface MessageMetaData {
+import com.google.common.base.Objects;
- MessageUid getUid();
-
-
- /**
- * Return the modify-sequence number of the message. This is kind of optional and the mailbox
- * implementation may not support this. If so it will return -1
- */
- long getModSeq();
+public class MessageMetaData {
+ private final MessageUid uid;
+ private final Flags flags;
+ private final long size;
+ private final Date internalDate;
+ private final long modSeq;
+ private final MessageId messageId;
+
+ public MessageMetaData(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, MessageId messageId) {
+ this.uid = uid;
+ this.flags = flags;
+ this.size = size;
+ this.modSeq = modSeq;
+ this.internalDate = internalDate;
+ this.messageId = messageId;
+ }
+
+ public Flags getFlags() {
+ return flags;
+ }
- Flags getFlags();
-
/**
* Return the size in bytes
*/
- long getSize();
+ public long getSize() {
+ return size;
+ }
/**
* <p>
@@ -48,7 +60,37 @@ public interface MessageMetaData {
* (by smtp). Clients are also allowed to set the internalDate on append.
* </p>
*/
- Date getInternalDate();
-
- MessageId getMessageId();
+ public Date getInternalDate() {
+ return internalDate;
+ }
+
+ public MessageUid getUid() {
+ return uid;
+ }
+
+ public MessageId getMessageId() {
+ return messageId;
+ }
+
+ /**
+ * Return the modify-sequence number of the message. This is kind of optional and the mailbox
+ * implementation may not support this. If so it will return -1
+ */
+ public long getModSeq() {
+ return modSeq;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MessageMetaData) {
+ return uid.equals(((MessageMetaData) obj).getUid());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(uid);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
deleted file mode 100644
index 61e2f54..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMessageMetaData.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************
- * 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;
-
-import java.util.Date;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageMetaData;
-
-import com.google.common.base.Objects;
-
-
-public class SimpleMessageMetaData implements MessageMetaData {
- private final MessageUid uid;
- private final Flags flags;
- private final long size;
- private final Date internalDate;
- private final long modSeq;
- private final MessageId messageId;
-
- public SimpleMessageMetaData(MessageUid uid, long modSeq, Flags flags, long size, Date internalDate, MessageId messageId) {
- this.uid = uid;
- this.flags = flags;
- this.size = size;
- this.modSeq = modSeq;
- this.internalDate = internalDate;
- this.messageId = messageId;
- }
-
- @Override
- public Flags getFlags() {
- return flags;
- }
-
- @Override
- public long getSize() {
- return size;
- }
-
- @Override
- public Date getInternalDate() {
- return internalDate;
- }
-
- @Override
- public MessageUid getUid() {
- return uid;
- }
-
- @Override
- public MessageId getMessageId() {
- return messageId;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof SimpleMessageMetaData) {
- return uid.equals(((SimpleMessageMetaData) obj).getUid());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(uid);
- }
-
- @Override
- public long getModSeq() {
- return modSeq;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
index 2842356..7d0df02 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxMessage.java
@@ -24,7 +24,6 @@ import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
/**
* A MIME message, consisting of meta-data (including MIME headers)
@@ -129,7 +128,7 @@ public interface MailboxMessage extends Message, Comparable<MailboxMessage> {
Flags createFlags();
default MessageMetaData metaData() {
- return new SimpleMessageMetaData(getUid(), getModSeq(), createFlags(), getFullContentOctets(), getInternalDate(), getMessageId());
+ return new MessageMetaData(getUid(), getModSeq(), createFlags(), getFullContentOctets(), getInternalDate(), getMessageId());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
index 0ed6dda..08d8747 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
@@ -384,7 +384,8 @@ public abstract class AbstractCombinationManagerTest {
assertThat(messageManager1.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, session)).isEmpty();
assertThat(messageManager2.getMessages(MessageRange.all(), FetchGroupImpl.MINIMAL, session))
.hasSize(1)
- .extractingResultOf("getMessageId").containsOnly(messageId);
+ .extracting(MessageResult::getMessageId)
+ .containsOnly(messageId);
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
index b916395..0a02502 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
@@ -210,7 +210,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
assertThat(messageResults).hasSize(2);
messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox3.getMailboxId()), session);
- verify(dispatcher).expunged(eq(session), any(SimpleMessageMetaData.class), eq(mailbox2));
+ verify(dispatcher).expunged(eq(session), any(MessageMetaData.class), eq(mailbox2));
verify(dispatcher).added(eq(session), eq(mailbox3), any(MailboxMessage.class));
verify(dispatcher).moved(eq(session), any(), any());
verifyNoMoreInteractions(dispatcher);
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
index 0fd78d7..e8870b9 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
@@ -30,7 +30,6 @@ import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.junit.Before;
@@ -59,14 +58,14 @@ public class MetadataMapAssertTest {
@Test
public void metadataMapAssertShouldSucceedWhenContainingRightMetadata() {
Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<>();
- metaDataMap.put(UID, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE, MESSAGE_ID));
+ metaDataMap.put(UID, new MessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE, MESSAGE_ID));
MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
}
@Test(expected = AssertionError.class)
public void metadataMapAssertShouldFailWhenUidMismatch() {
Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<>();
- metaDataMap.put(UID, new SimpleMessageMetaData(UID.next(), MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE, MESSAGE_ID));
+ metaDataMap.put(UID, new MessageMetaData(UID.next(), MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE, MESSAGE_ID));
MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
}
@@ -75,14 +74,14 @@ public class MetadataMapAssertTest {
Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<>();
Date date = new Date();
date.setTime(DATE.getTime() + 100L);
- metaDataMap.put(UID, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), date, MESSAGE_ID));
+ metaDataMap.put(UID, new MessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), date, MESSAGE_ID));
MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
}
@Test(expected = AssertionError.class)
public void metadataMapAssertShouldFailWhenSizeMismatch() {
Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<>();
- metaDataMap.put(UID, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length() + 1, DATE, MESSAGE_ID));
+ metaDataMap.put(UID, new MessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length() + 1, DATE, MESSAGE_ID));
MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index 241b62b..0d62a90 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -37,11 +37,11 @@ import org.apache.james.core.quota.QuotaSize;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.model.TestId;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.junit.Before;
@@ -73,8 +73,8 @@ public class ListeningCurrentQuotaUpdaterTest {
public void addedEventShouldIncreaseCurrentQuotaValues() throws Exception {
MailboxListener.Added added = mock(MailboxListener.Added.class);
when(added.getMailboxId()).thenReturn(MAILBOX_ID);
- when(added.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
- when(added.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
+ when(added.getMetaData(MessageUid.of(36))).thenReturn(new MessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
+ when(added.getMetaData(MessageUid.of(38))).thenReturn(new MessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
when(added.getUser()).thenReturn(USER_BENWA);
when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID))).thenReturn(QUOTA_ROOT);
@@ -87,8 +87,8 @@ public class ListeningCurrentQuotaUpdaterTest {
@Test
public void expungedEventShouldDecreaseCurrentQuotaValues() throws Exception {
MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
- when(expunged.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
- when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
+ when(expunged.getMetaData(MessageUid.of(36))).thenReturn(new MessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
+ when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new MessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
when(expunged.getUser()).thenReturn(USER_BENWA);
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index e26ff4f..cc12128 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -46,7 +46,6 @@ import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResultIterator;
import org.apache.james.mailbox.model.TestId;
import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.event.EventFactory;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -149,7 +148,7 @@ public class MailboxEventAnalyserTest {
MailboxListener.Added mailboxAdded = eventFactory.added(
MAILBOX_SESSION,
ImmutableSortedMap.of(MessageUid.of(11),
- new SimpleMessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
+ new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
DEFAULT_MAILBOX);
testee.event(mailboxAdded);
assertThat(testee.isSizeChanged()).isTrue();
@@ -160,7 +159,7 @@ public class MailboxEventAnalyserTest {
MailboxListener.Added mailboxAdded = eventFactory.added(
MAILBOX_SESSION,
ImmutableSortedMap.of(MessageUid.of(11),
- new SimpleMessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
+ new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())),
DEFAULT_MAILBOX);
testee.event(mailboxAdded);
testee.resetEvents();
http://git-wip-us.apache.org/repos/asf/james-project/blob/b16d06f0/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 7973ab2..437c41f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -50,7 +50,6 @@ import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.SearchQuery;
import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.event.EventFactory;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -168,7 +167,7 @@ public class SelectedMailboxImplTest {
private void emitEvent(MailboxListener mailboxListener) {
SecureRandom random = new SecureRandom();
TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
- result.put(EMITTED_EVENT_UID, new SimpleMessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
+ result.put(EMITTED_EVENT_UID, new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
mailboxListener.event(new EventFactory().added(MailboxSession.SessionId.of(random.nextLong()),
mock(User.class), result, mailbox));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/13] james-project git commit: MAILBOX-359 Compose MessageMetaData
in MessageResult
Posted by bt...@apache.org.
MAILBOX-359 Compose MessageMetaData in MessageResult
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1c3c3e56
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1c3c3e56
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1c3c3e56
Branch: refs/heads/master
Commit: 1c3c3e569dfc02ba98cc44237fc44472bf81ceba
Parents: ef2c68c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 17 16:39:12 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:58:07 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/model/MessageResult.java | 21 ++++-
.../james/mailbox/store/MessageResultImpl.java | 26 +++---
.../store/StoreMessageResultIterator.java | 94 +++++++++-----------
.../AbstractMessageIdManagerSideEffectTest.java | 11 +--
.../base/MailboxEventAnalyserTest.java | 1 +
.../james/jmap/methods/GetMessagesMethod.java | 3 +-
6 files changed, 81 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
index b0591bd..8bd39aa 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
@@ -20,12 +20,15 @@
package org.apache.james.mailbox.model;
import java.io.IOException;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import javax.mail.Flags;
import javax.mail.MessagingException;
+import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.exception.MailboxException;
@@ -57,7 +60,20 @@ import org.apache.james.mailbox.exception.MailboxException;
* </p>
*/
-public interface MessageResult extends Comparable<MessageResult>, MessageMetaData {
+public interface MessageResult extends Comparable<MessageResult> {
+ MessageId getMessageId();
+
+ Date getInternalDate();
+
+ Flags getFlags();
+
+ long getSize();
+
+ MessageMetaData messageMetaData();
+
+ MessageUid getUid();
+
+ long getModSeq();
/**
* Indicates the results fetched.
@@ -264,7 +280,4 @@ public interface MessageResult extends Comparable<MessageResult>, MessageMetaDat
*/
int[] getPositions();
}
-
- @Override
- MessageId getMessageId();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
index 05b910a..03caa8c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.model.Headers;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MimeDescriptor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -68,33 +69,43 @@ public class MessageResultImpl implements MessageResult {
}
@Override
+ public MessageMetaData messageMetaData() {
+ return message.metaData();
+ }
+
+ @Override
public MailboxId getMailboxId() {
return message.getMailboxId();
}
@Override
public MessageUid getUid() {
- return message.getUid();
+ return messageMetaData().getUid();
}
@Override
public MessageId getMessageId() {
- return message.getMessageId();
+ return messageMetaData().getMessageId();
}
@Override
public Date getInternalDate() {
- return message.getInternalDate();
+ return messageMetaData().getInternalDate();
}
@Override
public Flags getFlags() {
- return message.createFlags();
+ return messageMetaData().getFlags();
+ }
+
+ @Override
+ public long getModSeq() {
+ return messageMetaData().getModSeq();
}
@Override
public long getSize() {
- return message.getFullContentOctets();
+ return messageMetaData().getSize();
}
@Override
@@ -318,11 +329,6 @@ public class MessageResultImpl implements MessageResult {
}
return mimeDescriptor;
}
-
- @Override
- public long getModSeq() {
- return message.getModSeq();
- }
@Override
public Headers getHeaders() throws MailboxException {
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
index 4a6965b..664d91c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
@@ -22,6 +22,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Objects;
import javax.mail.Flags;
@@ -32,6 +33,7 @@ import org.apache.james.mailbox.model.Headers;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageRange.Type;
import org.apache.james.mailbox.model.MessageResult;
@@ -45,8 +47,6 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Objects;
-
public class StoreMessageResultIterator implements MessageResultIterator {
private static final Logger LOGGER = LoggerFactory.getLogger(StoreMessageResultIterator.class);
@@ -187,7 +187,7 @@ public class StoreMessageResultIterator implements MessageResultIterator {
MessageResult result;
try {
result = ResultUtils.loadMessageResult(message, group);
- cursor = result.getUid();
+ cursor = result.messageMetaData().getUid();
} catch (MailboxException e) {
result = new UnloadedMessageResult(message, e);
}
@@ -209,93 +209,88 @@ public class StoreMessageResultIterator implements MessageResultIterator {
private static final class UnloadedMessageResult implements MessageResult {
private final MailboxException exception;
- private final Date internalDate;
-
- private final long size;
-
- private final MessageUid uid;
-
- private final Flags flags;
-
+ private final MessageMetaData messageMetaData;
private final MessageId messageId;
-
- private long modSeq = -1;
-
private final MailboxId mailboxId;
public UnloadedMessageResult(MailboxMessage message, MailboxException exception) {
- super();
- internalDate = message.getInternalDate();
- size = message.getFullContentOctets();
- uid = message.getUid();
- flags = message.createFlags();
- modSeq = message.getModSeq();
+ messageMetaData = message.metaData();
mailboxId = message.getMailboxId();
messageId = message.getMessageId();
this.exception = exception;
}
@Override
- public MailboxId getMailboxId() {
- return mailboxId;
+ public MessageMetaData messageMetaData() {
+ return messageMetaData;
}
@Override
- public Flags getFlags() {
- return flags;
+ public MessageUid getUid() {
+ return messageMetaData().getUid();
}
@Override
- public Content getFullContent() throws MailboxException {
- throw exception;
+ public MessageId getMessageId() {
+ return messageMetaData().getMessageId();
}
@Override
public Date getInternalDate() {
- return internalDate;
+ return messageMetaData().getInternalDate();
}
@Override
- public Content getBody() throws MailboxException {
- throw exception;
+ public Flags getFlags() {
+ return messageMetaData().getFlags();
+ }
+
+ @Override
+ public long getModSeq() {
+ return messageMetaData().getModSeq();
}
@Override
public long getSize() {
- return size;
+ return messageMetaData().getSize();
}
@Override
- public MessageUid getUid() {
- return uid;
+ public MailboxId getMailboxId() {
+ return mailboxId;
}
@Override
- public MessageId getMessageId() {
- return messageId;
+ public Content getFullContent() throws MailboxException {
+ throw exception;
+ }
+
+ @Override
+ public Content getBody() throws MailboxException {
+ throw exception;
}
@Override
public int compareTo(MessageResult that) {
- return uid.compareTo(that.getUid());
+ return getUid().compareTo(that.getUid());
}
@Override
- public int hashCode() {
- return Objects.hashCode(exception, internalDate, size, uid, flags, modSeq, messageId);
+ public final boolean equals(Object o) {
+ if (o instanceof UnloadedMessageResult) {
+ UnloadedMessageResult that = (UnloadedMessageResult) o;
+
+ return Objects.equals(this.exception, that.exception)
+ && Objects.equals(this.messageMetaData, that.messageMetaData)
+ && Objects.equals(this.messageId, that.messageId)
+ && Objects.equals(this.mailboxId, that.mailboxId);
+ }
+ return false;
}
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof UnloadedMessageResult) {
- UnloadedMessageResult that = (UnloadedMessageResult)obj;
- return (size == that.size) && (uid.equals(that.uid)) && (modSeq == that.modSeq) && exception.equals(that.exception)
- && internalDate.equals(that.internalDate) && flags.equals(that.flags);
- }
- return false;
+ public final int hashCode() {
+ return Objects.hash(exception, messageMetaData, messageId, mailboxId);
}
@Override
@@ -329,11 +324,6 @@ public class StoreMessageResultIterator implements MessageResultIterator {
}
@Override
- public long getModSeq() {
- return modSeq;
- }
-
- @Override
public Headers getHeaders() throws MailboxException {
throw exception;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
index b2a3050..b916395 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java
@@ -47,6 +47,7 @@ import org.apache.james.mailbox.exception.OverQuotaException;
import org.apache.james.mailbox.fixture.MailboxFixture;
import org.apache.james.mailbox.model.FetchGroupImpl;
import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.model.QuotaRoot;
@@ -105,7 +106,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
reset(dispatcher);
MessageResult messageResult = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, session).get(0);
- SimpleMessageMetaData simpleMessageMetaData = fromMessageResult(messageId, messageResult);
+ MessageMetaData simpleMessageMetaData = messageResult.messageMetaData();
messageIdManager.delete(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
@@ -121,9 +122,9 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
reset(dispatcher);
MessageResult messageResult1 = messageIdManager.getMessages(ImmutableList.of(messageId1), FetchGroupImpl.MINIMAL, session).get(0);
- SimpleMessageMetaData simpleMessageMetaData1 = fromMessageResult(messageId1, messageResult1);
+ MessageMetaData simpleMessageMetaData1 = messageResult1.messageMetaData();
MessageResult messageResult2 = messageIdManager.getMessages(ImmutableList.of(messageId2), FetchGroupImpl.MINIMAL, session).get(0);
- SimpleMessageMetaData simpleMessageMetaData2 = fromMessageResult(messageId2, messageResult2);
+ MessageMetaData simpleMessageMetaData2 = messageResult2.messageMetaData();
messageIdManager.delete(ImmutableList.of(messageId1, messageId2), session);
@@ -355,8 +356,4 @@ public abstract class AbstractMessageIdManagerSideEffectTest {
when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn(
Quota.<QuotaSize>builder().used(QuotaSize.size(2)).computedLimit(QuotaSize.unlimited()).build());
}
-
- private SimpleMessageMetaData fromMessageResult(MessageId messageId, MessageResult messageResult) {
- return new SimpleMessageMetaData(messageResult.getUid(), messageResult.getModSeq(), messageResult.getFlags(), messageResult.getSize(), messageResult.getInternalDate(), messageId);
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 55e4d0c..e26ff4f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResultIterator;
import org.apache.james.mailbox.model.TestId;
http://git-wip-us.apache.org/repos/asf/james-project/blob/1c3c3e56/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 1c97156..ca05d89 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -44,7 +44,6 @@ import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.FetchGroupImpl;
import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.util.MDCBuilder;
@@ -170,7 +169,7 @@ public class GetMessagesMethod implements Method {
.collect(Guavate.toImmutableList());
try {
Keywords keywords = messageResults.stream()
- .map(MessageMetaData::getFlags)
+ .map(MessageResult::getFlags)
.map(keywordsFactory::fromFlags)
.reduce(ACCUMULATOR)
.get();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/13] james-project git commit: MAILBOX-362 MailboxACLUpdated
should implement equals and hashcode
Posted by bt...@apache.org.
MAILBOX-362 MailboxACLUpdated should implement equals and hashcode
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/892f95a1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/892f95a1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/892f95a1
Branch: refs/heads/master
Commit: 892f95a19a8b366f830e044bcf5c5dd8e1478c5c
Parents: 6000b48
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:01:44 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:53 2018 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/MailboxListener.java | 19 +++++++++++++++++++
.../james/mailbox/MailboxListenerTest.java | 5 +++++
2 files changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/892f95a1/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index bbd5e4a..b3d4785 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -323,6 +323,25 @@ public interface MailboxListener {
return aclDiff;
}
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof MailboxACLUpdated) {
+ MailboxACLUpdated that = (MailboxACLUpdated) o;
+
+ return Objects.equals(this.sessionId, that.sessionId)
+ && Objects.equals(this.user, that.user)
+ && Objects.equals(this.path, that.path)
+ && Objects.equals(this.aclDiff, that.aclDiff)
+ && Objects.equals(this.mailboxId, that.mailboxId);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(sessionId, user, path, aclDiff, mailboxId);
+ }
+
}
/**
http://git-wip-us.apache.org/repos/asf/james-project/blob/892f95a1/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
index 0e28d17..ac9c364 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxListenerTest.java
@@ -38,4 +38,9 @@ class MailboxListenerTest {
void mailboxDeletionShouldMatchBeanContract() {
EqualsVerifier.forClass(MailboxListener.MailboxDeletion.class).verify();
}
+
+ @Test
+ void mailboxACLUpdatedShouldMatchBeanContract() {
+ EqualsVerifier.forClass(MailboxListener.MailboxACLUpdated.class).verify();
+ }
}
\ 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
[05/13] james-project git commit: MAILBOX-362 Serialization for
MailboxACLUpdated event
Posted by bt...@apache.org.
MAILBOX-362 Serialization for MailboxACLUpdated 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/2d5abee7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2d5abee7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2d5abee7
Branch: refs/heads/master
Commit: 2d5abee7b6cb67eea84a5f6d2f0cb6d68ccbf039
Parents: 8eaf1f6
Author: datph <dp...@linagora.com>
Authored: Tue Dec 18 11:12:02 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:53 2018 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/model/MailboxACL.java | 4 +
.../org/apache/james/event/json/DTOs.scala | 14 +-
.../james/event/json/EventSerializer.scala | 40 +-
...MailboxACLUpdatedEventSerializationTest.java | 985 +++++++++++++++++++
4 files changed, 1039 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/2d5abee7/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
index 3bdf826..d02d6ff 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxACL.java
@@ -175,6 +175,10 @@ public class MailboxACL {
.except(new Rfc4314Rights(rights));
}
+ public static Rfc4314Rights deserialize(String serialized) throws UnsupportedRightException {
+ return new Rfc4314Rights(serialized);
+ }
+
private static final char c_ObsoleteCreate = 'c';
private static final char d_ObsoleteDelete = 'd';
http://git-wip-us.apache.org/repos/asf/james-project/blob/2d5abee7/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
index 8d8af9e..3e04d1c 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/DTOs.scala
@@ -20,11 +20,18 @@
package org.apache.james.event.json
import org.apache.james.core.quota.QuotaValue
-import org.apache.james.mailbox.model.{MailboxPath => JavaMailboxPath, Quota => JavaQuota}
+import org.apache.james.mailbox.acl.{ACLDiff => JavaACLDiff}
+import org.apache.james.mailbox.model.{MailboxACL, MailboxPath => JavaMailboxPath, Quota => JavaQuota}
import scala.collection.JavaConverters._
object DTOs {
+ object ACLDiff {
+ def fromJava(javaACLDiff: JavaACLDiff): ACLDiff = ACLDiff(
+ javaACLDiff.getOldACL.getEntries.asScala.toMap,
+ javaACLDiff.getNewACL.getEntries.asScala.toMap)
+ }
+
object MailboxPath {
def fromJava(javaMailboxPath: JavaMailboxPath): MailboxPath = MailboxPath(
Option(javaMailboxPath.getNamespace),
@@ -39,6 +46,11 @@ object DTOs {
limits = java.getLimitByScope.asScala.toMap)
}
+ case class ACLDiff(oldACL: Map[MailboxACL.EntryKey, MailboxACL.Rfc4314Rights],
+ newACL: Map[MailboxACL.EntryKey, MailboxACL.Rfc4314Rights]) {
+ def toJava: JavaACLDiff = new JavaACLDiff(new MailboxACL(oldACL.asJava), new MailboxACL(newACL.asJava))
+ }
+
case class MailboxPath(namespace: Option[String], user: Option[String], name: String) {
def toJava: JavaMailboxPath = new JavaMailboxPath(namespace.orNull, user.orNull, name)
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/2d5abee7/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
index 544859b..7dcffbc 100644
--- a/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
+++ b/mailbox/event/json/src/main/scala/org/apache/james/event/json/EventSerializer.scala
@@ -25,10 +25,10 @@ import java.util.Optional
import julienrf.json.derived
import org.apache.james.core.quota.{QuotaCount, QuotaSize, QuotaValue}
import org.apache.james.core.{Domain, User}
-import org.apache.james.event.json.DTOs.{MailboxPath, Quota}
-import org.apache.james.mailbox.MailboxListener.{MailboxAdded => JavaMailboxAdded, MailboxDeletion => JavaMailboxDeletion, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
+import org.apache.james.event.json.DTOs.{ACLDiff, MailboxPath, Quota}
+import org.apache.james.mailbox.MailboxListener.{MailboxACLUpdated => JavaMailboxACLUpdated, MailboxAdded => JavaMailboxAdded, MailboxDeletion => JavaMailboxDeletion, MailboxRenamed => JavaMailboxRenamed, QuotaUsageUpdatedEvent => JavaQuotaUsageUpdatedEvent}
import org.apache.james.mailbox.MailboxSession.SessionId
-import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, Quota => JavaQuota}
+import org.apache.james.mailbox.model.{MailboxId, QuotaRoot, MailboxACL => JavaMailboxACL, Quota => JavaQuota}
import org.apache.james.mailbox.{Event => JavaEvent}
import play.api.libs.json.{JsError, JsNull, JsNumber, JsObject, JsResult, JsString, JsSuccess, Json, OFormat, Reads, Writes}
@@ -57,6 +57,10 @@ private object DTO {
totalDeletedSize,
mailboxId)
}
+
+ case class MailboxACLUpdated(sessionId: SessionId, user: User, mailboxPath: MailboxPath, aclDiff: ACLDiff, mailboxId: MailboxId) extends Event {
+ override def toJava: JavaEvent = new JavaMailboxACLUpdated(sessionId, user, mailboxPath.toJava, aclDiff.toJava, mailboxId)
+ }
}
private object ScalaConverter {
@@ -89,11 +93,19 @@ private object ScalaConverter {
totalDeletedSize = event.getTotalDeletedSize,
mailboxId = event.getMailboxId)
+ private def toScala(event: JavaMailboxACLUpdated): DTO.MailboxACLUpdated = DTO.MailboxACLUpdated(
+ sessionId = event.getSessionId,
+ user = event.getUser,
+ mailboxPath = MailboxPath.fromJava(event.getMailboxPath),
+ aclDiff = ACLDiff.fromJava(event.getAclDiff),
+ mailboxId = event.getMailboxId)
+
def toScala(javaEvent: JavaEvent): Event = javaEvent match {
case e: JavaQuotaUsageUpdatedEvent => toScala(e)
case e: JavaMailboxAdded => toScala(e)
case e: JavaMailboxRenamed => toScala(e)
case e: JavaMailboxDeletion => toScala(e)
+ case e: JavaMailboxACLUpdated => toScala(e)
case _ => throw new RuntimeException("no Scala convertion known")
}
}
@@ -108,7 +120,18 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
implicit val mailboxPathWrites: Writes[MailboxPath] = Json.writes[MailboxPath]
implicit val mailboxIdWrites: Writes[MailboxId] = value => JsString(value.serialize())
implicit val sessionIdWrites: Writes[SessionId] = value => JsNumber(value.getValue)
+ implicit val aclEntryKeyWrites: Writes[JavaMailboxACL.EntryKey] = value => JsString(value.serialize())
+ implicit val aclRightsWrites: Writes[JavaMailboxACL.Rfc4314Rights] = value => JsString(value.serialize())
+ implicit val aclDiffWrites: Writes[ACLDiff] = Json.writes[ACLDiff]
+ implicit val aclEntryKeyReads: Reads[JavaMailboxACL.EntryKey] = {
+ case JsString(keyAsString) => JsSuccess(JavaMailboxACL.EntryKey.deserialize(keyAsString))
+ case _ => JsError()
+ }
+ implicit val aclRightsReads: Reads[JavaMailboxACL.Rfc4314Rights] = {
+ case JsString(rightsAsString) => JsSuccess(JavaMailboxACL.Rfc4314Rights.deserialize(rightsAsString))
+ case _ => JsError()
+ }
implicit val userReads: Reads[User] = {
case JsString(userAsString) => JsSuccess(User.fromUsername(userAsString))
case _ => JsError()
@@ -150,9 +173,20 @@ private class JsonSerialize(mailboxIdFactory: MailboxId.Factory) {
JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
}
+ implicit def scopeMapReadsACL[V](implicit vr: Reads[V]): Reads[Map[JavaMailboxACL.EntryKey, V]] =
+ Reads.mapReads[JavaMailboxACL.EntryKey, V] { str =>
+ Json.fromJson[JavaMailboxACL.EntryKey](JsString(str))
+ }
+
+ implicit def scopeMapWriteACL[V](implicit vr: Writes[V]): Writes[Map[JavaMailboxACL.EntryKey, V]] =
+ (m: Map[JavaMailboxACL.EntryKey, V]) => {
+ JsObject(m.map { case (k, v) => (k.toString, vr.writes(v)) }.toSeq)
+ }
+
implicit val quotaCReads: Reads[Quota[QuotaCount]] = Json.reads[Quota[QuotaCount]]
implicit val quotaSReads: Reads[Quota[QuotaSize]] = Json.reads[Quota[QuotaSize]]
implicit val mailboxPathReads: Reads[MailboxPath] = Json.reads[MailboxPath]
+ implicit val aclDiffReads: Reads[ACLDiff] = Json.reads[ACLDiff]
implicit val eventOFormat: OFormat[Event] = derived.oformat()
http://git-wip-us.apache.org/repos/asf/james-project/blob/2d5abee7/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
new file mode 100644
index 0000000..ceed360
--- /dev/null
+++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/MailboxACLUpdatedEventSerializationTest.java
@@ -0,0 +1,985 @@
+/****************************************************************
+ * 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.event.json;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.NoSuchElementException;
+
+import org.apache.james.core.User;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.acl.ACLDiff;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.TestId;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.core.JsonParseException;
+
+class MailboxACLUpdatedEventSerializationTest {
+
+ private static final User USER = User.fromUsername("user");
+ private static final MailboxACL.EntryKey ENTRY_KEY = org.apache.james.mailbox.model.MailboxACL.EntryKey.createGroupEntryKey("any", false);
+ private static final MailboxACL.Rfc4314Rights RIGHTS = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer, MailboxACL.Right.Read);
+ private static final EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory());
+ private static final MailboxACL MAILBOX_ACL = new MailboxACL(
+ new MailboxACL.Entry(ENTRY_KEY, RIGHTS),
+ new MailboxACL.Entry(MailboxACL.EntryKey.createUserEntryKey("alice", true),
+ new MailboxACL.Rfc4314Rights(MailboxACL.Right.Insert)));
+
+ private static final MailboxListener.MailboxACLUpdated MAILBOX_ACL_UPDATED = new MailboxListener.MailboxACLUpdated(
+ MailboxSession.SessionId.of(6),
+ USER,
+ new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
+ ACLDiff.computeDiff(MailboxACL.EMPTY, MAILBOX_ACL),
+ TestId.of(23));
+
+ private static final String MAILBOX_ACL_UPDATED_JSON = "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\", \"-alice\":\"i\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}";
+
+ @Test
+ void mailboxACLUpdatedShouldBeSerialized() {
+ assertThatJson(EVENT_SERIALIZER.toJson(MAILBOX_ACL_UPDATED))
+ .isEqualTo(MAILBOX_ACL_UPDATED_JSON);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldBeDeserialized() {
+ assertThat(EVENT_SERIALIZER.fromJson(MAILBOX_ACL_UPDATED_JSON).get())
+ .isEqualTo(MAILBOX_ACL_UPDATED);
+ }
+
+ @Nested
+ class NullUserInMailboxPath {
+ private final String NULL_USER = null;
+ private static final String JSON_2 = "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}";
+
+ private final MailboxACL MAILBOX_ACL= new MailboxACL(
+ new MailboxACL.Entry(ENTRY_KEY, RIGHTS));
+
+ private final MailboxListener.MailboxACLUpdated UPDATED_EVENT = new MailboxListener.MailboxACLUpdated(
+ MailboxSession.SessionId.of(6),
+ USER,
+ new MailboxPath(MailboxConstants.USER_NAMESPACE, NULL_USER, "mailboxName"),
+ ACLDiff.computeDiff(MailboxACL.EMPTY, MAILBOX_ACL),
+ TestId.of(23));
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellSerializedWithNullUser() {
+ assertThatJson(EVENT_SERIALIZER.toJson(UPDATED_EVENT))
+ .isEqualTo(JSON_2);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
+ assertThat(EVENT_SERIALIZER.fromJson(JSON_2).get())
+ .isEqualTo(UPDATED_EVENT);
+ }
+ }
+
+ @Nested
+ class NullNameSpaceInMailboxPath {
+
+ private final MailboxACL MAILBOX_ACL = new MailboxACL(
+ new MailboxACL.Entry(ENTRY_KEY, RIGHTS));
+
+ private final MailboxListener.MailboxACLUpdated UPDATED_EVENT = new MailboxListener.MailboxACLUpdated(
+ MailboxSession.SessionId.of(6),
+ USER,
+ new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
+ ACLDiff.computeDiff(MailboxACL.EMPTY, MAILBOX_ACL),
+ TestId.of(23));
+
+ @Test
+ void mailboxAddedShouldBeWellDeSerializedWhenMissingNameSpace() {
+ assertThat(EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"user\": \"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isEqualTo(UPDATED_EVENT);
+ }
+
+ @Test
+ void mailboxAddedShouldBeWellDeSerializedWhenNullNameSpace() {
+ assertThat(EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":null," +
+ " \"user\": \"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isEqualTo(UPDATED_EVENT);
+ }
+ }
+
+ @Nested
+ class EmptyRightInMailboxACL {
+
+ private final String jsonNullRight =
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":\"\"}," +
+ " \"newACL\":{}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}";
+
+ private final MailboxACL mailboxACL = new MailboxACL(
+ new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights()));
+
+ private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated(
+ MailboxSession.SessionId.of(6),
+ USER,
+ new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
+ ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY),
+ TestId.of(23));
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() {
+ assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated))
+ .isEqualTo(jsonNullRight);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
+ assertThat(EVENT_SERIALIZER.fromJson(jsonNullRight).get())
+ .isEqualTo(mailboxACLUpdated);
+ }
+ }
+
+ @Nested
+ class DoubleRightInMailboxACL {
+
+ private final String jsonDoubleRight =
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":\"aa\"}," +
+ " \"newACL\":{}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}";
+
+ private final MailboxACL mailboxACL = new MailboxACL(
+ new MailboxACL.Entry(ENTRY_KEY, new MailboxACL.Rfc4314Rights(MailboxACL.Right.Administer)));
+
+ private final MailboxListener.MailboxACLUpdated mailboxACLUpdated = new MailboxListener.MailboxACLUpdated(
+ MailboxSession.SessionId.of(6),
+ USER,
+ new MailboxPath(MailboxConstants.USER_NAMESPACE, "bob", "mailboxName"),
+ ACLDiff.computeDiff(mailboxACL, MailboxACL.EMPTY),
+ TestId.of(23));
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellSerializedWithNullRight() {
+ assertThatJson(EVENT_SERIALIZER.toJson(mailboxACLUpdated))
+ .isNotEqualTo(jsonDoubleRight);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldBeWellDeSerializedWithNullUser() {
+ assertThat(EVENT_SERIALIZER.fromJson(jsonDoubleRight).get())
+ .isEqualTo(mailboxACLUpdated);
+ }
+ }
+
+ @Nested
+ class DeserializationErrors {
+
+ @Nested
+ class DeserializationErrorOnSessionId {
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingSessionId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullSessionId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":null," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenStringSessionId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":\"123\"," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnUser {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingUser() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":12345" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenUserIsNotWellFormatted() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user@domain@secondDomain\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnACLDiff {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingACLDiff() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnOldACL {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingOldACLinACLDiff() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Nested
+ class DeserializationErrorOnOldACLEntryKey {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$\":\"ar\"}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{1234:\"ar\"}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(JsonParseException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"\":\"ar\"}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullEntryKey() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{null:\"ar\"}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(JsonParseException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"-\":\"ar\"}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(StringIndexOutOfBoundsException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnOldACLRight {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInMailboxACL() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":\"unsupported\"}," +
+ " \"newACL\":{\"$any\":\"a\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(UnsupportedRightException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":null}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenRightIsNotStringInMailboxACL() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":1234}}," +
+ " \"newACL\":{}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnNewACL {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingNewACLinACLDiff() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Nested
+ class DeserializationErrorOnNewACLEntryKey {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNotIncludedNameInEntryKey() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsNotString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{1234:\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(JsonParseException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNameInEntryKeyIsEmpty() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullEntryKey() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{null:\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(JsonParseException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenEntryKeyIsNotWellFormatted() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"-\":\"ar\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(StringIndexOutOfBoundsException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnNewACLRight {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenUnsupportedRightInNewACL() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{\"$any\":\"a\"}," +
+ " \"newACL\":{\"$any\":\"unsupported\"}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(UnsupportedRightException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullRightInMailboxACL() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":null}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenRightIsNotString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":1234}}," +
+ " \"mailboxId\":\"23\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnMailboxId {
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMissingMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullMailboxId() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":null," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMailboxIdIsANumber() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":\"#private\"," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":123," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnMailboxPath {
+
+ @Nested
+ class DeserializationErrorOnNameSpace {
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNameSpaceIsNotAString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":\"bob\"," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnUser {
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenUserIsNotAString() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":180806," +
+ " \"name\":\"mailboxName\"" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+
+ @Nested
+ class DeserializationErrorOnMailboxName {
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenNullMailboxName() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":180806," +
+ " \"name\":null" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+
+ @Test
+ void mailboxACLUpdatedShouldThrowWhenMailboxNameIdIsANumber() {
+ assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(
+ "{" +
+ " \"MailboxACLUpdated\":{" +
+ " \"mailboxPath\":{" +
+ " \"namespace\":230192.06," +
+ " \"user\":\"bob\"," +
+ " \"name\":160205" +
+ " }," +
+ " \"aclDiff\":{" +
+ " \"oldACL\":{}," +
+ " \"newACL\":{\"$any\":\"ar\"}}," +
+ " \"mailboxId\":\"123\"," +
+ " \"sessionId\":6," +
+ " \"user\":\"user\"" +
+ " }" +
+ "}").get())
+ .isInstanceOf(NoSuchElementException.class);
+ }
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org