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 bt...@apache.org on 2018/12/19 04:10:29 UTC
[03/13] james-project git commit: MAILBOX-359 POJOify MailboxMetaData
MAILBOX-359 POJOify MailboxMetaData
That way, the Mailbox API is all we need to instanciate this POJO
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c25596df
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c25596df
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c25596df
Branch: refs/heads/master
Commit: c25596dfdba4c970dcd1de1638f18b29d68825fa
Parents: 89917a8
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 17 11:06:40 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 19 10:55:21 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/model/MailboxMetaData.java | 98 +++++++++++++--
.../mailbox/store/SimpleMailboxMetaData.java | 120 -------------------
.../mailbox/store/StoreMailboxManager.java | 4 +-
.../james/imap/processor/ListProcessor.java | 33 +----
.../james/jmap/model/MailboxFactoryTest.java | 4 +-
.../routes/UserMailboxesRoutesTest.java | 12 +-
6 files changed, 101 insertions(+), 170 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
index 14d1ee7..355beb8 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxMetaData.java
@@ -19,21 +19,24 @@
package org.apache.james.mailbox.model;
+import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
+
/**
* Returned by the list method of MailboxRepository and others
*/
-public interface MailboxMetaData {
-
+public class MailboxMetaData implements Comparable<MailboxMetaData> {
/** RFC3501 Selectability flag */
- enum Selectability {
+ public enum Selectability {
NONE, MARKED, UNMARKED, NOSELECT
}
/**
* Indicates whether this mailbox allows children and - if so - whether it
* has any.
+ *
+ * See <code>\Noinferiors</code> as per RFC3501.
*/
- enum Children {
+ public enum Children {
/**
* No children allowed.
*/
@@ -54,31 +57,104 @@ public interface MailboxMetaData {
HAS_NO_CHILDREN
}
+ private final MailboxPath path;
+ private final char delimiter;
+ private final Children inferiors;
+ private final Selectability selectability;
+ private final MailboxId mailboxId;
+
+ public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
+ this(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
+ }
+
+ public MailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter, Children inferiors, Selectability selectability) {
+ super();
+ this.path = path;
+ this.mailboxId = mailboxId;
+ this.delimiter = delimiter;
+ this.inferiors = inferiors;
+ this.selectability = selectability;
+ }
+
+
/**
* Gets the inferiors status of this mailbox.
- *
+ *
+ * Is this mailbox <code>\Noinferiors</code> as per RFC3501.
+ *
* @return not null
*/
- Children inferiors();
+ public final Children inferiors() {
+ return inferiors;
+ }
/**
* Gets the RFC3501 Selectability flag.
*/
- Selectability getSelectability();
+ public final Selectability getSelectability() {
+ return selectability;
+ }
/**
* Return the delimiter
*
* @return delimiter
*/
- char getHierarchyDelimiter();
+ public char getHierarchyDelimiter() {
+ return delimiter;
+ }
+
/**
* Return the MailboxPath
*
* @return path
*/
- MailboxPath getPath();
-
- MailboxId getId();
+ public MailboxPath getPath() {
+ return path;
+ }
+
+ public MailboxId getId() {
+ return mailboxId;
+ }
+
+ @Override
+ public String toString() {
+ return "ListResult: " + path;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final MailboxMetaData other = (MailboxMetaData) obj;
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int compareTo(MailboxMetaData o) {
+ return StandardMailboxMetaDataComparator.order(this, o);
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
deleted file mode 100644
index a3d63bd..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SimpleMailboxMetaData.java
+++ /dev/null
@@ -1,120 +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.mailbox.store;
-
-import org.apache.james.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-
-public class SimpleMailboxMetaData implements MailboxMetaData, Comparable<MailboxMetaData> {
- private final MailboxPath path;
- private final char delimiter;
- private final Children inferiors;
- private final Selectability selectability;
- private final MailboxId mailboxId;
-
- public SimpleMailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter) {
- this(path, mailboxId, delimiter, Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.NONE);
- }
-
- public SimpleMailboxMetaData(MailboxPath path, MailboxId mailboxId, char delimiter, Children inferiors, Selectability selectability) {
- super();
- this.path = path;
- this.mailboxId = mailboxId;
- this.delimiter = delimiter;
- this.inferiors = inferiors;
- this.selectability = selectability;
- }
-
- /**
- * Is this mailbox <code>\Noinferiors</code> as per RFC3501.
- *
- * @return true if marked, false otherwise
- */
- @Override
- public final Children inferiors() {
- return inferiors;
- }
-
- /**
- * Gets the RFC3501 Selectability flag.
- */
- @Override
- public final Selectability getSelectability() {
- return selectability;
- }
-
- @Override
- public char getHierarchyDelimiter() {
- return delimiter;
- }
-
- @Override
- public MailboxPath getPath() {
- return path;
- }
-
- @Override
- public MailboxId getId() {
- return mailboxId;
- }
-
- @Override
- public String toString() {
- return "ListResult: " + path;
- }
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + ((path == null) ? 0 : path.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final SimpleMailboxMetaData other = (SimpleMailboxMetaData) obj;
- if (path == null) {
- if (other.path != null) {
- return false;
- }
- } else if (!path.equals(other.path)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int compareTo(MailboxMetaData o) {
- return StandardMailboxMetaDataComparator.order(this, o);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 45b4fbc..cbe6425 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -713,8 +713,8 @@ public class StoreMailboxManager implements MailboxManager {
return mailboxMapper.findNonPersonalMailboxes(session.getUser().asString(), right).stream();
}
- private SimpleMailboxMetaData toMailboxMetadata(MailboxSession session, List<Mailbox> mailboxes, Mailbox mailbox) {
- return new SimpleMailboxMetaData(
+ private MailboxMetaData toMailboxMetadata(MailboxSession session, List<Mailbox> mailboxes, Mailbox mailbox) {
+ return new MailboxMetaData(
mailbox.generateAssociatedPath(),
mailbox.getMailboxId(),
getDelimiter(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index ec66922..e0569c1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -119,36 +119,11 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
isRelative = true;
}
// Get the mailbox for the reference name.
- final MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
+ MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
+ MailboxId mailboxId = null;
results = new ArrayList<>(1);
- results.add(new MailboxMetaData() {
-
- @Override
- public Children inferiors() {
- return Children.CHILDREN_ALLOWED_BUT_UNKNOWN;
- }
-
- @Override
- public Selectability getSelectability() {
- return Selectability.NOSELECT;
- }
-
- @Override
- public char getHierarchyDelimiter() {
- return mailboxSession.getPathDelimiter();
- }
-
- @Override
- public MailboxPath getPath() {
- return rootPath;
- }
-
- @Override
- public MailboxId getId() {
- return null; //Will not be call in ListProcessor scope
- }
-
- });
+ results.add(new MailboxMetaData(rootPath, mailboxId, mailboxSession.getPathDelimiter(),
+ MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NOSELECT));
} else {
// If the mailboxPattern is fully qualified, ignore the
// reference name.
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
----------------------------------------------------------------------
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 d9244ac..d213045 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
@@ -30,11 +30,11 @@ import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
import org.apache.james.mailbox.manager.ManagerTestResources;
import org.apache.james.mailbox.model.MailboxACL;
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.quota.MaxQuotaManager;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.assertj.core.api.JUnitSoftAssertions;
import org.junit.Before;
@@ -173,7 +173,7 @@ public class MailboxFactoryTest {
mailboxManager.createMailbox(mailboxPath, mailboxSession);
Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath,
- Optional.of(ImmutableList.of(new SimpleMailboxMetaData(parentMailboxPath, parentId, DELIMITER))),
+ Optional.of(ImmutableList.of(new MailboxMetaData(parentMailboxPath, parentId, DELIMITER))),
mailboxSession);
assertThat(id).contains(parentId);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c25596df/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 4081afd..1c60d93 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -43,9 +43,9 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
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.search.MailboxQuery;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
import org.apache.james.metrics.logger.DefaultMetricFactory;
import org.apache.james.user.api.UsersRepository;
import org.apache.james.webadmin.WebAdminServer;
@@ -774,7 +774,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(
+ new MailboxMetaData(
MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
@@ -800,7 +800,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
+ new MailboxMetaData(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -856,7 +856,7 @@ class UserMailboxesRoutesTest {
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
ImmutableList.of(
- new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -870,7 +870,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(), any());
when()
@@ -884,7 +884,7 @@ class UserMailboxesRoutesTest {
MailboxId mailboxId = InMemoryId.of(12);
when(mailboxManager.search(any(MailboxQuery.class), any()))
.thenReturn(
- ImmutableList.of(new SimpleMailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+ ImmutableList.of(new MailboxMetaData(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
when()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org