Skip to content

Commit

Permalink
Move memory implementations in jmap-extensions to jmap-extensions-api (
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri authored Dec 13, 2024
1 parent 409de91 commit 4ea92e3
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -226,7 +226,7 @@ private static List<Module> chooseMailbox(MailboxConfiguration mailboxConfigurat

private static List<Module> chooseFirebase(FirebaseModuleChooserConfiguration moduleChooserConfiguration) {
if (moduleChooserConfiguration.enable()) {
return List.of(new MemoryFirebaseSubscriptionRepository.Module(), new FirebaseCommonModule());
return List.of(new MemoryFirebaseSubscriptionRepositoryModule(), new FirebaseCommonModule());
}
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
}


Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions tmail-backend/jmap/extensions-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
</properties>

<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>blob-memory</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>blob-storage-strategy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-data-jmap</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Username, FirebaseSubscriptionId, FirebaseSubscription> table;
private final Clock clock;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Original file line number Diff line number Diff line change
@@ -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`
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 4ea92e3

Please sign in to comment.