james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [james-project] 10/12: JAMES-2632 Use the same method for all max quota computations
Date Wed, 13 Feb 2019 08:18:17 GMT
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 8dce1ec1481a8c9af84d13211b7b47163321b49c
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
AuthorDate: Tue Dec 18 12:09:24 2018 +0100

    JAMES-2632 Use the same method for all max quota computations
---
 .../james/mailbox/quota/MaxQuotaManager.java       | 11 ++++++--
 .../quota/CassandraPerUserMaxQuotaManager.java     | 30 ----------------------
 .../jpa/quota/JPAPerUserMaxQuotaManager.java       | 22 ----------------
 .../quota/InMemoryPerUserMaxQuotaManager.java      | 17 ------------
 4 files changed, 9 insertions(+), 71 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
index d027a32..6cb89b7 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
@@ -27,6 +27,7 @@ import org.apache.james.core.quota.QuotaCount;
 import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.Quota.Scope;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.util.OptionalUtils;
 
@@ -114,7 +115,10 @@ public interface MaxQuotaManager {
      * @param quotaRoot Quota root argument from RFC 2087 ( correspond to the user owning
this mailbox )
      * @return The maximum storage in bytes if any
      */
-    Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) throws MailboxException;
+    default Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) throws MailboxException
{
+        Map<Scope, QuotaSize> maxStorageDetails = listMaxStorageDetails(quotaRoot);
+        return getMaxStorage(maxStorageDetails);
+    }
 
     default Optional<QuotaSize> getMaxStorage(Map<Quota.Scope, QuotaSize> maxStorageDetails)
{
         return OptionalUtils.or(
@@ -129,7 +133,10 @@ public interface MaxQuotaManager {
      * @param quotaRoot Quota root argument from RFC 2087 ( correspond to the user owning
this mailbox )
      * @return maximum of allowed message count
      */
-    Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) throws MailboxException;
+    default Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) throws MailboxException
{
+        Map<Scope, QuotaCount> maxMessagesDetails = listMaxMessagesDetails(quotaRoot);
+        return getMaxMessage(maxMessagesDetails);
+    }
 
     default Optional<QuotaCount> getMaxMessage(Map<Quota.Scope, QuotaCount> maxMessagesDetails)
{
         return OptionalUtils.or(
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
index e4f7327..c278ae6 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.cassandra.quota;
 import java.util.Map;
 import java.util.Optional;
 import java.util.function.Function;
-import java.util.function.Supplier;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
@@ -34,7 +33,6 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
-import org.apache.james.util.OptionalUtils;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
@@ -135,34 +133,6 @@ public class CassandraPerUserMaxQuotaManager implements MaxQuotaManager
{
     }
 
     @Override
-    public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) {
-        Supplier<Optional<QuotaSize>> domainQuotaSupplier = Throwing.supplier(()
-> quotaRoot.getDomain()
-            .flatMap(this::getDomainMaxStorage)).sneakyThrow();
-        Supplier<Optional<QuotaSize>> globalDomainSupplier = Throwing.supplier(this::getGlobalMaxStorage).sneakyThrow();
-
-        return Stream
-            .of(() -> perUserQuota.getMaxStorage(quotaRoot),
-                domainQuotaSupplier,
-                globalDomainSupplier)
-            .flatMap(supplier -> OptionalUtils.toStream(supplier.get()))
-            .findFirst();
-    }
-
-    @Override
-    public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) {
-        Supplier<Optional<QuotaCount>> domainQuotaSupplier = Throwing.supplier(()
-> quotaRoot.getDomain()
-            .flatMap(this::getDomainMaxMessage)).sneakyThrow();
-        Supplier<Optional<QuotaCount>> globalDomainSupplier = Throwing.supplier(this::getGlobalMaxMessage).sneakyThrow();
-
-        return Stream
-            .of(() -> perUserQuota.getMaxMessage(quotaRoot),
-                domainQuotaSupplier,
-                globalDomainSupplier)
-            .flatMap(supplier -> OptionalUtils.toStream(supplier.get()))
-            .findFirst();
-    }
-
-    @Override
     public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot)
{
         Function<Domain, Optional<QuotaCount>> domainQuotaSupplier = Throwing.function(this::getDomainMaxMessage).sneakyThrow();
         return Stream.of(
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java
index dd24bd2..53b6ccd 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.jpa.quota;
 import java.util.Map;
 import java.util.Optional;
 import java.util.function.Function;
-import java.util.function.Supplier;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
@@ -34,7 +33,6 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
-import org.apache.james.util.OptionalUtils;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
@@ -119,26 +117,6 @@ public class JPAPerUserMaxQuotaManager implements MaxQuotaManager {
     }
 
     @Override
-    public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) {
-        return Stream
-            .of((Supplier<Optional<QuotaSize>>) () -> dao.getMaxStorage(quotaRoot),
-                () -> quotaRoot.getDomain().flatMap(this::getDomainMaxStorage),
-                this::getGlobalMaxStorage)
-            .flatMap(supplier -> OptionalUtils.toStream(supplier.get()))
-            .findFirst();
-    }
-
-    @Override
-    public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) {
-        return Stream
-            .of((Supplier<Optional<QuotaCount>>) () -> dao.getMaxMessage(quotaRoot),
-                () -> quotaRoot.getDomain().flatMap(this::getDomainMaxMessage),
-                this::getGlobalMaxMessage)
-            .flatMap(supplier -> OptionalUtils.toStream(supplier.get()))
-            .findFirst();
-    }
-
-    @Override
     public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot)
{
         Function<Domain, Optional<QuotaCount>> domainQuotaFunction = Throwing.function(this::getDomainMaxMessage).sneakyThrow();
         return Stream.of(
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
index b2b56a7..848118a 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java
@@ -31,7 +31,6 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
-import org.apache.james.util.OptionalUtils;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
@@ -73,22 +72,6 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager
{
     }
 
     @Override
-    public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) {
-        return OptionalUtils.or(
-            Optional.ofNullable(userMaxStorage.get(quotaRoot.getValue())),
-            quotaRoot.getDomain().flatMap(this::getDomainMaxStorage),
-            maxStorage);
-    }
-
-    @Override
-    public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) {
-        return OptionalUtils.or(
-            Optional.ofNullable(userMaxMessage.get(quotaRoot.getValue())),
-            quotaRoot.getDomain().flatMap(this::getDomainMaxMessage),
-            maxMessage);
-    }
-
-    @Override
     public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot)
{
         Function<Domain, Optional<QuotaCount>> domainQuotaFunction = Throwing.function(this::getDomainMaxMessage).sneakyThrow();
         return Stream.of(


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


Mime
View raw message