You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2018/05/18 14:29:54 UTC
[1/4] james-project git commit: JAMES-2401 Swagger documentation test
for some routes had been forgotten
Repository: james-project
Updated Branches:
refs/heads/master 38ea6fc9a -> cb9ccb5d5
JAMES-2401 Swagger documentation test for some routes had been forgotten
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bb01282d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bb01282d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bb01282d
Branch: refs/heads/master
Commit: bb01282d36cbeb328cbb7ae042ca2f5049fae6b2
Parents: 38ea6fc
Author: benwa <bt...@linagora.com>
Authored: Fri May 18 16:22:28 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri May 18 16:28:38 2018 +0700
----------------------------------------------------------------------
.../webadmin/integration/WebAdminServerIntegrationTest.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/bb01282d/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index 18181b3..ac8c7a8 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -321,8 +321,13 @@ public class WebAdminServerIntegrationTest {
.body(containsString("\"info\":{\"description\":\"All the web administration API for JAMES\",\"version\":\"V1.0\",\"title\":\"JAMES Web Admin API\"}"))
.body(containsString("\"tags\":[\"User's Mailbox\"]"))
.body(containsString("\"tags\":[\"GlobalQuota\"]"))
+ .body(containsString("\"tags\":[\"DomainQuota\"]"))
+ .body(containsString("\"tags\":[\"UserQuota\"]"))
.body(containsString("\"tags\":[\"Domains\"]"))
.body(containsString("\"tags\":[\"Users\"]"))
+ .body(containsString("\"tags\":[\"MailRepositories\"]"))
+ .body(containsString("\"tags\":[\"MailQueues\"]"))
+ .body(containsString("\"tags\":[\"Address Forwards\"]"))
.body(containsString("\"tags\":[\"Address Groups\"]"));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/4] james-project git commit: JAMES-2401 DomainQuotaService is not
in the right package
Posted by ma...@apache.org.
JAMES-2401 DomainQuotaService is not in the right package
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/91b90f0f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/91b90f0f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/91b90f0f
Branch: refs/heads/master
Commit: 91b90f0f1a02e666df9d38f5de35b97a06630432
Parents: 4c1093d
Author: benwa <bt...@linagora.com>
Authored: Fri May 18 16:34:57 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri May 18 16:41:16 2018 +0700
----------------------------------------------------------------------
.../webadmin/routes/DomainQuotaRoutes.java | 1 +
.../webadmin/routes/DomainQuotaService.java | 82 --------------------
.../webadmin/service/DomainQuotaService.java | 82 ++++++++++++++++++++
.../DomainQuotaRoutesNoVirtualHostingTest.java | 1 +
.../webadmin/routes/DomainQuotaRoutesTest.java | 1 +
5 files changed, 85 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/91b90f0f/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
index a73c5d1..3360c23 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
@@ -39,6 +39,7 @@ import org.apache.james.user.api.UsersRepository;
import org.apache.james.user.api.UsersRepositoryException;
import org.apache.james.webadmin.Routes;
import org.apache.james.webadmin.dto.QuotaDTO;
+import org.apache.james.webadmin.service.DomainQuotaService;
import org.apache.james.webadmin.utils.ErrorResponder;
import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
import org.apache.james.webadmin.utils.JsonExtractException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/91b90f0f/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaService.java
deleted file mode 100644
index 08b75e4..0000000
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaService.java
+++ /dev/null
@@ -1,82 +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.webadmin.routes;
-
-import java.util.Optional;
-
-import javax.inject.Inject;
-
-import org.apache.james.core.Domain;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.quota.MaxQuotaManager;
-import org.apache.james.mailbox.quota.QuotaCount;
-import org.apache.james.mailbox.quota.QuotaSize;
-import org.apache.james.webadmin.dto.QuotaDTO;
-
-import com.github.fge.lambdas.Throwing;
-
-public class DomainQuotaService {
-
- private final MaxQuotaManager maxQuotaManager;
-
- @Inject
- public DomainQuotaService(MaxQuotaManager maxQuotaManager) {
- this.maxQuotaManager = maxQuotaManager;
- }
-
- public Optional<QuotaCount> getMaxCountQuota(Domain domain) {
- return maxQuotaManager.getDomainMaxMessage(domain);
- }
-
- public void setMaxCountQuota(Domain domain, QuotaCount quotaCount) throws MailboxException {
- maxQuotaManager.setDomainMaxMessage(domain, quotaCount);
- }
-
- public void remoteMaxQuotaCount(Domain domain) throws MailboxException {
- maxQuotaManager.removeDomainMaxMessage(domain);
- }
-
- public Optional<QuotaSize> getMaxSizeQuota(Domain domain) {
- return maxQuotaManager.getDomainMaxStorage(domain);
- }
-
- public void setMaxSizeQuota(Domain domain, QuotaSize quotaSize) throws MailboxException {
- maxQuotaManager.setDomainMaxStorage(domain, quotaSize);
- }
-
- public void remoteMaxQuotaSize(Domain domain) throws MailboxException {
- maxQuotaManager.removeDomainMaxStorage(domain);
- }
-
- public QuotaDTO getQuota(Domain domain) {
- return QuotaDTO
- .builder()
- .count(maxQuotaManager.getDomainMaxMessage(domain))
- .size(maxQuotaManager.getDomainMaxStorage(domain))
- .build();
- }
-
- public void defineQuota(Domain domain, QuotaDTO quota) {
- quota.getCount()
- .ifPresent(Throwing.consumer(count -> maxQuotaManager.setDomainMaxMessage(domain, count)));
- quota.getSize()
- .ifPresent(Throwing.consumer(size -> maxQuotaManager.setDomainMaxStorage(domain, size)));
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/91b90f0f/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
new file mode 100644
index 0000000..c0ad607
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
@@ -0,0 +1,82 @@
+/****************************************************************
+ * 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.webadmin.service;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Domain;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+import org.apache.james.webadmin.dto.QuotaDTO;
+
+import com.github.fge.lambdas.Throwing;
+
+public class DomainQuotaService {
+
+ private final MaxQuotaManager maxQuotaManager;
+
+ @Inject
+ public DomainQuotaService(MaxQuotaManager maxQuotaManager) {
+ this.maxQuotaManager = maxQuotaManager;
+ }
+
+ public Optional<QuotaCount> getMaxCountQuota(Domain domain) {
+ return maxQuotaManager.getDomainMaxMessage(domain);
+ }
+
+ public void setMaxCountQuota(Domain domain, QuotaCount quotaCount) throws MailboxException {
+ maxQuotaManager.setDomainMaxMessage(domain, quotaCount);
+ }
+
+ public void remoteMaxQuotaCount(Domain domain) throws MailboxException {
+ maxQuotaManager.removeDomainMaxMessage(domain);
+ }
+
+ public Optional<QuotaSize> getMaxSizeQuota(Domain domain) {
+ return maxQuotaManager.getDomainMaxStorage(domain);
+ }
+
+ public void setMaxSizeQuota(Domain domain, QuotaSize quotaSize) throws MailboxException {
+ maxQuotaManager.setDomainMaxStorage(domain, quotaSize);
+ }
+
+ public void remoteMaxQuotaSize(Domain domain) throws MailboxException {
+ maxQuotaManager.removeDomainMaxStorage(domain);
+ }
+
+ public QuotaDTO getQuota(Domain domain) {
+ return QuotaDTO
+ .builder()
+ .count(maxQuotaManager.getDomainMaxMessage(domain))
+ .size(maxQuotaManager.getDomainMaxStorage(domain))
+ .build();
+ }
+
+ public void defineQuota(Domain domain, QuotaDTO quota) {
+ quota.getCount()
+ .ifPresent(Throwing.consumer(count -> maxQuotaManager.setDomainMaxMessage(domain, count)));
+ quota.getSize()
+ .ifPresent(Throwing.consumer(size -> maxQuotaManager.setDomainMaxStorage(domain, size)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/91b90f0f/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java
index bfca198..0700cef 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesNoVirtualHostingTest.java
@@ -31,6 +31,7 @@ import org.apache.james.user.memory.MemoryUsersRepository;
import org.apache.james.webadmin.WebAdminServer;
import org.apache.james.webadmin.WebAdminUtils;
import org.apache.james.webadmin.jackson.QuotaModule;
+import org.apache.james.webadmin.service.DomainQuotaService;
import org.apache.james.webadmin.utils.JsonTransformer;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.jupiter.api.AfterEach;
http://git-wip-us.apache.org/repos/asf/james-project/blob/91b90f0f/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
index 2e96dda..5c4ae39 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
@@ -37,6 +37,7 @@ import org.apache.james.user.memory.MemoryUsersRepository;
import org.apache.james.webadmin.WebAdminServer;
import org.apache.james.webadmin.WebAdminUtils;
import org.apache.james.webadmin.jackson.QuotaModule;
+import org.apache.james.webadmin.service.DomainQuotaService;
import org.apache.james.webadmin.utils.JsonTransformer;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.jupiter.api.AfterEach;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/4] james-project git commit: JAMES-2401 Provide documentation
Posted by ma...@apache.org.
JAMES-2401 Provide documentation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cb9ccb5d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cb9ccb5d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cb9ccb5d
Branch: refs/heads/master
Commit: cb9ccb5d5e29a5c08bb1b73603e938519c6530bf
Parents: 91b90f0
Author: benwa <bt...@linagora.com>
Authored: Fri May 18 17:07:49 2018 +0700
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Fri May 18 16:29:11 2018 +0200
----------------------------------------------------------------------
src/site/markdown/server/manage-webadmin.md | 30 ++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/cb9ccb5d/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 420825e..0748379 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -282,10 +282,31 @@ The answer is the details of the quota of that user.
```
{
- "global": {"count":252,"size":242},
- "domain": {"count":152,"size":142},
- "user": {"count":52,"size":42},
- "computed": {"count":52,"size":42}
+ "global": {
+ "count":252,
+ "size":242
+ },
+ "domain": {
+ "count":152,
+ "size":142
+ },
+ "user": {
+ "count":52,
+ "size":42
+ },
+ "computed": {
+ "count":52,
+ "size":42
+ },
+ "occupation": {
+ "size":1000,
+ "count":10000,
+ "ratio": {
+ "size":0.8,
+ "count":0.6,
+ "max":0.8
+ }
+ }
}
```
@@ -293,6 +314,7 @@ The answer is the details of the quota of that user.
- The `domain` entry represent the quota limit allowed for the user of that domain.
- The `user` entry represent the quota limit allowed for this specific user.
- The `computed` entry represent the quota limit applied for this user, resolved from the upper values.
+ - The `occupation` entry represent the occupation of the quota for this user. This includes used count and size as well as occupation ratio (used / limit).
Note that `quota` object can contain a fixed value, an empty value (null) or an unlimited value (-1):
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/4] james-project git commit: JAMES-2401 Getting user details
should return occupation
Posted by ma...@apache.org.
JAMES-2401 Getting user details should return occupation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4c1093dd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4c1093dd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4c1093dd
Branch: refs/heads/master
Commit: 4c1093dd2cfdad3edbc4d78313252c66768881f9
Parents: bb01282
Author: benwa <bt...@linagora.com>
Authored: Fri May 18 16:23:08 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri May 18 16:41:16 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/mailbox/model/Quota.java | 7 +++
.../apache/james/mailbox/model/QuotaTest.java | 23 +++++++
.../james/webadmin/dto/OccupationDTO.java | 55 +++++++++++++++++
.../james/webadmin/dto/OccupationRatioDTO.java | 53 ++++++++++++++++
.../james/webadmin/dto/QuotaDetailsDTO.java | 21 ++++++-
.../webadmin/service/UserQuotaService.java | 9 ++-
.../webadmin/routes/UserQuotaRoutesTest.java | 63 +++++++++++++++++++-
7 files changed, 226 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/mailbox/api/src/main/java/org/apache/james/mailbox/model/Quota.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Quota.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Quota.java
index cabd05a..8b2a2a8 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Quota.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Quota.java
@@ -94,6 +94,13 @@ public class Quota<T extends QuotaValue<T>> {
return used;
}
+ public double getRatio() {
+ if (limit.isUnlimited()) {
+ return 0;
+ }
+ return Double.valueOf(used.asLong()) / Double.valueOf(limit.asLong());
+ }
+
public ImmutableMap<Scope, T> getLimitByScope() {
return limitByScope;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java
index ef5a1d6..bcf360b 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
import org.junit.Test;
public class QuotaTest {
@@ -93,4 +94,26 @@ public class QuotaTest {
assertThat(actual).isNotNull();
}
+ @Test
+ public void getRatioShouldReturnUsedDividedByLimit() {
+ assertThat(
+ Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(15))
+ .computedLimit(QuotaSize.size(60))
+ .build()
+ .getRatio())
+ .isEqualTo(0.25);
+ }
+
+ @Test
+ public void getRatioShouldReturnZeroWhenUnlimited() {
+ assertThat(
+ Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(15))
+ .computedLimit(QuotaSize.unlimited())
+ .build()
+ .getRatio())
+ .isEqualTo(0);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationDTO.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationDTO.java
new file mode 100644
index 0000000..ca85a37
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationDTO.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.webadmin.dto;
+
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+
+public class OccupationDTO {
+ public static OccupationDTO from(Quota<QuotaSize> sizeQuota, Quota<QuotaCount> countQuota) {
+ return new OccupationDTO(
+ sizeQuota.getUsed().asLong(),
+ countQuota.getUsed().asLong(),
+ OccupationRatioDTO.from(sizeQuota, countQuota));
+ }
+
+ private final long size;
+ private final long count;
+ private final OccupationRatioDTO ratio;
+
+ private OccupationDTO(long size, long count, OccupationRatioDTO ratio) {
+ this.size = size;
+ this.count = count;
+ this.ratio = ratio;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public OccupationRatioDTO getRatio() {
+ return ratio;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
new file mode 100644
index 0000000..1358f13
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.webadmin.dto;
+
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+
+public class OccupationRatioDTO {
+
+ public static OccupationRatioDTO from(Quota<QuotaSize> sizeQuota, Quota<QuotaCount> countQuota) {
+ return new OccupationRatioDTO(
+ sizeQuota.getRatio(),
+ countQuota.getRatio());
+ }
+
+ private final double size;
+ private final double count;
+
+ private OccupationRatioDTO(double size, double count) {
+ this.size = size;
+ this.count = count;
+ }
+
+ public double getSize() {
+ return size;
+ }
+
+ public double getCount() {
+ return count;
+ }
+
+ public double getMax() {
+ return Math.max(size, count);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDetailsDTO.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDetailsDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDetailsDTO.java
index 0519c43..e365ecc 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDetailsDTO.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDetailsDTO.java
@@ -23,6 +23,10 @@ package org.apache.james.webadmin.dto;
import java.util.Optional;
import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+
+import com.google.common.base.Preconditions;
public class QuotaDetailsDTO {
@@ -35,6 +39,7 @@ public class QuotaDetailsDTO {
private Optional<QuotaDTO> domain;
private Optional<QuotaDTO> user;
private Optional<QuotaDTO> computed;
+ private OccupationDTO occupation;
private Builder() {
global = Optional.empty();
@@ -62,6 +67,11 @@ public class QuotaDetailsDTO {
return this;
}
+ public Builder occupation(Quota<QuotaSize> sizeQuota, Quota<QuotaCount> countQuota) {
+ this.occupation = OccupationDTO.from(sizeQuota, countQuota);
+ return this;
+ }
+
public Builder valueForScope(Quota.Scope scope, QuotaDTO value) {
switch (scope) {
case Global:
@@ -75,7 +85,8 @@ public class QuotaDetailsDTO {
}
public QuotaDetailsDTO build() {
- return new QuotaDetailsDTO(global, domain, user, computed);
+ Preconditions.checkNotNull(occupation);
+ return new QuotaDetailsDTO(global, domain, user, computed, occupation);
}
}
@@ -83,12 +94,14 @@ public class QuotaDetailsDTO {
private final Optional<QuotaDTO> domain;
private final Optional<QuotaDTO> user;
private final Optional<QuotaDTO> computed;
+ private final OccupationDTO occupation;
- private QuotaDetailsDTO(Optional<QuotaDTO> global, Optional<QuotaDTO> domain, Optional<QuotaDTO> user, Optional<QuotaDTO> computed) {
+ private QuotaDetailsDTO(Optional<QuotaDTO> global, Optional<QuotaDTO> domain, Optional<QuotaDTO> user, Optional<QuotaDTO> computed, OccupationDTO occupation) {
this.global = global;
this.domain = domain;
this.user = user;
this.computed = computed;
+ this.occupation = occupation;
}
public Optional<QuotaDTO> getGlobal() {
@@ -106,4 +119,8 @@ public class QuotaDetailsDTO {
public Optional<QuotaDTO> getComputed() {
return computed;
}
+
+ public OccupationDTO getOccupation() {
+ return occupation;
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
index 7e48bba..31a934f 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserQuotaService.java
@@ -31,6 +31,7 @@ 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.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaSize;
import org.apache.james.mailbox.quota.UserQuotaRootResolver;
import org.apache.james.webadmin.dto.QuotaDTO;
@@ -42,11 +43,13 @@ import com.google.common.collect.Sets;
public class UserQuotaService {
private final MaxQuotaManager maxQuotaManager;
+ private final QuotaManager quotaManager;
private final UserQuotaRootResolver userQuotaRootResolver;
@Inject
- public UserQuotaService(MaxQuotaManager maxQuotaManager, UserQuotaRootResolver userQuotaRootResolver) {
+ public UserQuotaService(MaxQuotaManager maxQuotaManager, QuotaManager quotaManager, UserQuotaRootResolver userQuotaRootResolver) {
this.maxQuotaManager = maxQuotaManager;
+ this.quotaManager = quotaManager;
this.userQuotaRootResolver = userQuotaRootResolver;
}
@@ -60,7 +63,9 @@ public class UserQuotaService {
public QuotaDetailsDTO getQuota(User user) throws MailboxException {
QuotaRoot quotaRoot = userQuotaRootResolver.forUser(user);
- QuotaDetailsDTO.Builder quotaDetails = QuotaDetailsDTO.builder();
+ QuotaDetailsDTO.Builder quotaDetails = QuotaDetailsDTO.builder()
+ .occupation(quotaManager.getStorageQuota(quotaRoot),
+ quotaManager.getMessageQuota(quotaRoot));
mergeMaps(
maxQuotaManager.listMaxMessagesDetails(quotaRoot),
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c1093dd/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
index 2d877e3..b3c7204 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserQuotaRoutesTest.java
@@ -23,6 +23,8 @@ import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.when;
import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
import java.util.Map;
@@ -31,10 +33,13 @@ import org.apache.james.core.User;
import org.apache.james.dnsservice.api.InMemoryDNSService;
import org.apache.james.domainlist.memory.MemoryDomainList;
import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
+import org.apache.james.mailbox.quota.CurrentQuotaManager;
import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaSize;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
+import org.apache.james.mailbox.store.quota.StoreQuotaManager;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.apache.james.user.memory.MemoryUsersRepository;
import org.apache.james.webadmin.WebAdminServer;
@@ -48,6 +53,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import com.google.common.collect.ImmutableSet;
import com.jayway.restassured.RestAssured;
@@ -67,6 +73,7 @@ class UserQuotaRoutesTest {
private WebAdminServer webAdminServer;
private InMemoryPerUserMaxQuotaManager maxQuotaManager;
private DefaultUserQuotaRootResolver userQuotaRootResolver;
+ private CurrentQuotaManager currentQuotaManager;
@BeforeEach
void setUp() throws Exception {
@@ -79,7 +86,13 @@ class UserQuotaRoutesTest {
usersRepository.addUser(BOB.asString(), PASSWORD);
MailboxSessionMapperFactory factory = null;
userQuotaRootResolver = new DefaultUserQuotaRootResolver(factory);
- UserQuotaService userQuotaService = new UserQuotaService(maxQuotaManager, userQuotaRootResolver);
+
+ currentQuotaManager = mock(CurrentQuotaManager.class);
+ Mockito.when(currentQuotaManager.getCurrentMessageCount(any())).thenReturn(QuotaCount.count(0));
+ Mockito.when(currentQuotaManager.getCurrentStorage(any())).thenReturn(QuotaSize.size(0));
+
+ QuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager);
+ UserQuotaService userQuotaService = new UserQuotaService(maxQuotaManager, quotaManager, userQuotaRootResolver);
QuotaModule quotaModule = new QuotaModule();
UserQuotaRoutes userQuotaRoutes = new UserQuotaRoutes(usersRepository, userQuotaService, new JsonTransformer(quotaModule), ImmutableSet.of(quotaModule));
webAdminServer = WebAdminUtils.createWebAdminServer(
@@ -422,6 +435,54 @@ class UserQuotaRoutesTest {
}
@Test
+ public void getQuotaShouldReturnOccupation() throws Exception {
+ maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.size(80));
+ maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.count(100));
+ Mockito.when(currentQuotaManager.getCurrentStorage(any())).thenReturn(QuotaSize.size(40));
+ Mockito.when(currentQuotaManager.getCurrentMessageCount(any())).thenReturn(QuotaCount.count(20));
+
+ JsonPath jsonPath =
+ given()
+ .get(QUOTA_USERS + "/" + BOB.asString())
+ .then()
+ .statusCode(HttpStatus.OK_200)
+ .contentType(ContentType.JSON)
+ .extract()
+ .jsonPath();
+
+ SoftAssertions softly = new SoftAssertions();
+ softly.assertThat(jsonPath.getLong("occupation.count")).isEqualTo(20);
+ softly.assertThat(jsonPath.getLong("occupation.size")).isEqualTo(40);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.count")).isEqualTo(0.2);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.size")).isEqualTo(0.5);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.max")).isEqualTo(0.5);
+ }
+
+ @Test
+ public void getQuotaShouldReturnOccupationWhenUnlimited() throws Exception {
+ maxQuotaManager.setMaxStorage(userQuotaRootResolver.forUser(BOB), QuotaSize.unlimited());
+ maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.unlimited());
+ Mockito.when(currentQuotaManager.getCurrentStorage(any())).thenReturn(QuotaSize.size(40));
+ Mockito.when(currentQuotaManager.getCurrentMessageCount(any())).thenReturn(QuotaCount.count(20));
+
+ JsonPath jsonPath =
+ given()
+ .get(QUOTA_USERS + "/" + BOB.asString())
+ .then()
+ .statusCode(HttpStatus.OK_200)
+ .contentType(ContentType.JSON)
+ .extract()
+ .jsonPath();
+
+ SoftAssertions softly = new SoftAssertions();
+ softly.assertThat(jsonPath.getLong("occupation.count")).isEqualTo(20);
+ softly.assertThat(jsonPath.getLong("occupation.size")).isEqualTo(40);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.count")).isEqualTo(0);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.size")).isEqualTo(0);
+ softly.assertThat(jsonPath.getDouble("occupation.ratio.max")).isEqualTo(0);
+ }
+
+ @Test
public void getQuotaShouldReturnOnlySpecifiedValues() throws Exception {
maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(1111));
maxQuotaManager.setMaxMessage(userQuotaRootResolver.forUser(BOB), QuotaCount.count(18));
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org