james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] 02/06: JAMES-2746 extract QuotaLoader from MailboxFactory
Date Wed, 12 Jun 2019 14:32:13 GMT
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch 3.3.x
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e65b685e8dc70aaaf9991296e1b000230b2f1fa4
Author: RĂ©mi Kowalski <rkowalski@linagora.com>
AuthorDate: Tue Apr 30 16:31:56 2019 +0200

    JAMES-2746 extract QuotaLoader from MailboxFactory
---
 .../james/jmap/methods/GetMailboxesMethod.java     | 31 +++++----
 .../apache/james/jmap/model/MailboxFactory.java    | 79 +++++----------------
 .../jmap/utils/quotas/DefaultQuotaLoader.java      | 52 ++++++++++++++
 .../james/jmap/utils/quotas/QuotaLoader.java       | 50 ++++++++++++++
 .../quotas/QuotaLoaderWithDefaultPreloaded.java    | 80 ++++++++++++++++++++++
 .../james/jmap/methods/GetMailboxesMethodTest.java | 31 +++++----
 .../james/jmap/model/MailboxFactoryTest.java       |  2 +
 7 files changed, 237 insertions(+), 88 deletions(-)

diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
index ab22edc..485d364 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
@@ -33,13 +33,16 @@ import org.apache.james.jmap.model.GetMailboxesResponse;
 import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.MailboxProperty;
 import org.apache.james.jmap.model.mailbox.Mailbox;
-import org.apache.james.jmap.model.mailbox.Quotas;
+import org.apache.james.jmap.utils.quotas.QuotaLoader;
+import org.apache.james.jmap.utils.quotas.QuotaLoaderWithDefaultPreloaded;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.apache.james.util.OptionalUtils;
@@ -57,17 +60,21 @@ public class GetMailboxesMethod implements Method {
     private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMailboxes");
     private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("mailboxes");
     private static final Optional<List<MailboxMetaData>> NO_PRELOADED_METADATA
= Optional.empty();
-    private static final Optional<Quotas> NO_PRELOADED_QUOTAS = Optional.empty();
 
-    private final MailboxManager mailboxManager; 
+    private final MailboxManager mailboxManager;
     private final MailboxFactory mailboxFactory;
     private final MetricFactory metricFactory;
+    private final QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
 
     @Inject
-    @VisibleForTesting public GetMailboxesMethod(MailboxManager mailboxManager, MailboxFactory
mailboxFactory, MetricFactory metricFactory) {
+    @VisibleForTesting
+    public GetMailboxesMethod(MailboxManager mailboxManager, QuotaRootResolver quotaRootResolver,
QuotaManager quotaManager, MailboxFactory mailboxFactory, MetricFactory metricFactory) {
         this.mailboxManager = mailboxManager;
         this.mailboxFactory = mailboxFactory;
         this.metricFactory = metricFactory;
+        this.quotaRootResolver = quotaRootResolver;
+        this.quotaManager = quotaManager;
     }
 
     @Override
@@ -126,15 +133,13 @@ public class GetMailboxesMethod implements Method {
     }
 
 
-
     private Stream<Mailbox> retrieveSpecificMailboxes(MailboxSession mailboxSession,
ImmutableList<MailboxId> mailboxIds) {
         return mailboxIds
             .stream()
-            .map(mailboxId ->  mailboxFactory.builder()
+            .map(mailboxId -> mailboxFactory.builder()
                 .id(mailboxId)
                 .session(mailboxSession)
                 .usingPreloadedMailboxesMetadata(NO_PRELOADED_METADATA)
-                .usingPreloadedUserDefaultQuotas(NO_PRELOADED_QUOTAS)
                 .build()
             )
             .flatMap(OptionalUtils::toStream);
@@ -142,7 +147,7 @@ public class GetMailboxesMethod implements Method {
 
     private Stream<Mailbox> retrieveAllMailboxes(MailboxSession mailboxSession) throws
MailboxException {
         List<MailboxMetaData> userMailboxes = getAllMailboxesMetaData(mailboxSession);
-        Quotas mailboxQuotas =  mailboxFactory.getUserDefaultQuotas(mailboxSession);
+        QuotaLoader quotaLoader = new QuotaLoaderWithDefaultPreloaded(quotaRootResolver,
quotaManager, mailboxSession);
 
         return userMailboxes
             .stream()
@@ -151,17 +156,17 @@ public class GetMailboxesMethod implements Method {
                 .id(mailboxId)
                 .session(mailboxSession)
                 .usingPreloadedMailboxesMetadata(Optional.of(userMailboxes))
-                .usingPreloadedUserDefaultQuotas(Optional.of(mailboxQuotas))
+                .quotaLoader(quotaLoader)
                 .build())
             .flatMap(OptionalUtils::toStream);
     }
 
     private List<MailboxMetaData> getAllMailboxesMetaData(MailboxSession mailboxSession)
throws MailboxException {
         return mailboxManager.search(
-                MailboxQuery.builder()
-                    .matchesAllMailboxNames()
-                    .build(),
-                mailboxSession);
+            MailboxQuery.builder()
+                .matchesAllMailboxNames()
+                .build(),
+            mailboxSession);
     }
 
 }
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
index d2506fb..2e88972 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
@@ -23,14 +23,14 @@ import java.util.Optional;
 
 import javax.inject.Inject;
 
-import org.apache.james.core.quota.QuotaValue;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.MailboxNamespace;
 import org.apache.james.jmap.model.mailbox.Quotas;
-import org.apache.james.jmap.model.mailbox.Quotas.QuotaId;
 import org.apache.james.jmap.model.mailbox.Rights;
 import org.apache.james.jmap.model.mailbox.Rights.Username;
 import org.apache.james.jmap.model.mailbox.SortOrder;
+import org.apache.james.jmap.utils.quotas.DefaultQuotaLoader;
+import org.apache.james.jmap.utils.quotas.QuotaLoader;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -41,8 +41,6 @@ import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.Quota;
-import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 
@@ -57,13 +55,14 @@ public class MailboxFactory {
 
     public static class MailboxBuilder {
         private final MailboxFactory mailboxFactory;
+        private QuotaLoader quotaLoader;
         private MailboxSession session;
         private MailboxId id;
         private Optional<List<MailboxMetaData>> userMailboxesMetadata = Optional.empty();
-        private Optional<Quotas> preloadedUserDefaultQuotas = Optional.empty();
 
-        private MailboxBuilder(MailboxFactory mailboxFactory) {
+        private MailboxBuilder(MailboxFactory mailboxFactory, QuotaLoader quotaLoader) {
             this.mailboxFactory = mailboxFactory;
+            this.quotaLoader = quotaLoader;
         }
 
         public MailboxBuilder id(MailboxId id) {
@@ -76,13 +75,13 @@ public class MailboxFactory {
             return this;
         }
 
-        public MailboxBuilder usingPreloadedMailboxesMetadata(Optional<List<MailboxMetaData>>
userMailboxesMetadata) {
-            this.userMailboxesMetadata = userMailboxesMetadata;
+        public MailboxBuilder quotaLoader(QuotaLoader quotaLoader) {
+            this.quotaLoader = quotaLoader;
             return this;
         }
 
-        public MailboxBuilder usingPreloadedUserDefaultQuotas(Optional<Quotas> preloadedUserDefaultQuotas)
{
-            this.preloadedUserDefaultQuotas = preloadedUserDefaultQuotas;
+        public MailboxBuilder usingPreloadedMailboxesMetadata(Optional<List<MailboxMetaData>>
userMailboxesMetadata) {
+            this.userMailboxesMetadata = userMailboxesMetadata;
             return this;
         }
 
@@ -92,7 +91,7 @@ public class MailboxFactory {
 
             try {
                 MessageManager mailbox = mailboxFactory.mailboxManager.getMailbox(id, session);
-                return Optional.of(mailboxFactory.fromMessageManager(mailbox, userMailboxesMetadata,
preloadedUserDefaultQuotas, session));
+                return Optional.of(mailboxFactory.fromMessageManager(mailbox, userMailboxesMetadata,
quotaLoader, session));
             } catch (MailboxNotFoundException e) {
                 return Optional.empty();
             } catch (MailboxException e) {
@@ -109,12 +108,13 @@ public class MailboxFactory {
     }
 
     public MailboxBuilder builder() {
-        return new MailboxBuilder(this);
+        QuotaLoader defaultQuotaLoader = new DefaultQuotaLoader(quotaRootResolver, quotaManager);
+        return new MailboxBuilder(this, defaultQuotaLoader);
     }
 
     private Mailbox fromMessageManager(MessageManager messageManager,
                                        Optional<List<MailboxMetaData>> userMailboxesMetadata,
-                                       Optional<Quotas> preloadedDefaultUserQuotas,
+                                       QuotaLoader quotaLoader,
                                        MailboxSession mailboxSession) throws MailboxException
{
         MailboxPath mailboxPath = messageManager.getMailboxPath();
         boolean isOwner = mailboxPath.belongsTo(mailboxSession);
@@ -125,7 +125,7 @@ public class MailboxFactory {
             .removeEntriesFor(Username.forMailboxPath(mailboxPath));
         Username username = Username.fromSession(mailboxSession);
 
-        Quotas quotas = getQuotas(mailboxPath, preloadedDefaultUserQuotas);
+        Quotas quotas = quotaLoader.getQuotas(mailboxPath);
 
         return Mailbox.builder()
             .id(messageManager.getId())
@@ -147,49 +147,6 @@ public class MailboxFactory {
             .build();
     }
 
-    private Quotas getQuotas(MailboxPath mailboxPath, Optional<Quotas> preloadedUserDefaultQuotas)
throws MailboxException {
-        QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
-        QuotaId quotaId = QuotaId.fromQuotaRoot(quotaRoot);
-
-        if (containsQuotaId(preloadedUserDefaultQuotas, quotaId)) {
-            return preloadedUserDefaultQuotas.get();
-        }
-        return Quotas.from(
-            quotaId,
-            Quotas.Quota.from(
-                quotaToValue(quotaManager.getStorageQuota(quotaRoot)),
-                quotaToValue(quotaManager.getMessageQuota(quotaRoot))));
-    }
-
-    private boolean containsQuotaId(Optional<Quotas> preloadedUserDefaultQuotas, QuotaId
quotaId) {
-        return preloadedUserDefaultQuotas
-                .map(Quotas::getQuotas)
-                .map(quotaIdQuotaMap -> quotaIdQuotaMap.containsKey(quotaId))
-                .orElse(false);
-    }
-
-    public Quotas getUserDefaultQuotas(MailboxSession mailboxSession) throws MailboxException
{
-        MailboxPath inboxPath = MailboxPath.inbox(mailboxSession);
-        return getQuotas(inboxPath, Optional.empty());
-    }
-
-    private <T extends QuotaValue<T>> Quotas.Value<T> quotaToValue(Quota<T>
quota) {
-        return new Quotas.Value<>(
-                quotaValueToNumber(quota.getUsed()),
-                quotaValueToOptionalNumber(quota.getLimit()));
-    }
-
-    private Number quotaValueToNumber(QuotaValue<?> value) {
-        return Number.BOUND_SANITIZING_FACTORY.from(value.asLong());
-    }
-
-    private Optional<Number> quotaValueToOptionalNumber(QuotaValue<?> value)
{
-        if (value.isUnlimited()) {
-            return Optional.empty();
-        }
-        return Optional.of(quotaValueToNumber(value));
-    }
-
     private MailboxNamespace getNamespace(MailboxPath mailboxPath, boolean isOwner) {
         if (isOwner) {
             return MailboxNamespace.personal();
@@ -197,7 +154,8 @@ public class MailboxFactory {
         return MailboxNamespace.delegated(mailboxPath.getUser());
     }
 
-    @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession)
{
+    @VisibleForTesting
+    String getName(MailboxPath mailboxPath, MailboxSession mailboxSession) {
         String name = mailboxPath.getName();
         if (name.contains(String.valueOf(mailboxSession.getPathDelimiter()))) {
             List<String> levels = Splitter.on(mailboxSession.getPathDelimiter()).splitToList(name);
@@ -206,8 +164,9 @@ public class MailboxFactory {
         return name;
     }
 
-    @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath,
Optional<List<MailboxMetaData>> userMailboxesMetadata,
-                                                                      MailboxSession mailboxSession)
throws MailboxException {
+    @VisibleForTesting
+    Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>>
userMailboxesMetadata,
+                                                   MailboxSession mailboxSession) throws
MailboxException {
         List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter());
         if (levels.size() <= 1) {
             return Optional.empty();
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/DefaultQuotaLoader.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/DefaultQuotaLoader.java
new file mode 100644
index 0000000..816d7cb
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/DefaultQuotaLoader.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.utils.quotas;
+
+import javax.inject.Inject;
+
+import org.apache.james.jmap.model.mailbox.Quotas;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+public class DefaultQuotaLoader extends QuotaLoader {
+
+    private final QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
+
+    @Inject
+    public DefaultQuotaLoader(QuotaRootResolver quotaRootResolver, QuotaManager quotaManager)
{
+        this.quotaRootResolver = quotaRootResolver;
+        this.quotaManager = quotaManager;
+    }
+
+    public Quotas getQuotas(MailboxPath mailboxPath) throws MailboxException {
+        QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
+        Quotas.QuotaId quotaId = Quotas.QuotaId.fromQuotaRoot(quotaRoot);
+
+        return Quotas.from(
+            quotaId,
+            Quotas.Quota.from(
+                quotaToValue(quotaManager.getStorageQuota(quotaRoot)),
+                quotaToValue(quotaManager.getMessageQuota(quotaRoot))));
+    }
+
+}
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoader.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoader.java
new file mode 100644
index 0000000..2d16844
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoader.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.utils.quotas;
+
+import java.util.Optional;
+
+import org.apache.james.core.quota.QuotaValue;
+import org.apache.james.jmap.model.Number;
+import org.apache.james.jmap.model.mailbox.Quotas;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.Quota;
+
+public abstract class QuotaLoader {
+
+    public abstract Quotas getQuotas(MailboxPath mailboxPath) throws MailboxException;
+
+    protected <T extends QuotaValue<T>> Quotas.Value<T> quotaToValue(Quota<T>
quota) {
+        return new Quotas.Value<>(
+            quotaValueToNumber(quota.getUsed()),
+            quotaValueToOptionalNumber(quota.getLimit()));
+    }
+
+    protected Number quotaValueToNumber(QuotaValue<?> value) {
+        return Number.BOUND_SANITIZING_FACTORY.from(value.asLong());
+    }
+
+    protected Optional<Number> quotaValueToOptionalNumber(QuotaValue<?> value)
{
+        if (value.isUnlimited()) {
+            return Optional.empty();
+        }
+        return Optional.of(quotaValueToNumber(value));
+    }
+}
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoaderWithDefaultPreloaded.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoaderWithDefaultPreloaded.java
new file mode 100644
index 0000000..abbda4f
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/quotas/QuotaLoaderWithDefaultPreloaded.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.utils.quotas;
+
+import java.util.Optional;
+
+import org.apache.james.jmap.model.mailbox.Quotas;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+public class QuotaLoaderWithDefaultPreloaded extends QuotaLoader {
+
+    private final QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
+    private final Optional<Quotas> preloadedUserDefaultQuotas;
+    private final MailboxSession session;
+
+    public QuotaLoaderWithDefaultPreloaded(QuotaRootResolver quotaRootResolver,
+                                           QuotaManager quotaManager,
+                                           MailboxSession session) throws MailboxException
{
+        this.quotaRootResolver = quotaRootResolver;
+        this.quotaManager = quotaManager;
+        this.session = session;
+        preloadedUserDefaultQuotas = Optional.of(getUserDefaultQuotas());
+
+    }
+
+    public Quotas getQuotas(MailboxPath mailboxPath) throws MailboxException {
+        QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
+        Quotas.QuotaId quotaId = Quotas.QuotaId.fromQuotaRoot(quotaRoot);
+
+        if (containsQuotaId(preloadedUserDefaultQuotas, quotaId)) {
+            return preloadedUserDefaultQuotas.get();
+        }
+        return Quotas.from(
+            quotaId,
+            Quotas.Quota.from(
+                quotaToValue(quotaManager.getStorageQuota(quotaRoot)),
+                quotaToValue(quotaManager.getMessageQuota(quotaRoot))));
+    }
+
+    private boolean containsQuotaId(Optional<Quotas> preloadedUserDefaultQuotas, Quotas.QuotaId
quotaId) {
+        return preloadedUserDefaultQuotas
+            .map(Quotas::getQuotas)
+            .map(quotaIdQuotaMap -> quotaIdQuotaMap.containsKey(quotaId))
+            .orElse(false);
+    }
+
+    private Quotas getUserDefaultQuotas() throws MailboxException {
+        QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(MailboxPath.inbox(session));
+        Quotas.QuotaId quotaId = Quotas.QuotaId.fromQuotaRoot(quotaRoot);
+        return Quotas.from(
+            quotaId,
+            Quotas.Quota.from(
+                quotaToValue(quotaManager.getStorageQuota(quotaRoot)),
+                quotaToValue(quotaManager.getMessageQuota(quotaRoot))));
+
+    }
+
+}
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index 8ee3ec0..89fad73 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -37,7 +37,6 @@ import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.Number;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.SortOrder;
-import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageManager;
@@ -68,17 +67,19 @@ public class GetMailboxesMethodTest {
     private ClientId clientId;
     private MailboxFactory mailboxFactory;
 
+    private QuotaRootResolver quotaRootResolver;
+    private QuotaManager quotaManager;
     @Before
     public void setup() throws Exception {
         clientId = ClientId.of("#0");
         InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources();
         GroupMembershipResolver groupMembershipResolver = inMemoryIntegrationResources.createGroupMembershipResolver();
         mailboxManager = inMemoryIntegrationResources.createMailboxManager(groupMembershipResolver);
-        QuotaRootResolver quotaRootResolver = mailboxManager.getQuotaComponents().getQuotaRootResolver();
-        QuotaManager quotaManager = mailboxManager.getQuotaComponents().getQuotaManager();
+        quotaRootResolver = mailboxManager.getQuotaComponents().getQuotaRootResolver();
+        quotaManager = mailboxManager.getQuotaComponents().getQuotaManager();
         mailboxFactory = new MailboxFactory(mailboxManager, quotaManager, quotaRootResolver);
 
-        getMailboxesMethod = new GetMailboxesMethod(mailboxManager, mailboxFactory, new DefaultMetricFactory());
+        getMailboxesMethod = new GetMailboxesMethod(mailboxManager, quotaRootResolver, quotaManager,
 mailboxFactory, new DefaultMetricFactory());
     }
 
     @Test
@@ -87,9 +88,9 @@ public class GetMailboxesMethodTest {
                 .build();
 
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
-        
+
         List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
clientId, mailboxSession).collect(Collectors.toList());
-        
+
         assertThat(getMailboxesResponse)
                 .hasSize(1)
                 .extracting(JmapResponse::getResponse)
@@ -98,22 +99,22 @@ public class GetMailboxesMethodTest {
                 .flatExtracting(GetMailboxesResponse::getList)
                 .isEmpty();
     }
-    
+
     @Test
     public void getMailboxesShouldNotFailWhenMailboxManagerErrors() throws Exception {
-        MailboxManager mockedMailboxManager = mock(MailboxManager.class);
+        StoreMailboxManager mockedMailboxManager = mock(StoreMailboxManager.class);
         when(mockedMailboxManager.list(any()))
             .thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name")));
         when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any()))
             .thenThrow(new MailboxException());
-        GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxFactory,
new DefaultMetricFactory());
-        
+        GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, quotaRootResolver,
quotaManager, mailboxFactory, new DefaultMetricFactory());
+
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
-        
+
         List<JmapResponse> getMailboxesResponse = testee.process(getMailboxesRequest,
clientId, session).collect(Collectors.toList());
-        
+
         assertThat(getMailboxesResponse)
                 .hasSize(1)
                 .extracting(JmapResponse::getResponse)
@@ -143,7 +144,7 @@ public class GetMailboxesMethodTest {
                 .build();
 
         List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
clientId, mailboxSession).collect(Collectors.toList());
-        
+
         assertThat(getMailboxesResponse)
                 .hasSize(1)
                 .extracting(JmapResponse::getResponse)
@@ -168,7 +169,7 @@ public class GetMailboxesMethodTest {
                 .build();
 
         List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest,
clientId, userSession).collect(Collectors.toList());
-        
+
         assertThat(getMailboxesResponse)
                 .hasSize(1)
                 .extracting(JmapResponse::getResponse)
@@ -382,7 +383,7 @@ public class GetMailboxesMethodTest {
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession);
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession);
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "WITHOUT ROLE"), mailboxSession);
-        
+
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
 
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
index 013e3ed..bef0d34 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
@@ -24,6 +24,8 @@ import java.util.Optional;
 
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.MailboxNamespace;
+import org.apache.james.jmap.utils.quotas.DefaultQuotaLoader;
+import org.apache.james.jmap.utils.quotas.QuotaLoader;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;


---------------------------------------------------------------------
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