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

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

commit fe0a43d1b17c9ff34d6a3965e6691991bfc590a7
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Thu Apr 11 11:08:39 2019 +0700

    JAMES-2709 Provide the LinShare BlobExport mechanism as a viable choice
---
 pom.xml                                            |  5 ++
 server/container/guice/blob-export-guice/pom.xml   |  4 ++
 .../apache/james/modules/BlobExportImplChoice.java |  3 +-
 .../james/modules/BlobExportMechanismModule.java   |  8 +++-
 .../modules/LinshareBlobExportMechanismModule.java | 53 ++++++++++++++++++++++
 .../modules/BlobExportMechanismModuleTest.java     | 11 ++++-
 .../linshare/LinshareBlobExportMechanism.java      |  5 +-
 7 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3110ef9..1acee52 100644
--- a/pom.xml
+++ b/pom.xml
@@ -720,6 +720,11 @@
             </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
+                <artifactId>apache-james-linshare</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
                 <artifactId>apache-james-spamassassin</artifactId>
                 <version>${project.version}</version>
             </dependency>
diff --git a/server/container/guice/blob-export-guice/pom.xml 
b/server/container/guice/blob-export-guice/pom.xml
index c465ffc..b55785d 100644
--- a/server/container/guice/blob-export-guice/pom.xml
+++ b/server/container/guice/blob-export-guice/pom.xml
@@ -36,6 +36,10 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-linshare</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>blob-api-guice</artifactId>
         </dependency>
         <dependency>
diff --git 
a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
index a00eb78..8f4f201 100644
--- 
a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
+++ 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
@@ -30,7 +30,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 enum  BlobExportImplChoice {
-    LOCAL_FILE("localFile");
+    LOCAL_FILE("localFile"),
+    LINSHARE("linshare");
 
     private static Optional<BlobExportImplChoice> from(String implNameString) {
         Preconditions.checkNotNull(implNameString);
diff --git 
a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
index ae1d6c3..6e258c9 100644
--- 
a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
+++ 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
@@ -27,6 +27,7 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.blob.export.api.BlobExportMechanism;
 import org.apache.james.blob.export.file.LocalFileBlobExportMechanism;
+import org.apache.james.linshare.LinshareBlobExportMechanism;
 import org.apache.james.modules.mailbox.ConfigurationComponent;
 import org.apache.james.utils.PropertiesProvider;
 import org.slf4j.Logger;
@@ -44,6 +45,7 @@ public class BlobExportMechanismModule extends AbstractModule 
{
     @Override
     protected void configure() {
         install(new LocalFileBlobExportMechanismModule());
+        install(new LinshareBlobExportMechanismModule());
     }
 
     @VisibleForTesting
@@ -66,10 +68,14 @@ public class BlobExportMechanismModule extends 
AbstractModule {
     @VisibleForTesting
     @Provides
     @Singleton
-    BlobExportMechanism provideMechanism(BlobExportImplChoice implChoice, 
Provider<LocalFileBlobExportMechanism> localFileMechanismProvider) {
+    BlobExportMechanism provideMechanism(BlobExportImplChoice implChoice,
+                                         
Provider<LocalFileBlobExportMechanism> localFileMechanismProvider,
+                                         Provider<LinshareBlobExportMechanism> 
linshareMechanismProvider) {
         switch (implChoice) {
             case LOCAL_FILE:
                 return localFileMechanismProvider.get();
+            case LINSHARE:
+                return linshareMechanismProvider.get();
             default:
                 throw new RuntimeException("blobExportMechanism '" + 
implChoice.getImplName() + "' is not supported yet");
         }
diff --git 
a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LinshareBlobExportMechanismModule.java
 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LinshareBlobExportMechanismModule.java
new file mode 100644
index 0000000..b154cb6
--- /dev/null
+++ 
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LinshareBlobExportMechanismModule.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.modules;
+
+import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.linshare.LinshareConfiguration;
+import org.apache.james.linshare.client.LinshareAPI;
+import org.apache.james.modules.mailbox.ConfigurationComponent;
+import org.apache.james.utils.PropertiesProvider;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+
+public class LinshareBlobExportMechanismModule extends AbstractModule {
+    @Override
+    protected void configure() {
+    }
+
+    @Singleton
+    @Provides
+    LinshareConfiguration linshareConfiguration(PropertiesProvider 
propertiesProvider) throws ConfigurationException, FileNotFoundException, 
MalformedURLException {
+        Configuration configuration = 
propertiesProvider.getConfigurations(ConfigurationComponent.NAMES);
+        return LinshareConfiguration.from(configuration);
+    }
+
+    @Singleton
+    @Provides
+    LinshareAPI linshare(LinshareConfiguration configuration) {
+        return LinshareAPI.from(configuration);
+    }
+}
diff --git 
a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
 
b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
index e011a90..f615527 100644
--- 
a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
+++ 
b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.FakePropertiesProvider;
 import org.apache.james.blob.export.file.LocalFileBlobExportMechanism;
+import org.apache.james.linshare.LinshareBlobExportMechanism;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -35,7 +36,9 @@ import com.google.inject.Provider;
 class BlobExportMechanismModuleTest {
 
     private static LocalFileBlobExportMechanism LOCAL_FILE_EXPORT = 
mock(LocalFileBlobExportMechanism.class);
+    private static LinshareBlobExportMechanism LINSHARE_EXPORT = 
mock(LinshareBlobExportMechanism.class);
     private static Provider<LocalFileBlobExportMechanism> 
LOCAL_FILE_EXPORT_PROVIDER = () -> LOCAL_FILE_EXPORT;
+    private static Provider<LinshareBlobExportMechanism> 
LINSHARE_FILE_EXPORT_PROVIDER = () -> LINSHARE_EXPORT;
 
     private BlobExportMechanismModule module;
 
@@ -91,7 +94,13 @@ class BlobExportMechanismModuleTest {
 
     @Test
     void provideMechanismShouldProvideFileExportWhenPassingLocalFileChoice() {
-        assertThat(module.provideMechanism(BlobExportImplChoice.LOCAL_FILE, 
LOCAL_FILE_EXPORT_PROVIDER))
+        assertThat(module.provideMechanism(BlobExportImplChoice.LOCAL_FILE, 
LOCAL_FILE_EXPORT_PROVIDER, LINSHARE_FILE_EXPORT_PROVIDER))
             .isEqualTo(LOCAL_FILE_EXPORT);
     }
+
+    @Test
+    void 
provideMechanismShouldProvideLinshareExportWhenPassingLinshareChoice() {
+        assertThat(module.provideMechanism(BlobExportImplChoice.LINSHARE, 
LOCAL_FILE_EXPORT_PROVIDER, LINSHARE_FILE_EXPORT_PROVIDER))
+            .isEqualTo(LINSHARE_EXPORT);
+    }
 }
\ No newline at end of file
diff --git 
a/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
 
b/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
index b5b7db4..042c966 100644
--- 
a/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
+++ 
b/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
@@ -23,6 +23,8 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Optional;
 
+import javax.inject.Inject;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
@@ -37,7 +39,8 @@ public class LinshareBlobExportMechanism implements 
BlobExportMechanism {
     private final LinshareAPI linshareAPI;
     private final BlobStore blobStore;
 
-    public LinshareBlobExportMechanism(LinshareAPI linshareAPI, BlobStore 
blobStore) {
+    @Inject
+    LinshareBlobExportMechanism(LinshareAPI linshareAPI, BlobStore blobStore) {
         this.linshareAPI = linshareAPI;
         this.blobStore = blobStore;
     }


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

Reply via email to