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 a59013bef0851db3e51f0f562d32f76ba06013e5
Author: Benoit Tellier <[email protected]>
AuthorDate: Sat May 15 11:35:54 2021 +0700

    [REFACTORING] SetMessagesUpdateProcessor: Remove unused 
DraftMessageMailboxUpdateException
---
 .../DraftMessageMailboxUpdateException.java        | 29 ----------
 .../draft/methods/SetMessagesUpdateProcessor.java  | 65 +++++++++-------------
 2 files changed, 26 insertions(+), 68 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/exceptions/DraftMessageMailboxUpdateException.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/exceptions/DraftMessageMailboxUpdateException.java
deleted file mode 100644
index fe82448..0000000
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/exceptions/DraftMessageMailboxUpdateException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.jmap.draft.exceptions;
-
-import org.apache.james.mailbox.exception.MailboxException;
-
-public class DraftMessageMailboxUpdateException extends MailboxException {
-
-    public DraftMessageMailboxUpdateException(String message) {
-        super(message);
-    }
-}
diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
index 9e1930f..fea0e2a 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
@@ -29,7 +29,6 @@ import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import javax.inject.Inject;
 import javax.mail.Flags;
@@ -38,7 +37,6 @@ import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.Username;
-import 
org.apache.james.jmap.draft.exceptions.DraftMessageMailboxUpdateException;
 import org.apache.james.jmap.draft.exceptions.InvalidOutboxMoveException;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
@@ -124,16 +122,13 @@ public class SetMessagesUpdateProcessor implements 
SetMessagesProcessor {
     public Mono<SetMessagesResponse> processReactive(SetMessagesRequest 
request, MailboxSession mailboxSession) {
         return 
Mono.from(metricFactory.decoratePublisherWithTimerMetricLogP99(JMAP_PREFIX + 
"SetMessagesUpdateProcessor",
             listMailboxIdsForRole(mailboxSession, Role.OUTBOX)
-                .flatMap(outboxIds -> Mono.fromCallable(() -> 
prepareResponse(request, mailboxSession, outboxIds).build())
-                    .subscribeOn(Schedulers.elastic()))
+                .flatMap(outboxIds -> prepareResponse(request, mailboxSession, 
outboxIds).map(SetMessagesResponse.Builder::build))
                 .onErrorResume(e ->
-                    Mono.fromCallable(() ->
-                        
request.buildUpdatePatches(updatePatchConverter).entrySet().stream()
-                            .map(entry -> prepareResponseIfCantReadOutboxes(e, 
entry.getKey(), entry.getValue()))
-                            .reduce(SetMessagesResponse.Builder::mergeWith)
-                            .orElse(SetMessagesResponse.builder())
-                            .build())
-                        .subscribeOn(Schedulers.elastic()))));
+                    
Mono.just(request.buildUpdatePatches(updatePatchConverter).entrySet().stream()
+                        .map(entry -> prepareResponseIfCantReadOutboxes(e, 
entry.getKey(), entry.getValue()))
+                        .reduce(SetMessagesResponse.Builder::mergeWith)
+                        .orElse(SetMessagesResponse.builder())
+                        .build()))));
     }
 
     private SetMessagesResponse.Builder 
prepareResponseIfCantReadOutboxes(Throwable e, MessageId id, UpdateMessagePatch 
patch) {
@@ -144,28 +139,31 @@ public class SetMessagesUpdateProcessor implements 
SetMessagesProcessor {
         }
     }
 
-    private SetMessagesResponse.Builder prepareResponse(SetMessagesRequest 
request, MailboxSession mailboxSession, Set<MailboxId> outboxes) {
+    private Mono<SetMessagesResponse.Builder> 
prepareResponse(SetMessagesRequest request, MailboxSession mailboxSession, 
Set<MailboxId> outboxes) {
         Map<MessageId, UpdateMessagePatch> patches = 
request.buildUpdatePatches(updatePatchConverter);
 
-        Multimap<MessageId, ComposedMessageIdWithMetaData> messages = 
Flux.from(messageIdManager.messagesMetadata(patches.keySet(), mailboxSession))
+        return Flux.from(messageIdManager.messagesMetadata(patches.keySet(), 
mailboxSession))
             .collect(Guavate.toImmutableListMultimap(metaData -> 
metaData.getComposedMessageId().getMessageId()))
-            .block();
-
-        if (isAMassiveFlagUpdate(patches, messages)) {
-            return applyRangedFlagUpdate(patches, messages, mailboxSession);
-        } else if (isAMassiveMove(patches, messages)) {
-            return applyMove(patches, messages, mailboxSession);
-        } else {
-            return patches.entrySet().stream()
-                .map(entry ->  {
-                if (entry.getValue().isValid()) {
-                    return update(outboxes, entry.getKey(), entry.getValue(), 
mailboxSession, messages);
+            .flatMap(messages -> {
+                if (isAMassiveFlagUpdate(patches, messages)) {
+                    return Mono.fromCallable(() -> 
applyRangedFlagUpdate(patches, messages, mailboxSession))
+                        .subscribeOn(Schedulers.elastic());
+                } else if (isAMassiveMove(patches, messages)) {
+                    return Mono.fromCallable(() -> applyMove(patches, 
messages, mailboxSession))
+                        .subscribeOn(Schedulers.elastic());
                 } else {
-                    return handleInvalidRequest(entry.getKey(), 
entry.getValue().getValidationErrors(), entry.getValue());
+                    return Flux.fromIterable(patches.entrySet())
+                        .flatMap(entry -> {
+                            if (entry.getValue().isValid()) {
+                                return update(outboxes, entry.getKey(), 
entry.getValue(), mailboxSession, messages);
+                            } else {
+                                return 
Mono.just(handleInvalidRequest(entry.getKey(), 
entry.getValue().getValidationErrors(), entry.getValue()));
+                            }
+
+                        }).reduce(SetMessagesResponse.Builder::mergeWith)
+                        
.switchIfEmpty(Mono.just(SetMessagesResponse.builder()));
                 }
-            }).reduce(SetMessagesResponse.Builder::mergeWith)
-            .orElse(SetMessagesResponse.builder());
-        }
+            });
     }
 
     private boolean isAMassiveFlagUpdate(Map<MessageId, UpdateMessagePatch> 
patches, Multimap<MessageId, ComposedMessageIdWithMetaData> messages) {
@@ -305,8 +303,6 @@ public class SetMessagesUpdateProcessor implements 
SetMessagesProcessor {
                 
builder.mergeWith(sendMessageWhenOutboxInTargetMailboxIds(outboxes, messageId, 
updateMessagePatch, mailboxSession));
             }
             return builder;
-        } catch (DraftMessageMailboxUpdateException e) {
-            return handleDraftMessageMailboxUpdateException(messageId, e);
         } catch (InvalidOutboxMoveException e) {
             ValidationResult invalidPropertyMailboxIds = 
ValidationResult.builder()
                 
.property(MessageProperties.MessageProperty.mailboxIds.asFieldName())
@@ -468,15 +464,6 @@ public class SetMessagesUpdateProcessor implements 
SetMessagesProcessor {
                         .build()));
     }
 
-    private SetMessagesResponse.Builder 
handleDraftMessageMailboxUpdateException(MessageId messageId,
-                                                                     
DraftMessageMailboxUpdateException e) {
-        return 
SetMessagesResponse.builder().notUpdated(ImmutableMap.of(messageId, 
SetError.builder()
-            .type(SetError.Type.INVALID_ARGUMENTS)
-            .properties(MessageProperties.MessageProperty.mailboxIds)
-            .description(e.getMessage())
-            .build()));
-    }
-
     private SetMessagesResponse.Builder handleMessageUpdateException(MessageId 
messageId,
                                                                      Throwable 
e) {
         LOGGER.error("An error occurred when updating a message", e);

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to