You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2022/05/24 04:48:35 UTC

[GitHub] [james-project] chibenwa commented on a diff in pull request #1011: JAMES-3737 Reactive IMAP CREATE + RENAME

chibenwa commented on code in PR #1011:
URL: https://github.com/apache/james-project/pull/1011#discussion_r880053902


##########
mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java:
##########
@@ -334,94 +332,102 @@ private boolean userHasLookupRightsOn(Mailbox mailbox, MailboxSession session) {
 
     @Override
     public Optional<MailboxId> createMailbox(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
+        return MailboxReactorUtils.blockOptional(createMailboxReactive(mailboxPath, mailboxSession));
+    }
+
+    public Mono<MailboxId> createMailboxReactive(MailboxPath mailboxPath, MailboxSession mailboxSession) {
         LOGGER.debug("createMailbox {}", mailboxPath);
 
-        assertMailboxPathBelongToUser(mailboxSession, mailboxPath);
+        return assertMailboxPathBelongToUserReactive(mailboxSession, mailboxPath)
+            .then(doCreateMailboxReactive(mailboxPath, mailboxSession));
+    }
 
+    private Mono<MailboxId> doCreateMailboxReactive(MailboxPath mailboxPath, MailboxSession mailboxSession) {
         if (mailboxPath.getName().isEmpty()) {
             LOGGER.warn("Ignoring mailbox with empty name");
+            return Mono.empty();
         } else {
-            MailboxPath sanitizedMailboxPath = mailboxPath.sanitize(mailboxSession.getPathDelimiter());
-            sanitizedMailboxPath.assertAcceptable(mailboxSession.getPathDelimiter());
-
-            if (block(mailboxExists(sanitizedMailboxPath, mailboxSession))) {
-                throw new MailboxExistsException(sanitizedMailboxPath.asString());
-            }
-
-            List<MailboxId> mailboxIds = createMailboxesForPath(mailboxSession, sanitizedMailboxPath);
-
-            if (!mailboxIds.isEmpty()) {
-                return Optional.ofNullable(Iterables.getLast(mailboxIds));
+            try {
+                MailboxPath sanitizedMailboxPath = mailboxPath.sanitize(mailboxSession.getPathDelimiter());
+                sanitizedMailboxPath.assertAcceptable(mailboxSession.getPathDelimiter());
+
+                return mailboxExists(sanitizedMailboxPath, mailboxSession)
+                    .flatMap(exists -> {
+                        if (exists) {
+                            return Mono.error(new MailboxExistsException(sanitizedMailboxPath.asString()));
+                        } else {
+                            return createMailboxesForPath(mailboxSession, sanitizedMailboxPath).last();
+                        }
+                    });
+            } catch (MailboxNameException e) {
+                return Mono.error(e);
             }

Review Comment:
   No I want to avoid an uneeded flatmap bringing asynchronous semantic in asynchronous code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org