Skip to content

Commit

Permalink
JAMES-1692 message processors are injected
Browse files Browse the repository at this point in the history
... through SetMessagesMethod's ctor
  • Loading branch information
fvn-linagora authored and Raphael Ouazana committed Mar 1, 2016
1 parent 99ac325 commit b21eae3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.jmap; package org.apache.james.jmap;


import java.util.List;

import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.json.ObjectMapperFactory;
import org.apache.james.jmap.methods.GetMailboxesMethod; import org.apache.james.jmap.methods.GetMailboxesMethod;
import org.apache.james.jmap.methods.GetMessageListMethod; import org.apache.james.jmap.methods.GetMessageListMethod;
Expand All @@ -30,10 +32,13 @@
import org.apache.james.jmap.methods.Method; import org.apache.james.jmap.methods.Method;
import org.apache.james.jmap.methods.SetMessagesCreationProcessor; import org.apache.james.jmap.methods.SetMessagesCreationProcessor;
import org.apache.james.jmap.methods.SetMessagesMethod; import org.apache.james.jmap.methods.SetMessagesMethod;
import org.apache.james.jmap.methods.SetMessagesProcessor;
import org.apache.james.jmap.methods.SetMessagesUpdateProcessor; import org.apache.james.jmap.methods.SetMessagesUpdateProcessor;
import org.apache.james.mailbox.cassandra.CassandraId; import org.apache.james.mailbox.cassandra.CassandraId;


import com.google.common.collect.ImmutableList;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.Multibinder;
Expand All @@ -58,4 +63,12 @@ protected void configure() {
bind(SetMessagesCreationProcessor.class).to(new TypeLiteral<SetMessagesCreationProcessor<CassandraId>>(){}); bind(SetMessagesCreationProcessor.class).to(new TypeLiteral<SetMessagesCreationProcessor<CassandraId>>(){});
} }


@Provides
public List<SetMessagesProcessor<CassandraId>> setMessagesProcessors(
SetMessagesUpdateProcessor<CassandraId> messageUpdater,
SetMessagesCreationProcessor<CassandraId> messageCreator) {

return ImmutableList.of( messageUpdater, messageCreator);
}

} }
Expand Up @@ -43,6 +43,7 @@


import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;

import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


Expand All @@ -55,18 +56,15 @@ public class SetMessagesMethod<Id extends MailboxId> implements Method {


private final MailboxMapperFactory<Id> mailboxMapperFactory; private final MailboxMapperFactory<Id> mailboxMapperFactory;
private final MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory; private final MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory;
private final SetMessagesUpdateProcessor<Id> messageUpdater; private final List<SetMessagesProcessor<Id>> messagesProcessors;
private final SetMessagesCreationProcessor messageCreator;


@Inject @Inject
@VisibleForTesting SetMessagesMethod(MailboxMapperFactory<Id> mailboxMapperFactory, @VisibleForTesting SetMessagesMethod(MailboxMapperFactory<Id> mailboxMapperFactory,
MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory, MailboxSessionMapperFactory<Id> mailboxSessionMapperFactory,
SetMessagesUpdateProcessor<Id> messageUpdater, List<SetMessagesProcessor<Id>> messagesProcessors) {
SetMessagesCreationProcessor messageCreator) {
this.mailboxMapperFactory = mailboxMapperFactory; this.mailboxMapperFactory = mailboxMapperFactory;
this.mailboxSessionMapperFactory = mailboxSessionMapperFactory; this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
this.messageUpdater = messageUpdater; this.messagesProcessors = messagesProcessors;
this.messageCreator = messageCreator;
} }


@Override @Override
Expand Down Expand Up @@ -99,9 +97,13 @@ public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, Mail
private SetMessagesResponse setMessagesResponse(SetMessagesRequest request, MailboxSession mailboxSession) throws MailboxException { private SetMessagesResponse setMessagesResponse(SetMessagesRequest request, MailboxSession mailboxSession) throws MailboxException {
SetMessagesResponse.Builder responseBuilder = SetMessagesResponse.builder(); SetMessagesResponse.Builder responseBuilder = SetMessagesResponse.builder();
processDestroy(request.getDestroy(), mailboxSession, responseBuilder); processDestroy(request.getDestroy(), mailboxSession, responseBuilder);
messageUpdater.process(request, mailboxSession).mergeInto(responseBuilder); return messagesProcessors.stream()
messageCreator.process(request, mailboxSession).mergeInto(responseBuilder); .map(processor -> processor.process(request, mailboxSession))
return responseBuilder.build(); .reduce(responseBuilder,
(builder, resp) -> resp.mergeInto(builder) ,
(builder1, builder2) -> builder2.build().mergeInto(builder1)
)
.build();
} }


private void processDestroy(List<MessageId> messageIds, MailboxSession mailboxSession, SetMessagesResponse.Builder responseBuilder) throws MailboxException { private void processDestroy(List<MessageId> messageIds, MailboxSession mailboxSession, SetMessagesResponse.Builder responseBuilder) throws MailboxException {
Expand Down

0 comments on commit b21eae3

Please sign in to comment.