This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 1f5cd4f7a2f83ae4d3fff1ce715748c9151862d2 Author: Benoit TELLIER <btell...@linagora.com> AuthorDate: Thu Jan 16 10:41:07 2025 +0100 JAMES-4103 Allow customizing only the attachment id assignation Ease writing custom logic for this a LOT --- .../CassandraMailboxSessionMapperFactory.java | 3 ++- .../cassandra/mail/CassandraAttachmentMapper.java | 26 ++++++++++++++++++---- .../mailbox/cassandra/mail/utils/GuiceUtils.java | 2 ++ .../modules/mailbox/CassandraMailboxModule.java | 2 ++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java index 6c8e39c5b3..17abbdab44 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java @@ -132,7 +132,8 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa deletedMessageDAO); this.cassandraMailboxMapper = new CassandraMailboxMapper(mailboxDAO, mailboxPathV3DAO, userMailboxRightsDAO, aclMapper, cassandraConfiguration); this.cassandraSubscriptionMapper = new CassandraSubscriptionMapper(session); - this.cassandraAttachmentMapper = new CassandraAttachmentMapper(attachmentDAOV2, blobStore, new StringBackedAttachmentIdFactory()); + this.cassandraAttachmentMapper = new CassandraAttachmentMapper(attachmentDAOV2, blobStore, + new CassandraAttachmentMapper.AttachmentIdAssignationStrategy.Default(new StringBackedAttachmentIdFactory())); this.cassandraMessageMapper = new CassandraMessageMapper( uidProvider, modSeqProvider, diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java index 4fef446aec..a6542ce3a1 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java @@ -54,15 +54,33 @@ import reactor.core.publisher.Mono; public class CassandraAttachmentMapper implements AttachmentMapper { private static final Logger LOGGER = LoggerFactory.getLogger(CassandraAttachmentMapper.class); + public interface AttachmentIdAssignationStrategy { + AttachmentId assign(ParsedAttachment parsedAttachment, MessageId messageId); + + class Default implements AttachmentIdAssignationStrategy { + private final AttachmentIdFactory attachmentIdFactory; + + @Inject + public Default(AttachmentIdFactory attachmentIdFactory) { + this.attachmentIdFactory = attachmentIdFactory; + } + + @Override + public AttachmentId assign(ParsedAttachment parsedAttachment, MessageId messageId) { + return attachmentIdFactory.random(); + } + } + } + private final CassandraAttachmentDAOV2 attachmentDAOV2; private final BlobStore blobStore; - private final AttachmentIdFactory attachmentIdFactory; + private final AttachmentIdAssignationStrategy attachmentIdAssignationStrategy; @Inject - public CassandraAttachmentMapper(CassandraAttachmentDAOV2 attachmentDAOV2, BlobStore blobStore, AttachmentIdFactory attachmentIdFactory) { + public CassandraAttachmentMapper(CassandraAttachmentDAOV2 attachmentDAOV2, BlobStore blobStore, AttachmentIdAssignationStrategy attachmentIdAssignationStrategy) { this.attachmentDAOV2 = attachmentDAOV2; this.blobStore = blobStore; - this.attachmentIdFactory = attachmentIdFactory; + this.attachmentIdAssignationStrategy = attachmentIdAssignationStrategy; } @Override @@ -130,7 +148,7 @@ public class CassandraAttachmentMapper implements AttachmentMapper { private Mono<MessageAttachmentMetadata> storeAttachmentAsync(ParsedAttachment parsedAttachment, MessageId ownerMessageId) { try { - AttachmentId attachmentId = attachmentIdFactory.random(); + AttachmentId attachmentId = attachmentIdAssignationStrategy.assign(parsedAttachment, ownerMessageId); ByteSource content = parsedAttachment.getContent(); long size = content.size(); return Mono.from(blobStore.save(blobStore.getDefaultBucketName(), content, LOW_COST)) diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java index ecbb898d0b..4e64d8f3a8 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java @@ -42,6 +42,7 @@ import org.apache.james.mailbox.StringBackedAttachmentIdFactory; import org.apache.james.mailbox.cassandra.ids.CassandraMessageId; import org.apache.james.mailbox.cassandra.mail.ACLMapper; import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper; +import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentMapper; import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider; import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider; import org.apache.james.mailbox.cassandra.mail.eventsourcing.acl.ACLModule; @@ -85,6 +86,7 @@ public class GuiceUtils { binder -> binder.bind(MessageId.Factory.class).toInstance(messageIdFactory), binder -> binder.bind(BatchSizes.class).toInstance(BatchSizes.defaultValues()), binder -> binder.bind(UidProvider.class).to(CassandraUidProvider.class), + binder -> binder.bind(CassandraAttachmentMapper.AttachmentIdAssignationStrategy.class).to(CassandraAttachmentMapper.AttachmentIdAssignationStrategy.Default.class), binder -> binder.bind(ModSeqProvider.class).to(CassandraModSeqProvider.class), binder -> binder.bind(ACLMapper.class).to(CassandraACLMapper.class), binder -> binder.bind(BlobId.Factory.class).toInstance(new PlainBlobId.Factory()), diff --git a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index fd6c2b9f1e..5a63333ef3 100644 --- a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -75,6 +75,7 @@ import org.apache.james.mailbox.cassandra.mail.CassandraACLDAOV2; import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper; import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO; import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2; +import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentMapper; import org.apache.james.mailbox.cassandra.mail.CassandraDeletedMessageDAO; import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO; import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO; @@ -218,6 +219,7 @@ public class CassandraMailboxModule extends AbstractModule { bind(AttachmentContentLoader.class).to(AttachmentManager.class); bind(MailboxCounterCorrector.class).to(CassandraMailboxCounterCorrector.class); bind(MessageParser.class).toInstance(new MessageParserImpl()); + bind(CassandraAttachmentMapper.AttachmentIdAssignationStrategy.class).to(CassandraAttachmentMapper.AttachmentIdAssignationStrategy.Default.class); bind(Limit.class).annotatedWith(Names.named(CassandraEmailChangeRepository.LIMIT_NAME)).toInstance(Limit.of(256)); bind(Limit.class).annotatedWith(Names.named(CassandraMailboxChangeRepository.LIMIT_NAME)).toInstance(Limit.of(256)); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org