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

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

commit 55a09898a5c7501c3460ce37d847ed38f133d593
Author: Quan Tran <hqt...@linagora.com>
AuthorDate: Tue Jan 2 16:09:28 2024 +0700

    JAMES-2586 Guice binding + module chooser + sample config for Postgres 
DeletedMessageVault
---
 .../deletedMessageVault.properties                 |  7 ++++
 .../apache/james/PostgresJamesConfiguration.java   | 33 ++++++++++++++--
 .../org/apache/james/PostgresJamesServerMain.java  | 14 +++++++
 .../org/apache/james/PostgresJamesServerTest.java  |  2 +
 server/container/guice/mailbox-postgres/pom.xml    |  4 ++
 .../mailbox/PostgresDeletedMessageVaultModule.java | 44 ++++++++++++++++++++++
 6 files changed, 100 insertions(+), 4 deletions(-)

diff --git 
a/server/apps/postgres-app/sample-configuration/deletedMessageVault.properties 
b/server/apps/postgres-app/sample-configuration/deletedMessageVault.properties
new file mode 100644
index 0000000000..a6df89a227
--- /dev/null
+++ 
b/server/apps/postgres-app/sample-configuration/deletedMessageVault.properties
@@ -0,0 +1,7 @@
+# ============================================= Deleted Messages Vault 
Configuration ==================================
+
+enabled=false
+
+# Retention period for your deleted messages into the vault, after which they 
expire and can be potentially cleaned up
+# Optional, default 1y
+# retentionPeriod=1y
\ No newline at end of file
diff --git 
a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
 
b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
index 26bad105be..d526c89237 100644
--- 
a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
+++ 
b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
@@ -34,6 +34,7 @@ import 
org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.server.core.configuration.FileConfigurationProvider;
 import org.apache.james.server.core.filesystem.FileSystemImpl;
 import org.apache.james.utils.PropertiesProvider;
+import org.apache.james.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,8 +70,8 @@ public class PostgresJamesConfiguration implements 
Configuration {
         private Optional<UsersRepositoryModuleChooser.Implementation> 
usersRepositoryImplementation;
         private Optional<SearchConfiguration> searchConfiguration;
         private Optional<BlobStoreConfiguration> blobStoreConfiguration;
-
         private Optional<EventBusImpl> eventBusImpl;
+        private Optional<VaultConfiguration> deletedMessageVaultConfiguration;
 
         private Builder() {
             searchConfiguration = Optional.empty();
@@ -79,6 +80,7 @@ public class PostgresJamesConfiguration implements 
Configuration {
             usersRepositoryImplementation = Optional.empty();
             blobStoreConfiguration = Optional.empty();
             eventBusImpl = Optional.empty();
+            deletedMessageVaultConfiguration = Optional.empty();
         }
 
         public Builder workingDirectory(String path) {
@@ -129,6 +131,11 @@ public class PostgresJamesConfiguration implements 
Configuration {
             return this;
         }
 
+        public Builder deletedMessageVaultConfiguration(VaultConfiguration 
vaultConfiguration) {
+            this.deletedMessageVaultConfiguration = 
Optional.of(vaultConfiguration);
+            return this;
+        }
+
         public PostgresJamesConfiguration build() {
             ConfigurationPath configurationPath = 
this.configurationPath.orElse(new 
ConfigurationPath(FileSystem.FILE_PROTOCOL_AND_CONF));
             JamesServerResourceLoader directories = new 
JamesServerResourceLoader(rootDirectory
@@ -154,13 +161,24 @@ public class PostgresJamesConfiguration implements 
Configuration {
 
             EventBusImpl eventBusImpl = this.eventBusImpl.orElseGet(() -> 
EventBusImpl.from(propertiesProvider));
 
+            VaultConfiguration deletedMessageVaultConfiguration = 
this.deletedMessageVaultConfiguration.orElseGet(() -> {
+                try {
+                    return 
VaultConfiguration.from(propertiesProvider.getConfiguration("deletedMessageVault"));
+                } catch (FileNotFoundException e) {
+                    return VaultConfiguration.DEFAULT;
+                } catch (ConfigurationException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
             return new PostgresJamesConfiguration(
                 configurationPath,
                 directories,
                 searchConfiguration,
                 usersRepositoryChoice,
                 blobStoreConfiguration,
-                eventBusImpl);
+                eventBusImpl,
+                deletedMessageVaultConfiguration);
         }
     }
 
@@ -174,19 +192,22 @@ public class PostgresJamesConfiguration implements 
Configuration {
     private final UsersRepositoryModuleChooser.Implementation 
usersRepositoryImplementation;
     private final BlobStoreConfiguration blobStoreConfiguration;
     private final EventBusImpl eventBusImpl;
-
+    private final VaultConfiguration deletedMessageVaultConfiguration;
 
     private PostgresJamesConfiguration(ConfigurationPath configurationPath,
                                        JamesDirectoriesProvider directories,
                                        SearchConfiguration searchConfiguration,
                                        
UsersRepositoryModuleChooser.Implementation usersRepositoryImplementation,
-                                       BlobStoreConfiguration 
blobStoreConfiguration, EventBusImpl eventBusImpl) {
+                                       BlobStoreConfiguration 
blobStoreConfiguration,
+                                       EventBusImpl eventBusImpl,
+                                       VaultConfiguration 
deletedMessageVaultConfiguration) {
         this.configurationPath = configurationPath;
         this.directories = directories;
         this.searchConfiguration = searchConfiguration;
         this.usersRepositoryImplementation = usersRepositoryImplementation;
         this.blobStoreConfiguration = blobStoreConfiguration;
         this.eventBusImpl = eventBusImpl;
+        this.deletedMessageVaultConfiguration = 
deletedMessageVaultConfiguration;
     }
 
     @Override
@@ -214,4 +235,8 @@ public class PostgresJamesConfiguration implements 
Configuration {
     public EventBusImpl eventBusImpl() {
         return eventBusImpl;
     }
+
+    public VaultConfiguration getDeletedMessageVaultConfiguration() {
+        return deletedMessageVaultConfiguration;
+    }
 }
diff --git 
a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
 
b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
index a106e0da41..fd07cc23ac 100644
--- 
a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
+++ 
b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.james.blob.api.BlobReferenceSource;
 import org.apache.james.data.UsersRepositoryModuleChooser;
+import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.MailetProcessingModule;
 import org.apache.james.modules.RunArgumentsModule;
@@ -36,6 +37,7 @@ import org.apache.james.modules.event.RabbitMQEventBusModule;
 import org.apache.james.modules.events.PostgresDeadLetterModule;
 import org.apache.james.modules.eventstore.MemoryEventStoreModule;
 import org.apache.james.modules.mailbox.DefaultEventModule;
+import org.apache.james.modules.mailbox.PostgresDeletedMessageVaultModule;
 import org.apache.james.modules.mailbox.PostgresMailboxModule;
 import org.apache.james.modules.mailbox.TikaMailboxModule;
 import org.apache.james.modules.protocols.IMAPServerModule;
@@ -60,7 +62,9 @@ import org.apache.james.modules.server.SieveRoutesModule;
 import org.apache.james.modules.server.TaskManagerModule;
 import 
org.apache.james.modules.server.WebAdminReIndexingTaskSerializationModule;
 import org.apache.james.modules.server.WebAdminServerModule;
+import org.apache.james.modules.vault.DeletedMessageVaultRoutesModule;
 import org.apache.james.server.blob.deduplication.StorageStrategy;
+import org.apache.james.vault.VaultConfiguration;
 
 import com.google.common.collect.ImmutableList;
 import com.google.inject.Module;
@@ -91,6 +95,7 @@ public class PostgresJamesServerMain implements 
JamesServerMain {
 
     private static final Module POSTGRES_SERVER_MODULE = Modules.combine(
         new ActiveMQQueueModule(),
+        new BlobExportMechanismModule(),
         new PostgresDelegationStoreModule(),
         new DefaultProcessorsConfigurationProviderModule(),
         new PostgresMailboxModule(),
@@ -131,6 +136,7 @@ public class PostgresJamesServerMain implements 
JamesServerMain {
                 
.chooseModules(configuration.getUsersRepositoryImplementation()))
             .combineWith(chooseBlobStoreModules(configuration))
             .combineWith(chooseEventBusModules(configuration))
+            
.combineWith(chooseDeletedMessageVaultModules(configuration.getDeletedMessageVaultConfiguration()))
             .combineWith(POSTGRES_MODULE_AGGREGATE);
     }
 
@@ -158,4 +164,12 @@ public class PostgresJamesServerMain implements 
JamesServerMain {
                 throw new RuntimeException("Unsupported event-bus 
implementation " + configuration.eventBusImpl().name());
         }
     }
+
+    private static Module chooseDeletedMessageVaultModules(VaultConfiguration 
vaultConfiguration) {
+        if (vaultConfiguration.isEnabled()) {
+            return Modules.combine(new PostgresDeletedMessageVaultModule(), 
new DeletedMessageVaultRoutesModule());
+        }
+
+        return Modules.EMPTY_MODULE;
+    }
 }
diff --git 
a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
 
b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
index ca25ff6c9e..6d7ba64109 100644
--- 
a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
+++ 
b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
@@ -33,6 +33,7 @@ import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
 import org.apache.james.utils.TestIMAPClient;
+import org.apache.james.vault.VaultConfiguration;
 import org.awaitility.Awaitility;
 import org.awaitility.core.ConditionFactory;
 import org.junit.jupiter.api.BeforeEach;
@@ -52,6 +53,7 @@ class PostgresJamesServerTest implements 
JamesServerConcreteContract {
             .searchConfiguration(SearchConfiguration.scanning())
             .usersRepository(DEFAULT)
             .eventBusImpl(EventBusImpl.IN_MEMORY)
+            
.deletedMessageVaultConfiguration(VaultConfiguration.ENABLED_DEFAULT)
             .build())
         .server(PostgresJamesServerMain::createServer)
         .extension(postgresExtension)
diff --git a/server/container/guice/mailbox-postgres/pom.xml 
b/server/container/guice/mailbox-postgres/pom.xml
index 3f345720af..28da17432d 100644
--- a/server/container/guice/mailbox-postgres/pom.xml
+++ b/server/container/guice/mailbox-postgres/pom.xml
@@ -33,6 +33,10 @@
     <name>Apache James :: Server :: Postgres - Guice injection</name>
 
     <dependencies>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            
<artifactId>apache-james-mailbox-deleted-messages-vault-postgres</artifactId>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-postgres</artifactId>
diff --git 
a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresDeletedMessageVaultModule.java
 
b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresDeletedMessageVaultModule.java
new file mode 100644
index 0000000000..6e874b0d4f
--- /dev/null
+++ 
b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresDeletedMessageVaultModule.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.mailbox;
+
+import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.modules.vault.DeletedMessageVaultModule;
+import org.apache.james.vault.metadata.DeletedMessageMetadataVault;
+import org.apache.james.vault.metadata.PostgresDeletedMessageMetadataModule;
+import org.apache.james.vault.metadata.PostgresDeletedMessageMetadataVault;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.multibindings.Multibinder;
+
+public class PostgresDeletedMessageVaultModule extends AbstractModule {
+    @Override
+    protected void configure() {
+        install(new DeletedMessageVaultModule());
+
+        Multibinder<PostgresModule> postgresDataDefinitions = 
Multibinder.newSetBinder(binder(), PostgresModule.class);
+        
postgresDataDefinitions.addBinding().toInstance(PostgresDeletedMessageMetadataModule.MODULE);
+
+        bind(PostgresDeletedMessageMetadataVault.class).in(Scopes.SINGLETON);
+        bind(DeletedMessageMetadataVault.class)
+            .to(PostgresDeletedMessageMetadataVault.class);
+    }
+}


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

Reply via email to