james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/19] james-project git commit: JAMES-2541 MimeMessageStore should not extend Store.Impl<MimeMessage>
Date Mon, 10 Sep 2018 10:34:05 GMT
JAMES-2541 MimeMessageStore should not extend Store.Impl<MimeMessage>

We'd better instantiate Store.Impl with the right parameters.


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

Branch: refs/heads/master
Commit: 9d216b219d50a534ba5da7b8f1d0e2f8c6cbd337
Parents: 0aef5b2
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Sep 7 09:43:03 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon Sep 10 17:17:41 2018 +0700

----------------------------------------------------------------------
 .../james/blob/mail/MimeMessageStore.java       | 32 +++++++++++++++-----
 .../james/blob/mail/MimeMessageStoreTest.java   |  7 +++--
 .../cassandra/CassandraMailRepository.java      |  5 +--
 .../CassandraMailRepositoryProvider.java        |  8 ++---
 .../cassandra/CassandraMailRepositoryTest.java  |  2 +-
 5 files changed, 36 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d216b21/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessageStore.java
----------------------------------------------------------------------
diff --git a/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessageStore.java
b/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessageStore.java
index e7ef327..adfc6ed 100644
--- a/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessageStore.java
+++ b/server/blob/mail-store/src/main/java/org/apache/james/blob/mail/MimeMessageStore.java
@@ -41,16 +41,33 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.Store;
+import org.apache.james.blob.api.Store.BlobType;
 import org.apache.james.util.BodyOffsetInputStream;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 
-public class MimeMessageStore extends Store.Impl<MimeMessage> {
-    public static final BlobType HEADER_BLOB_TYPE = new BlobType("mailHeader");
-    public static final BlobType BODY_BLOB_TYPE = new BlobType("mailBody");
+public class MimeMessageStore {
+    public static final Store.BlobType HEADER_BLOB_TYPE = new Store.BlobType("mailHeader");
+    public static final Store.BlobType BODY_BLOB_TYPE = new Store.BlobType("mailBody");
 
-    static class MailEncoder implements Encoder<MimeMessage> {
+    public static class Factory {
+        private final BlobStore blobStore;
+
+        @Inject
+        public Factory(BlobStore blobStore) {
+            this.blobStore = blobStore;
+        }
+
+        public Store<MimeMessage> mimeMessageStore() {
+            return new Store.Impl<>(
+                new MailEncoder(),
+                new MailDecoder(),
+                blobStore);
+        }
+    }
+
+    static class MailEncoder implements Store.Encoder<MimeMessage> {
         @Override
         public Stream<Pair<BlobType, InputStream>> encode(MimeMessage message)
{
             try {
@@ -107,7 +124,7 @@ public class MimeMessageStore extends Store.Impl<MimeMessage> {
         }
     }
 
-    static class MailDecoder implements Decoder<MimeMessage> {
+    static class MailDecoder implements Store.Decoder<MimeMessage> {
         @Override
         public void validateInput(Collection<BlobType> input) {
             Preconditions.checkArgument(input.contains(HEADER_BLOB_TYPE), "Expecting 'mailHeader'
blobId to be specified");
@@ -137,8 +154,7 @@ public class MimeMessageStore extends Store.Impl<MimeMessage> {
         }
     }
 
-    @Inject
-    public MimeMessageStore(BlobStore blobStore) {
-        super(new MailEncoder(), new MailDecoder(), blobStore);
+    public static Factory factory(BlobStore blobStore) {
+        return new Factory(blobStore);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d216b21/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
----------------------------------------------------------------------
diff --git a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
index 4db2110..0817963 100644
--- a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
+++ b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
@@ -28,6 +28,7 @@ import java.util.Map;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.api.Store;
 import org.apache.james.blob.memory.MemoryBlobStore;
@@ -41,13 +42,13 @@ import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
 class MimeMessageStoreTest {
     private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory();
 
-    private MimeMessageStore testee;
-    private MemoryBlobStore blobStore;
+    private Store<MimeMessage> testee;
+    private BlobStore blobStore;
 
     @BeforeEach
     void setUp() {
         blobStore = new MemoryBlobStore(BLOB_ID_FACTORY);
-        testee = new MimeMessageStore(blobStore);
+        testee = MimeMessageStore.factory(blobStore).mimeMessageStore();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d216b21/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
index d0b4cbe..d32a2d6 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
@@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionStage;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
 
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.Store;
@@ -46,11 +47,11 @@ public class CassandraMailRepository implements MailRepository {
     private final CassandraMailRepositoryKeysDAO keysDAO;
     private final CassandraMailRepositoryCountDAO countDAO;
     private final CassandraMailRepositoryMailDAO mailDAO;
-    private final MimeMessageStore mimeMessageStore;
+    private final Store<MimeMessage> mimeMessageStore;
 
     public CassandraMailRepository(MailRepositoryUrl url, CassandraMailRepositoryKeysDAO
keysDAO,
                                    CassandraMailRepositoryCountDAO countDAO, CassandraMailRepositoryMailDAO
mailDAO,
-                                   MimeMessageStore mimeMessageStore) {
+                                   Store<MimeMessage> mimeMessageStore) {
         this.url = url;
         this.keysDAO = keysDAO;
         this.countDAO = countDAO;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d216b21/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryProvider.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryProvider.java
b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryProvider.java
index 77d8ca4..d5c1077 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryProvider.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryProvider.java
@@ -30,15 +30,15 @@ public class CassandraMailRepositoryProvider implements MailRepositoryProvider
{
     private final CassandraMailRepositoryKeysDAO keysDAO;
     private final CassandraMailRepositoryCountDAO countDAO;
     private final CassandraMailRepositoryMailDAO mailDAO;
-    private final MimeMessageStore mimeMessageStore;
+    private final MimeMessageStore.Factory mimeMessageStoreFactory;
 
     @Inject
     public CassandraMailRepositoryProvider(CassandraMailRepositoryKeysDAO keysDAO, CassandraMailRepositoryCountDAO
countDAO,
-                                           CassandraMailRepositoryMailDAO mailDAO, MimeMessageStore
mimeMessageStore) {
+                                           CassandraMailRepositoryMailDAO mailDAO, MimeMessageStore.Factory
mimeMessageStoreFactory) {
         this.keysDAO = keysDAO;
         this.countDAO = countDAO;
         this.mailDAO = mailDAO;
-        this.mimeMessageStore = mimeMessageStore;
+        this.mimeMessageStoreFactory = mimeMessageStoreFactory;
     }
 
     @Override
@@ -48,6 +48,6 @@ public class CassandraMailRepositoryProvider implements MailRepositoryProvider
{
 
     @Override
     public MailRepository provide(MailRepositoryUrl url) {
-        return new CassandraMailRepository(url, keysDAO, countDAO, mailDAO, mimeMessageStore);
+        return new CassandraMailRepository(url, keysDAO, countDAO, mailDAO, mimeMessageStoreFactory.mimeMessageStore());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d216b21/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 8151a2a..64fdfd5 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -62,7 +62,7 @@ class CassandraMailRepositoryTest implements MailRepositoryContract {
         CassandraBlobsDAO blobsDAO = new CassandraBlobsDAO(cassandra.getConf());
 
         cassandraMailRepository = new CassandraMailRepository(URL,
-            keysDAO, countDAO, mailDAO, new MimeMessageStore(blobsDAO));
+            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobsDAO).mimeMessageStore());
     }
 
     @AfterEach


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message