Arsnael commented on code in PR #1500:
URL: https://github.com/apache/james-project/pull/1500#discussion_r1145616851


##########
mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java:
##########
@@ -53,6 +53,10 @@ public interface MaxQuotaManager {
      */
     void setMaxStorage(QuotaRoot quotaRoot, QuotaSizeLimit maxStorageQuota) 
throws MailboxException;
 
+    default Publisher<Void> setMaxStorageReactive(QuotaRoot quotaRoot, 
QuotaSizeLimit maxStorageQuota) {
+        return Mono.fromRunnable(Throwing.runnable(() -> 
setMaxStorage(quotaRoot, maxStorageQuota)).sneakyThrow());

Review Comment:
   How is that making it really reactive? We should refactor it the other way 
around IMO...  Having a default method for setMaxStorage that would use the 
reactive method with a block() and wrtting the reactive code for implementation 
of that interface?



##########
server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaUsernameChangeTaskStep.java:
##########
@@ -0,0 +1,103 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaCountLimit;
+import org.apache.james.core.quota.QuotaSizeLimit;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.UserQuotaRootResolver;
+import org.apache.james.user.api.UsernameChangeTaskStep;
+import org.reactivestreams.Publisher;
+
+import reactor.core.publisher.Mono;
+
+public class QuotaUsernameChangeTaskStep implements UsernameChangeTaskStep {
+    private final QuotaManager quotaManager;
+    private final MaxQuotaManager maxQuotaManager;
+    private final CurrentQuotaManager currentQuotaManager;
+    private final UserQuotaRootResolver userQuotaRootResolver;
+
+    @Inject
+    public QuotaUsernameChangeTaskStep(QuotaManager quotaManager,
+                                       CurrentQuotaManager currentQuotaManager,
+                                       UserQuotaRootResolver 
userQuotaRootResolver,
+                                       MaxQuotaManager maxQuotaManager) {
+        this.quotaManager = quotaManager;
+        this.currentQuotaManager = currentQuotaManager;
+        this.userQuotaRootResolver = userQuotaRootResolver;
+        this.maxQuotaManager = maxQuotaManager;
+    }
+
+    @Override
+    public StepName name() {
+        return new StepName("QuotaUsernameChangeTaskStep");
+    }
+
+    @Override
+    public int priority() {
+        return 3;
+    }
+
+    @Override
+    public Publisher<Void> changeUsername(Username oldUsername, Username 
newUsername) {
+        return Mono.fromCallable(() -> 
userQuotaRootResolver.forUser(oldUsername))
+            .flatMap(quotaRoot -> 
Mono.from(quotaManager.getQuotasReactive(quotaRoot)))
+            .flatMap(quotas -> 
setQuotaForNewUser(userQuotaRootResolver.forUser(newUsername), quotas));
+    }
+
+    private Mono<Void> setQuotaForNewUser(QuotaRoot quotaRoot, 
QuotaManager.Quotas quotas) {
+        return setMaxQuota(quotaRoot, quotas)
+            .then(setCurrentQuota(quotaRoot, quotas));
+    }
+
+    private Mono<Void> setMaxQuota(QuotaRoot quotaRoot, QuotaManager.Quotas 
quotas) {
+        return Mono.zip(setMaxMessagesQuota(quotaRoot, 
quotas).thenReturn(quotaRoot),
+                setMaxStorageQuota(quotaRoot, quotas).thenReturn(quotaRoot))

Review Comment:
   I don't think the `thenReturn` are necessary here, as you finish with a then 
and return nothing nothing end of the pipeline?



##########
server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaUsernameChangeTaskStep.java:
##########
@@ -0,0 +1,103 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.core.quota.QuotaCountLimit;
+import org.apache.james.core.quota.QuotaSizeLimit;
+import org.apache.james.mailbox.model.CurrentQuotas;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaOperation;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.UserQuotaRootResolver;
+import org.apache.james.user.api.UsernameChangeTaskStep;
+import org.reactivestreams.Publisher;
+
+import reactor.core.publisher.Mono;
+
+public class QuotaUsernameChangeTaskStep implements UsernameChangeTaskStep {
+    private final QuotaManager quotaManager;
+    private final MaxQuotaManager maxQuotaManager;
+    private final CurrentQuotaManager currentQuotaManager;
+    private final UserQuotaRootResolver userQuotaRootResolver;
+
+    @Inject
+    public QuotaUsernameChangeTaskStep(QuotaManager quotaManager,
+                                       CurrentQuotaManager currentQuotaManager,
+                                       UserQuotaRootResolver 
userQuotaRootResolver,
+                                       MaxQuotaManager maxQuotaManager) {
+        this.quotaManager = quotaManager;
+        this.currentQuotaManager = currentQuotaManager;
+        this.userQuotaRootResolver = userQuotaRootResolver;
+        this.maxQuotaManager = maxQuotaManager;
+    }
+
+    @Override
+    public StepName name() {
+        return new StepName("QuotaUsernameChangeTaskStep");
+    }
+
+    @Override
+    public int priority() {
+        return 3;
+    }
+
+    @Override
+    public Publisher<Void> changeUsername(Username oldUsername, Username 
newUsername) {
+        return Mono.fromCallable(() -> 
userQuotaRootResolver.forUser(oldUsername))
+            .flatMap(quotaRoot -> 
Mono.from(quotaManager.getQuotasReactive(quotaRoot)))
+            .flatMap(quotas -> 
setQuotaForNewUser(userQuotaRootResolver.forUser(newUsername), quotas));

Review Comment:
   Why don't you chain that flatmap to the 
`Mono.from(quotaManager.getQuotasReactive(quotaRoot))` method? then you can 
reuse `quotaRoot` without recalculating it with a resolver every time?



##########
mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java:
##########
@@ -61,6 +65,10 @@ public interface MaxQuotaManager {
      */
     void setMaxMessage(QuotaRoot quotaRoot, QuotaCountLimit maxMessageCount) 
throws MailboxException;
 
+    default Publisher<Void> setMaxMessageReactive(QuotaRoot quotaRoot, 
QuotaCountLimit maxMessageCount) {
+        return Mono.fromRunnable(Throwing.runnable(() -> 
setMaxMessage(quotaRoot, maxMessageCount)).sneakyThrow());

Review Comment:
   idem?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to