You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2018/05/25 09:09:03 UTC
[6/7] james-project git commit: MAILBOX-337 Improve JMAP message
destruction
MAILBOX-337 Improve JMAP message destruction
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fe3e39d5
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fe3e39d5
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fe3e39d5
Branch: refs/heads/master
Commit: fe3e39d53ea00882a28980ff421f151876d0dc7a
Parents: 5bfbc37
Author: benwa <bt...@linagora.com>
Authored: Thu May 24 16:11:09 2018 +0700
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Fri May 25 11:07:39 2018 +0200
----------------------------------------------------------------------
.../SetMessagesDestructionProcessor.java | 67 ++++++++------------
1 file changed, 28 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3e39d5/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
index 65fff33..a7bfa64 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
@@ -22,28 +22,23 @@ package org.apache.james.jmap.methods;
import static org.apache.james.jmap.methods.Method.JMAP_PREFIX;
import java.util.List;
-import java.util.function.Function;
+import java.util.stream.Stream;
import javax.inject.Inject;
-import org.apache.james.jmap.exceptions.MessageNotFoundException;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.FetchGroupImpl;
-import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.DeleteResult;
import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.metrics.api.MetricFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.github.steveash.guavate.Guavate;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
public class SetMessagesDestructionProcessor implements SetMessagesProcessor {
@@ -62,46 +57,40 @@ public class SetMessagesDestructionProcessor implements SetMessagesProcessor {
@Override
public SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession) {
return metricFactory.withMetric(JMAP_PREFIX + "SetMessageDestructionProcessor",
- () -> request.getDestroy().stream()
- .map(delete(mailboxSession))
+ () -> delete(request.getDestroy(), mailboxSession)
.reduce(SetMessagesResponse.builder(),
SetMessagesResponse.Builder::accumulator,
SetMessagesResponse.Builder::combiner)
.build());
}
- private Function<? super MessageId, SetMessagesResponse> delete(MailboxSession mailboxSession) {
- return (messageId) -> {
- try {
- List<MailboxId> mailboxes = listContainingMailboxes(messageId, mailboxSession);
- messageIdManager.delete(messageId, mailboxes, mailboxSession);
- return SetMessagesResponse.builder().destroyed(messageId).build();
- } catch (MessageNotFoundException e) {
- return SetMessagesResponse.builder().notDestroyed(messageId,
- SetError.builder()
- .type(SetError.Type.NOT_FOUND)
- .description("The message " + messageId.serialize() + " can't be found")
- .build())
- .build();
- } catch (MailboxException e) {
- LOGGER.error("An error occurred when deleting a message", e);
- return SetMessagesResponse.builder().notDestroyed(messageId,
- SetError.builder()
- .type(SetError.Type.ERROR)
- .description("An error occurred while deleting message " + messageId.serialize())
- .build())
- .build();
+
+ private Stream<SetMessagesResponse> delete(List<MessageId> toBeDestroyed, MailboxSession mailboxSession) {
+ try {
+ if (toBeDestroyed.isEmpty()) {
+ return Stream.empty();
}
- };
- }
+ DeleteResult deleteResult = messageIdManager.delete(toBeDestroyed, mailboxSession);
- private List<MailboxId> listContainingMailboxes(MessageId messageId, MailboxSession mailboxSession) throws MailboxException, MessageNotFoundException {
- List<MessageResult> messages = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, mailboxSession);
- if (messages.isEmpty()) {
- throw new MessageNotFoundException();
+ Stream<SetMessagesResponse> destroyed = deleteResult.getDestroyed().stream()
+ .map(messageId -> SetMessagesResponse.builder().destroyed(messageId).build());
+ Stream<SetMessagesResponse> notFound = deleteResult.getNotFound().stream()
+ .map(messageId -> SetMessagesResponse.builder().notDestroyed(messageId,
+ SetError.builder()
+ .type(SetError.Type.NOT_FOUND)
+ .description("The message " + messageId.serialize() + " can't be found")
+ .build())
+ .build());
+ return Stream.concat(destroyed, notFound);
+ } catch (MailboxException e) {
+ LOGGER.error("An error occurred when deleting a message", e);
+ return toBeDestroyed.stream()
+ .map(messageId -> SetMessagesResponse.builder().notDestroyed(messageId,
+ SetError.builder()
+ .type(SetError.Type.ERROR)
+ .description("An error occurred while deleting messages " + messageId.serialize())
+ .build())
+ .build());
}
- return messages.stream()
- .map(MessageResult::getMailboxId)
- .collect(Guavate.toImmutableList());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org