From 4ea92e39d7a8022501ee257680909d850fb52880 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Fri, 13 Dec 2024 15:52:03 +0100 Subject: [PATCH] Move memory implementations in jmap-extensions to jmap-extensions-api (#1406) --- .../tmail/james/app/MemoryServer.java | 12 ++--- .../jmap/MemoryEmailAddressContactModule.java | 45 +++++++++++++++++++ ...yFirebaseSubscriptionRepositoryModule.java | 22 +++++++++ .../MemoryJmapSettingsRepositoryModule.java | 29 ++++++++++++ .../jmap/MemoryLabelRepositoryModule.java | 33 ++++++++++++++ .../jmap/PublicAssetsMemoryModule.java | 14 ++++++ tmail-backend/jmap/extensions-api/pom.xml | 10 +++++ .../MemoryFirebaseSubscriptionRepository.java | 17 ------- .../EmailAddressContactEventModule.scala | 31 ------------- .../label/MemoryLabelChangeRepository.scala | 0 .../jmap/label/MemoryLabelRepository.scala | 23 +--------- .../MemoryPublicAssetRepository.scala | 0 .../MemoryJmapSettingsRepository.scala | 16 ------- .../james/jmap/ticket/MemoryTicketStore.scala | 21 +++++++++ ...yEmailAddressContactSearchEngineTest.scala | 0 ...ryFirebaseSubscriptionRepositoryTest.scala | 0 .../MemoryLabelChangeRepositoryTest.scala | 0 .../label/MemoryLabelRepositoryTest.scala | 0 .../MemoryPublicAssetRepositoryTest.scala | 6 +-- .../MemoryPublicAssetServiceTest.scala | 6 +-- .../MemoryJmapSettingsRepositoryTest.scala | 0 .../jmap/ticket/MemoryTicketStoreTest.scala | 0 .../jmap/publicAsset/PublicAssetsModule.scala | 7 --- .../james/jmap/ticket/TicketManager.scala | 18 -------- 24 files changed, 186 insertions(+), 124 deletions(-) create mode 100644 tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryEmailAddressContactModule.java create mode 100644 tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryFirebaseSubscriptionRepositoryModule.java create mode 100644 tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryJmapSettingsRepositoryModule.java create mode 100644 tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryLabelRepositoryModule.java create mode 100644 tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/PublicAssetsMemoryModule.java rename tmail-backend/jmap/{extensions => extensions-api}/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java (89%) delete mode 100644 tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/contact/EmailAddressContactEventModule.scala rename tmail-backend/jmap/{extensions => extensions-api}/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepository.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala (71%) rename tmail-backend/jmap/{extensions => extensions-api}/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepository.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala (83%) create mode 100644 tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStore.scala rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/contact/MemoryEmailAddressContactSearchEngineTest.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepositoryTest.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepositoryTest.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepositoryTest.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala (80%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala (80%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepositoryTest.scala (100%) rename tmail-backend/jmap/{extensions => extensions-api}/src/test/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStoreTest.scala (100%) diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/MemoryServer.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/MemoryServer.java index 7dc6a8f774..8b420b34d1 100644 --- a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/MemoryServer.java +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/MemoryServer.java @@ -59,13 +59,15 @@ import com.linagora.tmail.encrypted.KeystoreMemoryModule; import com.linagora.tmail.encrypted.MailboxConfiguration; import com.linagora.tmail.imap.TMailIMAPModule; +import com.linagora.tmail.james.app.modules.jmap.MemoryEmailAddressContactModule; +import com.linagora.tmail.james.app.modules.jmap.MemoryFirebaseSubscriptionRepositoryModule; +import com.linagora.tmail.james.app.modules.jmap.MemoryJmapSettingsRepositoryModule; +import com.linagora.tmail.james.app.modules.jmap.MemoryLabelRepositoryModule; +import com.linagora.tmail.james.app.modules.jmap.PublicAssetsMemoryModule; import com.linagora.tmail.james.jmap.ContactSupportCapabilitiesModule; import com.linagora.tmail.james.jmap.TMailJMAPModule; -import com.linagora.tmail.james.jmap.contact.MemoryEmailAddressContactModule; import com.linagora.tmail.james.jmap.firebase.FirebaseCommonModule; import com.linagora.tmail.james.jmap.firebase.FirebaseModuleChooserConfiguration; -import com.linagora.tmail.james.jmap.firebase.MemoryFirebaseSubscriptionRepository; -import com.linagora.tmail.james.jmap.label.MemoryLabelRepositoryModule; import com.linagora.tmail.james.jmap.mail.TMailMailboxSortOrderProviderModule; import com.linagora.tmail.james.jmap.method.CalendarEventMethodModule; import com.linagora.tmail.james.jmap.method.ContactAutocompleteMethodModule; @@ -84,11 +86,9 @@ import com.linagora.tmail.james.jmap.method.LabelMethodModule; import com.linagora.tmail.james.jmap.method.MessageVaultCapabilitiesModule; import com.linagora.tmail.james.jmap.oidc.WebFingerModule; -import com.linagora.tmail.james.jmap.publicAsset.PublicAssetsMemoryModule; import com.linagora.tmail.james.jmap.publicAsset.PublicAssetsModule; import com.linagora.tmail.james.jmap.service.discovery.LinagoraServicesDiscoveryModule; import com.linagora.tmail.james.jmap.service.discovery.LinagoraServicesDiscoveryModuleChooserConfiguration; -import com.linagora.tmail.james.jmap.settings.MemoryJmapSettingsRepositoryModule; import com.linagora.tmail.james.jmap.team.mailboxes.TeamMailboxJmapModule; import com.linagora.tmail.james.jmap.ticket.TicketRoutesModule; import com.linagora.tmail.rate.limiter.api.memory.MemoryRateLimitingModule; @@ -226,7 +226,7 @@ private static List chooseMailbox(MailboxConfiguration mailboxConfigurat private static List chooseFirebase(FirebaseModuleChooserConfiguration moduleChooserConfiguration) { if (moduleChooserConfiguration.enable()) { - return List.of(new MemoryFirebaseSubscriptionRepository.Module(), new FirebaseCommonModule()); + return List.of(new MemoryFirebaseSubscriptionRepositoryModule(), new FirebaseCommonModule()); } return List.of(); } diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryEmailAddressContactModule.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryEmailAddressContactModule.java new file mode 100644 index 0000000000..e6a3e1bead --- /dev/null +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryEmailAddressContactModule.java @@ -0,0 +1,45 @@ +package com.linagora.tmail.james.app.modules.jmap; + +import org.apache.james.events.EventBus; +import org.apache.james.lifecycle.api.Startable; +import org.apache.james.utils.InitializationOperation; +import org.apache.james.utils.InitilizationOperationBuilder; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.multibindings.ProvidesIntoSet; +import com.google.inject.name.Named; +import com.linagora.tmail.james.jmap.EmailAddressContactInjectKeys; +import com.linagora.tmail.james.jmap.contact.EmailAddressContactListener; +import com.linagora.tmail.james.jmap.contact.InMemoryEmailAddressContactSearchEngineModule; + +public class MemoryEmailAddressContactModule extends AbstractModule { + + @Override + protected void configure() { + install(new InMemoryEmailAddressContactSearchEngineModule()); + } + + @ProvidesIntoSet + public InitializationOperation registerListener( + @Named(EmailAddressContactInjectKeys.AUTOCOMPLETE) EventBus eventBus, + EmailAddressContactListener emailAddressContactListener) { + return InitilizationOperationBuilder + .forClass(EmailAddressContactEventLoader.class) + .init(() -> eventBus.register(emailAddressContactListener)); + } + + @Provides + @Singleton + @Named(EmailAddressContactInjectKeys.AUTOCOMPLETE) + public EventBus provideInVMEventBus(EventBus eventBus) { + return eventBus; + } + + public static class EmailAddressContactEventLoader implements Startable { + + } +} + + diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryFirebaseSubscriptionRepositoryModule.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryFirebaseSubscriptionRepositoryModule.java new file mode 100644 index 0000000000..542c2985f8 --- /dev/null +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryFirebaseSubscriptionRepositoryModule.java @@ -0,0 +1,22 @@ +package com.linagora.tmail.james.app.modules.jmap; + +import org.apache.james.user.api.DeleteUserDataTaskStep; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; +import com.linagora.tmail.james.jmap.firebase.FirebaseSubscriptionRepository; +import com.linagora.tmail.james.jmap.firebase.FirebaseSubscriptionUserDeletionTaskStep; +import com.linagora.tmail.james.jmap.firebase.MemoryFirebaseSubscriptionRepository; + +public class MemoryFirebaseSubscriptionRepositoryModule extends AbstractModule { + @Override + protected void configure() { + bind(MemoryFirebaseSubscriptionRepository.class).in(Scopes.SINGLETON); + bind(FirebaseSubscriptionRepository.class).to(MemoryFirebaseSubscriptionRepository.class); + + Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class) + .addBinding() + .to(FirebaseSubscriptionUserDeletionTaskStep.class); + } +} diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryJmapSettingsRepositoryModule.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryJmapSettingsRepositoryModule.java new file mode 100644 index 0000000000..005851dc52 --- /dev/null +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryJmapSettingsRepositoryModule.java @@ -0,0 +1,29 @@ +package com.linagora.tmail.james.app.modules.jmap; + +import org.apache.james.user.api.DeleteUserDataTaskStep; +import org.apache.james.user.api.UsernameChangeTaskStep; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; +import com.linagora.tmail.james.jmap.settings.JmapSettingsRepository; +import com.linagora.tmail.james.jmap.settings.JmapSettingsUserDeletionTaskStep; +import com.linagora.tmail.james.jmap.settings.JmapSettingsUsernameChangeTaskStep; +import com.linagora.tmail.james.jmap.settings.MemoryJmapSettingsRepository; + +public class MemoryJmapSettingsRepositoryModule extends AbstractModule { + @Override + protected void configure() { + bind(MemoryJmapSettingsRepository.class).in(Scopes.SINGLETON); + bind(JmapSettingsRepository.class).to(MemoryJmapSettingsRepository.class) + .in(Scopes.SINGLETON); + + Multibinder.newSetBinder(binder(), UsernameChangeTaskStep.class) + .addBinding() + .to(JmapSettingsUsernameChangeTaskStep.class); + + Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class) + .addBinding() + .to(JmapSettingsUserDeletionTaskStep.class); + } +} diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryLabelRepositoryModule.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryLabelRepositoryModule.java new file mode 100644 index 0000000000..f4e2605d16 --- /dev/null +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/MemoryLabelRepositoryModule.java @@ -0,0 +1,33 @@ +package com.linagora.tmail.james.app.modules.jmap; + +import org.apache.james.user.api.DeleteUserDataTaskStep; +import org.apache.james.user.api.UsernameChangeTaskStep; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; +import com.linagora.tmail.james.jmap.label.LabelChangeRepository; +import com.linagora.tmail.james.jmap.label.LabelRepository; +import com.linagora.tmail.james.jmap.label.LabelUserDeletionTaskStep; +import com.linagora.tmail.james.jmap.label.LabelUsernameChangeTaskStep; +import com.linagora.tmail.james.jmap.label.MemoryLabelChangeRepository; +import com.linagora.tmail.james.jmap.label.MemoryLabelRepository; + +public class MemoryLabelRepositoryModule extends AbstractModule { + @Override + protected void configure() { + bind(LabelRepository.class).to(MemoryLabelRepository.class); + bind(MemoryLabelRepository.class).in(Scopes.SINGLETON); + + Multibinder.newSetBinder(binder(), UsernameChangeTaskStep.class) + .addBinding() + .to(LabelUsernameChangeTaskStep.class); + + Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class) + .addBinding() + .to(LabelUserDeletionTaskStep.class); + + bind(LabelChangeRepository.class).to(MemoryLabelChangeRepository.class); + bind(MemoryLabelChangeRepository.class).in(Scopes.SINGLETON); + } +} diff --git a/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/PublicAssetsMemoryModule.java b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/PublicAssetsMemoryModule.java new file mode 100644 index 0000000000..8b326eaed4 --- /dev/null +++ b/tmail-backend/apps/memory/src/main/java/com/linagora/tmail/james/app/modules/jmap/PublicAssetsMemoryModule.java @@ -0,0 +1,14 @@ +package com.linagora.tmail.james.app.modules.jmap; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.linagora.tmail.james.jmap.publicAsset.MemoryPublicAssetRepository; +import com.linagora.tmail.james.jmap.publicAsset.PublicAssetRepository; + +public class PublicAssetsMemoryModule extends AbstractModule { + @Override + protected void configure() { + bind(MemoryPublicAssetRepository.class).in(Scopes.SINGLETON); + bind(PublicAssetRepository.class).to(MemoryPublicAssetRepository.class); + } +} diff --git a/tmail-backend/jmap/extensions-api/pom.xml b/tmail-backend/jmap/extensions-api/pom.xml index 2db88b9577..b3bca6d0fe 100644 --- a/tmail-backend/jmap/extensions-api/pom.xml +++ b/tmail-backend/jmap/extensions-api/pom.xml @@ -16,6 +16,16 @@ + + ${james.groupId} + blob-memory + test + + + ${james.groupId} + blob-storage-strategy + test + ${james.groupId} james-server-data-jmap diff --git a/tmail-backend/jmap/extensions/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java b/tmail-backend/jmap/extensions-api/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java similarity index 89% rename from tmail-backend/jmap/extensions/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java rename to tmail-backend/jmap/extensions-api/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java index 885fa84ae4..2aeef8a172 100644 --- a/tmail-backend/jmap/extensions/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java +++ b/tmail-backend/jmap/extensions-api/src/main/java/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepository.java @@ -13,14 +13,10 @@ import org.apache.james.core.Username; import org.apache.james.jmap.api.model.TypeName; -import org.apache.james.user.api.DeleteUserDataTaskStep; import org.reactivestreams.Publisher; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; -import com.google.inject.multibindings.Multibinder; import com.linagora.tmail.james.jmap.model.DeviceClientIdInvalidException; import com.linagora.tmail.james.jmap.model.ExpireTimeInvalidException; import com.linagora.tmail.james.jmap.model.FirebaseSubscription; @@ -36,19 +32,6 @@ import scala.jdk.javaapi.OptionConverters; public class MemoryFirebaseSubscriptionRepository implements FirebaseSubscriptionRepository { - - public static class Module extends AbstractModule { - @Override - protected void configure() { - bind(MemoryFirebaseSubscriptionRepository.class).in(Scopes.SINGLETON); - bind(FirebaseSubscriptionRepository.class).to(MemoryFirebaseSubscriptionRepository.class); - - Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class) - .addBinding() - .to(FirebaseSubscriptionUserDeletionTaskStep.class); - } - } - private final Table table; private final Clock clock; diff --git a/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/contact/EmailAddressContactEventModule.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/contact/EmailAddressContactEventModule.scala deleted file mode 100644 index 8acebda6ad..0000000000 --- a/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/contact/EmailAddressContactEventModule.scala +++ /dev/null @@ -1,31 +0,0 @@ -package com.linagora.tmail.james.jmap.contact - -import com.google.inject.multibindings.ProvidesIntoSet -import com.google.inject.name.Named -import com.google.inject.{AbstractModule, Provides, Singleton} -import com.linagora.tmail.james.jmap.EmailAddressContactInjectKeys -import org.apache.james.events.EventBus -import org.apache.james.lifecycle.api.Startable -import org.apache.james.utils.{InitializationOperation, InitilizationOperationBuilder} - -class MemoryEmailAddressContactModule extends AbstractModule { - - override def configure(): Unit = { - install(new InMemoryEmailAddressContactSearchEngineModule) - } - - @ProvidesIntoSet - def registerListener(@Named(EmailAddressContactInjectKeys.AUTOCOMPLETE) eventBus: EventBus, - emailAddressContactListener: EmailAddressContactListener): InitializationOperation = { - InitilizationOperationBuilder.forClass(classOf[EmailAddressContactEventLoader]) - .init(() => eventBus.register(emailAddressContactListener)) - } - - @Provides - @Singleton - @Named(EmailAddressContactInjectKeys.AUTOCOMPLETE) - def provideInVMEventBus(eventBus: EventBus): EventBus = eventBus - -} - -class EmailAddressContactEventLoader extends Startable diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepository.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepository.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepository.scala rename to tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepository.scala diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala similarity index 71% rename from tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala rename to tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala index edc2566e27..c6fe55d7cb 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala +++ b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepository.scala @@ -3,12 +3,9 @@ package com.linagora.tmail.james.jmap.label import java.util import com.google.common.collect.{HashBasedTable, ImmutableList, Table, Tables} -import com.google.inject.multibindings.Multibinder -import com.google.inject.{AbstractModule, Scopes} -import com.linagora.tmail.james.jmap.model.{Color, DisplayName, Label, LabelCreationRequest, LabelId, LabelNotFoundException} +import com.linagora.tmail.james.jmap.model._ import org.apache.james.core.Username import org.apache.james.jmap.mail.Keyword -import org.apache.james.user.api.{DeleteUserDataTaskStep, UsernameChangeTaskStep} import org.reactivestreams.Publisher import reactor.core.scala.publisher.{SFlux, SMono} @@ -54,22 +51,4 @@ class MemoryLabelRepository extends LabelRepository { override def deleteAllLabels(username: Username): Publisher[Void] = SMono.fromCallable(() => labelsTable.row(username).clear()) .`then`() -} - -case class MemoryLabelRepositoryModule() extends AbstractModule { - override def configure(): Unit = { - bind(classOf[LabelRepository]).to(classOf[MemoryLabelRepository]) - bind(classOf[MemoryLabelRepository]).in(Scopes.SINGLETON) - - Multibinder.newSetBinder(binder(), classOf[UsernameChangeTaskStep]) - .addBinding() - .to(classOf[LabelUsernameChangeTaskStep]) - - Multibinder.newSetBinder(binder(), classOf[DeleteUserDataTaskStep]) - .addBinding() - .to(classOf[LabelUserDeletionTaskStep]) - - bind(classOf[LabelChangeRepository]).to(classOf[MemoryLabelChangeRepository]) - bind(classOf[MemoryLabelChangeRepository]).in(Scopes.SINGLETON) - } } \ No newline at end of file diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepository.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepository.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepository.scala rename to tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepository.scala diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala similarity index 83% rename from tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala rename to tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala index 313bee5ae1..c3f785a7c9 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala +++ b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepository.scala @@ -69,20 +69,4 @@ case class MemoryJmapSettingsRepository @Inject()() extends JmapSettingsReposito stateStore.remove(username) }) .`then`() -} - -case class MemoryJmapSettingsRepositoryModule() extends AbstractModule { - override def configure(): Unit = { - bind(classOf[MemoryJmapSettingsRepository]).in(Scopes.SINGLETON) - bind(classOf[JmapSettingsRepository]).to(classOf[MemoryJmapSettingsRepository]) - .in(Scopes.SINGLETON) - - Multibinder.newSetBinder(binder(), classOf[UsernameChangeTaskStep]) - .addBinding() - .to(classOf[JmapSettingsUsernameChangeTaskStep]) - - Multibinder.newSetBinder(binder(), classOf[DeleteUserDataTaskStep]) - .addBinding() - .to(classOf[JmapSettingsUserDeletionTaskStep]) - } } \ No newline at end of file diff --git a/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStore.scala b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStore.scala new file mode 100644 index 0000000000..7a7fae9c23 --- /dev/null +++ b/tmail-backend/jmap/extensions-api/src/main/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStore.scala @@ -0,0 +1,21 @@ +package com.linagora.tmail.james.jmap.ticket + +import reactor.core.scala.publisher.SMono + +import scala.collection.mutable + +class MemoryTicketStore extends TicketStore { + private val map: mutable.Map[TicketValue, Ticket] = mutable.Map() + + override def persist(ticket: Ticket): SMono[Unit] = + SMono.fromCallable(() => map.put(ticket.value, ticket)) + .`then` + + override def retrieve(value: TicketValue): SMono[Ticket] = map.get(value) + .map(SMono.just) + .getOrElse(SMono.empty) + + override def delete(ticketValue: TicketValue): SMono[Unit] = + SMono.fromCallable(() => map.remove(ticketValue)) + .`then` +} diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/contact/MemoryEmailAddressContactSearchEngineTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/contact/MemoryEmailAddressContactSearchEngineTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/contact/MemoryEmailAddressContactSearchEngineTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/contact/MemoryEmailAddressContactSearchEngineTest.scala diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepositoryTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepositoryTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepositoryTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/firebase/MemoryFirebaseSubscriptionRepositoryTest.scala diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepositoryTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepositoryTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepositoryTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelChangeRepositoryTest.scala diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepositoryTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepositoryTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepositoryTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/label/MemoryLabelRepositoryTest.scala diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala similarity index 80% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala index 31e6b306c9..98028a2a47 100644 --- a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala +++ b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetRepositoryTest.scala @@ -1,8 +1,6 @@ package com.linagora.tmail.james.jmap.publicAsset -import java.time.Clock - -import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration +import com.linagora.tmail.james.jmap.PublicAssetTotalSizeLimit import com.linagora.tmail.james.jmap.publicAsset.PublicAssetRepositoryContract.PUBLIC_ASSET_URI_PREFIX import org.apache.james.blob.api.BucketName import org.apache.james.blob.memory.MemoryBlobStoreDAO @@ -17,7 +15,7 @@ class MemoryPublicAssetRepositoryTest extends PublicAssetRepositoryContract { def setup(): Unit = { val blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO, BucketName.DEFAULT, blobIdFactory) - memoryPublicAssetRepository = new MemoryPublicAssetRepository(blobStore, JMAPExtensionConfiguration.PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT, PUBLIC_ASSET_URI_PREFIX) + memoryPublicAssetRepository = new MemoryPublicAssetRepository(blobStore, PublicAssetTotalSizeLimit.DEFAULT, PUBLIC_ASSET_URI_PREFIX) } override def teste: PublicAssetRepository = memoryPublicAssetRepository diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala similarity index 80% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala index f6e18926df..71075a18fb 100644 --- a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala +++ b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/MemoryPublicAssetServiceTest.scala @@ -1,6 +1,6 @@ package com.linagora.tmail.james.jmap.publicAsset -import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration +import com.linagora.tmail.james.jmap.PublicAssetTotalSizeLimit import com.linagora.tmail.james.jmap.publicAsset.PublicAssetRepositoryContract.PUBLIC_ASSET_URI_PREFIX import com.linagora.tmail.james.jmap.publicAsset.PublicAssetServiceContract.identityRepository import org.apache.james.blob.api.BucketName @@ -16,8 +16,8 @@ class MemoryPublicAssetServiceTest extends PublicAssetServiceContract { @BeforeEach def setup(): Unit = { val blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO, BucketName.DEFAULT, blobIdFactory) - memoryPublicAssetRepository = new MemoryPublicAssetRepository(blobStore, JMAPExtensionConfiguration.PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT, PUBLIC_ASSET_URI_PREFIX) - publicAssetSetService = new PublicAssetSetService(identityRepository, memoryPublicAssetRepository, JMAPExtensionConfiguration.PUBLIC_ASSET_TOTAL_SIZE_LIMIT_DEFAULT) + memoryPublicAssetRepository = new MemoryPublicAssetRepository(blobStore, PublicAssetTotalSizeLimit.DEFAULT, PUBLIC_ASSET_URI_PREFIX) + publicAssetSetService = new PublicAssetSetService(identityRepository, memoryPublicAssetRepository, PublicAssetTotalSizeLimit.DEFAULT) } override def testee: PublicAssetSetService = publicAssetSetService diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepositoryTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepositoryTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepositoryTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/settings/MemoryJmapSettingsRepositoryTest.scala diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStoreTest.scala b/tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStoreTest.scala similarity index 100% rename from tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStoreTest.scala rename to tmail-backend/jmap/extensions-api/src/test/scala/com/linagora/tmail/james/jmap/ticket/MemoryTicketStoreTest.scala diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetsModule.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetsModule.scala index 2078092fbd..7a0f927d27 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetsModule.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetsModule.scala @@ -42,11 +42,4 @@ class PublicAssetsModule extends AbstractModule { def providePublicAssetUriPrefix(jmapConfiguration: JmapRfc8621Configuration): URI = { PublicAssetURIPrefix.fromConfiguration(jmapConfiguration).fold(throw _, identity) } -} - -class PublicAssetsMemoryModule extends AbstractModule { - override def configure(): Unit = { - bind(classOf[MemoryPublicAssetRepository]).in(Scopes.SINGLETON) - bind(classOf[PublicAssetRepository]).to(classOf[MemoryPublicAssetRepository]) - } } \ No newline at end of file diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/ticket/TicketManager.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/ticket/TicketManager.scala index aac027b056..ea6fedce1b 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/ticket/TicketManager.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/ticket/TicketManager.scala @@ -9,8 +9,6 @@ import org.apache.james.core.Username import org.apache.james.jmap.core.UTCDate import reactor.core.scala.publisher.SMono -import scala.collection.mutable - object TicketManager { private val validity: java.time.Duration = java.time.Duration.ofMinutes(1) } @@ -53,20 +51,4 @@ class TicketManager @Inject() (clock: Clock, ticketStore: TicketStore, jmapExten .map(_.value) .switchIfEmpty(SMono.error(ForbiddenException())) .flatMap(ticketStore.delete) -} - -class MemoryTicketStore extends TicketStore { - private val map: mutable.Map[TicketValue, Ticket] = mutable.Map() - - override def persist(ticket: Ticket): SMono[Unit] = - SMono.fromCallable(() => map.put(ticket.value, ticket)) - .`then` - - override def retrieve(value: TicketValue): SMono[Ticket] = map.get(value) - .map(SMono.just) - .getOrElse(SMono.empty) - - override def delete(ticketValue: TicketValue): SMono[Unit] = - SMono.fromCallable(() => map.remove(ticketValue)) - .`then` } \ No newline at end of file