This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 012ed9be872113e3923b05502821eea4a3eb3079
Author: tran tien duc <[email protected]>
AuthorDate: Tue Feb 19 15:19:50 2019 +0700

    MAILBOX-379 Moving MetadataWithMailboxId to use in other places
    
    Will be used in StoreMessageManager
---
 .../james/mailbox/MetadataWithMailboxId.java       | 64 ++++++++++++++++++++++
 .../james/mailbox/MetadataWithMailboxIdTest.java   | 33 +++++++++++
 .../james/mailbox/store/StoreMessageIdManager.java | 24 ++------
 3 files changed, 102 insertions(+), 19 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/MetadataWithMailboxId.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/MetadataWithMailboxId.java
new file mode 100644
index 0000000..a33345e
--- /dev/null
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/MetadataWithMailboxId.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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;
+
+import java.util.Objects;
+
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageMetaData;
+
+public class MetadataWithMailboxId {
+
+    public static MetadataWithMailboxId from(MessageMetaData messageMetaData, 
MailboxId mailboxId) {
+        return new MetadataWithMailboxId(messageMetaData, mailboxId);
+    }
+
+    private final MessageMetaData messageMetaData;
+    private final MailboxId mailboxId;
+
+    private MetadataWithMailboxId(MessageMetaData messageMetaData, MailboxId 
mailboxId) {
+        this.messageMetaData = messageMetaData;
+        this.mailboxId = mailboxId;
+    }
+
+    public MessageMetaData getMessageMetaData() {
+        return messageMetaData;
+    }
+
+    public MailboxId getMailboxId() {
+        return mailboxId;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof MetadataWithMailboxId) {
+            MetadataWithMailboxId that = (MetadataWithMailboxId) o;
+
+            return Objects.equals(this.messageMetaData, that.messageMetaData)
+                && Objects.equals(this.mailboxId, that.mailboxId);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(messageMetaData, mailboxId);
+    }
+}
\ No newline at end of file
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/MetadataWithMailboxIdTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MetadataWithMailboxIdTest.java
new file mode 100644
index 0000000..3e795c3
--- /dev/null
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MetadataWithMailboxIdTest.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class MetadataWithMailboxIdTest {
+
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(MetadataWithMailboxId.class)
+            .verify();
+    }
+}
\ No newline at end of file
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 0ed5694..3031b9b 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
@@ -80,20 +80,6 @@ import reactor.core.publisher.Mono;
 
 public class StoreMessageIdManager implements MessageIdManager {
 
-    private static class MetadataWithMailboxId {
-        private final MessageMetaData messageMetaData;
-        private final MailboxId mailboxId;
-
-        public MetadataWithMailboxId(MessageMetaData messageMetaData, 
MailboxId mailboxId) {
-            this.messageMetaData = messageMetaData;
-            this.mailboxId = mailboxId;
-        }
-    }
-
-    private static MetadataWithMailboxId 
toMetadataWithMailboxId(MailboxMessage message) {
-        return new MetadataWithMailboxId(message.metaData(), 
message.getMailboxId());
-    }
-
     public static ImmutableSet<MailboxId> toMailboxIds(List<MailboxMessage> 
mailboxMessages) {
         return mailboxMessages
             .stream()
@@ -211,7 +197,7 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 
     private void delete(MessageIdMapper messageIdMapper, List<MailboxMessage> 
messageList, MailboxSession mailboxSession) throws MailboxException {
         ImmutableList<MetadataWithMailboxId> metadataWithMailbox = 
messageList.stream()
-            .map(StoreMessageIdManager::toMetadataWithMailboxId)
+            .map(MetadataWithMailboxId::from)
             .collect(Guavate.toImmutableList());
 
         messageIdMapper.delete(
@@ -222,14 +208,14 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 
         MailboxMapper mailboxMapper = 
mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
         Flux.fromIterable(metadataWithMailbox)
-            .flatMap(Throwing.<StoreMessageIdManager.MetadataWithMailboxId, 
Mono<Void>>function(
+            .flatMap(Throwing.<MetadataWithMailboxId, Mono<Void>>function(
                 metadataWithMailboxId -> 
eventBus.dispatch(EventFactory.expunged()
                     .randomEventId()
                     .mailboxSession(mailboxSession)
-                    
.mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId))
-                    .addMetaData(metadataWithMailboxId.messageMetaData)
+                    
.mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.getMailboxId()))
+                    .addMetaData(metadataWithMailboxId.getMessageMetaData())
                     .build(),
-                new MailboxIdRegistrationKey(metadataWithMailboxId.mailboxId)))
+                new 
MailboxIdRegistrationKey(metadataWithMailboxId.getMailboxId())))
                 .sneakyThrow())
             .then()
             .block();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to