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/05 09:44:32 UTC
[01/14] james-project git commit: JAMES-2596 Add more test for
listSources
Repository: james-project
Updated Branches:
refs/heads/master d78ea34ec -> 16e4d9f93
JAMES-2596 Add more test for listSources
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8ab8d8bf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8ab8d8bf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8ab8d8bf
Branch: refs/heads/master
Commit: 8ab8d8bf4bfb2afc6697b1b2c1ad624ad7cdc3c6
Parents: 80f655c
Author: datph <dp...@linagora.com>
Authored: Fri Nov 30 17:34:59 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:33:18 2018 +0700
----------------------------------------------------------------------
.../james/rrt/api/RecipientRewriteTable.java | 31 ++-
.../user/lib/AbstractJamesUsersRepository.java | 4 -
.../lib/AbstractRecipientRewriteTableTest.java | 216 +++++++++++--------
3 files changed, 142 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8ab8d8bf/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index c21ba3a..cba17a4 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.rrt.api;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -26,7 +27,8 @@ import org.apache.james.rrt.lib.Mapping;
import org.apache.james.rrt.lib.MappingSource;
import org.apache.james.rrt.lib.Mappings;
-import com.google.common.collect.ImmutableList;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Preconditions;
/**
* Interface which should be implemented of classes which map recipients.
@@ -110,30 +112,25 @@ public interface RecipientRewriteTable {
Map<MappingSource, Mappings> getAllMappings() throws RecipientRewriteTableException;
default List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
- if (!isSupportedListSources(mapping)) {
- return ImmutableList.of();
- }
+ Preconditions.checkArgument(supportsSourceListing(mapping),
+ String.format("Not supported mapping of type %s", mapping.getType()));
return getAllMappings().entrySet().stream()
- .filter(entry -> filterMapping(entry, mapping))
+ .filter(entry -> entry.getValue().contains(mapping))
.map(Map.Entry::getKey)
- .collect(ImmutableList.toImmutableList());
+ .collect(Guavate.toImmutableList());
}
- default boolean filterMapping(Map.Entry<MappingSource, Mappings> entry, Mapping mapping) {
- return entry.getValue()
- .asStream()
- .anyMatch(map -> map.equals(mapping));
- }
+ EnumSet<Mapping.Type> listSourcesSupportedType = EnumSet.of(
+ Mapping.Type.Group,
+ Mapping.Type.Forward,
+ Mapping.Type.Address);
- default boolean isSupportedListSources(Mapping mapping) {
- return listSourcesSupportedType.stream()
- .anyMatch(type -> type.equals(mapping.getType()));
+ default boolean supportsSourceListing(Mapping mapping) {
+ return listSourcesSupportedType.contains(
+ mapping.getType());
}
- List<Mapping.Type> listSourcesSupportedType = ImmutableList
- .of(Mapping.Type.Group, Mapping.Type.Forward, Mapping.Type.Address);
-
class ErrorMappingException extends Exception {
private static final long serialVersionUID = 2348752938798L;
http://git-wip-us.apache.org/repos/asf/james-project/blob/8ab8d8bf/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
index 3b5d205..491accb 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
@@ -21,9 +21,7 @@ package org.apache.james.user.lib;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Optional;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -44,8 +42,6 @@ import org.apache.james.user.lib.model.DefaultJamesUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableList;
-
/**
* A partial implementation of a Repository to store users.
* <p>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8ab8d8bf/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
index abf05bb..671b1c8 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
@@ -41,6 +41,9 @@ import com.github.fge.lambdas.Throwing;
*/
public abstract class AbstractRecipientRewriteTableTest {
+ private static final String USER = "test";
+ private static final String ADDRESS = "test@localhost2";
+
protected abstract AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception;
@Rule public ExpectedException expectedException = ExpectedException.none();
@@ -68,29 +71,28 @@ public abstract class AbstractRecipientRewriteTableTest {
}
@Test
- public void testStoreAndGetMappings() throws ErrorMappingException, RecipientRewriteTableException {
+ public void testStoreAndGetMappings() throws Exception {
Domain domain = Domain.of("test");
virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.regex("prefix_.*:admin@test"));
assertThat(virtualUserTable.getMappings("prefix_abc", domain)).isNotEmpty();
}
@Test
- public void testStoreAndRetrieveRegexMapping() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void testStoreAndRetrieveRegexMapping() throws Exception {
Domain domain = Domain.LOCALHOST;
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
// String regex = "(.*):{$1}@localhost";
// String regex2 = "(.+):{$1}@test";
String regex = "(.*)@localhost";
String regex2 = "(.+)@test";
String invalidRegex = ".*):";
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
virtualUserTable.addMapping(source, Mapping.regex(regex));
virtualUserTable.addMapping(source, Mapping.regex(regex2));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
virtualUserTable.removeMapping(source, Mapping.regex(regex));
@@ -102,24 +104,23 @@ public abstract class AbstractRecipientRewriteTableTest {
virtualUserTable.removeMapping(source, Mapping.regex(regex2));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
}
@Test
public void getAllMappingsShouldListAllEntries() throws Exception {
- String user = "test";
String user2 = "test2";
String regex = "(.*)@localhost";
String regex2 = "(.+)@test";
- MappingSource source1 = MappingSource.fromUser(user, Domain.LOCALHOST);
+ MappingSource source1 = MappingSource.fromUser(USER, Domain.LOCALHOST);
MappingSource source2 = MappingSource.fromUser(user2, Domain.LOCALHOST);
virtualUserTable.addMapping(source1, Mapping.regex(regex));
virtualUserTable.addMapping(source1, Mapping.regex(regex2));
- virtualUserTable.addMapping(source2, Mapping.address(user + "@" + Domain.LOCALHOST.asString()));
+ virtualUserTable.addMapping(source2, Mapping.address(USER + "@" + Domain.LOCALHOST.asString()));
assertThat(virtualUserTable.getAllMappings())
.describedAs("One mappingline")
@@ -129,90 +130,84 @@ public abstract class AbstractRecipientRewriteTableTest {
.add(Mapping.regex(regex2))
.build()),
Pair.of(source2, MappingsImpl.builder()
- .add(Mapping.address(user + "@" + Domain.LOCALHOST.asString()))
+ .add(Mapping.address(USER + "@" + Domain.LOCALHOST.asString()))
.build()));
}
@Test
- public void testStoreAndRetrieveAddressMapping() throws ErrorMappingException, RecipientRewriteTableException {
-
- String user = "test";
+ public void testStoreAndRetrieveAddressMapping() throws Exception {
Domain domain = Domain.LOCALHOST;
- MappingSource source = MappingSource.fromUser(user, domain);
- String address = "test@localhost2";
+ MappingSource source = MappingSource.fromUser(USER, domain);
String address2 = "test@james";
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
- virtualUserTable.addMapping(source, Mapping.address(address));
+ virtualUserTable.addMapping(source, Mapping.address(ADDRESS));
virtualUserTable.addMapping(source, Mapping.address(address2));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("Two mappings").hasSize(2);
assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
- virtualUserTable.removeMapping(source, Mapping.address(address));
+ virtualUserTable.removeMapping(source, Mapping.address(ADDRESS));
virtualUserTable.removeMapping(source, Mapping.address(address2));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
}
@Test
- public void testStoreAndRetrieveErrorMapping() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void testStoreAndRetrieveErrorMapping() throws Exception {
Domain domain = Domain.LOCALHOST;
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
String error = "bounce!";
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
virtualUserTable.addMapping(source, Mapping.error(error));
assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
assertThatThrownBy(() ->
- virtualUserTable.getMappings(user, domain))
+ virtualUserTable.getMappings(USER, domain))
.describedAs("Exception thrown on to many mappings")
.isInstanceOf(ErrorMappingException.class);
virtualUserTable.removeMapping(source, Mapping.error(error));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty();
}
@Test
- public void testStoreAndRetrieveWildCardAddressMapping() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void testStoreAndRetrieveWildCardAddressMapping() throws Exception {
String user2 = "test2";
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
String address2 = "test@james";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
- virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.address(address));
+ virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.address(ADDRESS));
virtualUserTable.addMapping(source, Mapping.address(address2));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("One mappings").hasSize(1);
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("One mappings").hasSize(1);
assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1);
virtualUserTable.removeMapping(source, Mapping.address(address2));
- virtualUserTable.removeMapping(MappingSource.fromDomain(domain), Mapping.address(address));
+ virtualUserTable.removeMapping(MappingSource.fromDomain(domain), Mapping.address(ADDRESS));
- assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping")
+ assertThat(virtualUserTable.getMappings(USER, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping")
.isEqualTo(MappingsImpl.empty());
}
@Test
- public void testRecursiveMapping() throws ErrorMappingException, RecipientRewriteTableException {
+ public void testRecursiveMapping() throws Exception {
String user1 = "user1";
String user2 = "user2";
String user3 = "user3";
@@ -243,7 +238,7 @@ public abstract class AbstractRecipientRewriteTableTest {
}
@Test
- public void testAliasDomainMapping() throws ErrorMappingException, RecipientRewriteTableException {
+ public void testAliasDomainMapping() throws Exception {
String domain = "realdomain";
Domain aliasDomain = Domain.of("aliasdomain");
String user = "user";
@@ -267,119 +262,164 @@ public abstract class AbstractRecipientRewriteTableTest {
@Test
public void addMappingShouldThrowWhenMappingAlreadyExists() throws Exception {
- String user = "test";
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
expectedException.expect(RecipientRewriteTableException.class);
- virtualUserTable.addAddressMapping(source, address);
- virtualUserTable.addAddressMapping(source, address);
+ virtualUserTable.addAddressMapping(source, ADDRESS);
+ virtualUserTable.addAddressMapping(source, ADDRESS);
}
@Test
public void addMappingShouldNotThrowWhenMappingAlreadyExistsWithAnOtherType() throws Exception {
- String user = "test";
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- virtualUserTable.addMapping(source, Mapping.address(address));
- virtualUserTable.addMapping(source, Mapping.regex(address));
+ virtualUserTable.addMapping(source, Mapping.address(ADDRESS));
+ virtualUserTable.addMapping(source, Mapping.regex(ADDRESS));
- assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2);
+ assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
}
@Test
- public void addForwardMappingShouldStore() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void addForwardMappingShouldStore() throws Exception {
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
String address2 = "test@james";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- virtualUserTable.addMapping(source, Mapping.forward(address));
+ virtualUserTable.addMapping(source, Mapping.forward(ADDRESS));
virtualUserTable.addMapping(source, Mapping.forward(address2));
- assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2);
+ assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
}
@Test
- public void removeForwardMappingShouldDelete() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void removeForwardMappingShouldDelete() throws Exception {
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
String address2 = "test@james";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- virtualUserTable.addMapping(source, Mapping.forward(address));
+ virtualUserTable.addMapping(source, Mapping.forward(ADDRESS));
virtualUserTable.addMapping(source, Mapping.forward(address2));
- virtualUserTable.removeMapping(source, Mapping.forward(address));
+ virtualUserTable.removeMapping(source, Mapping.forward(ADDRESS));
virtualUserTable.removeMapping(source, Mapping.forward(address2));
- assertThat(virtualUserTable.getMappings(user, domain))
+ assertThat(virtualUserTable.getMappings(USER, domain))
.isEqualTo(MappingsImpl.empty());
}
@Test
- public void addGroupMappingShouldStore() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void addGroupMappingShouldStore() throws Exception {
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
String address2 = "test@james";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- virtualUserTable.addMapping(source, Mapping.group(address));
+ virtualUserTable.addMapping(source, Mapping.group(ADDRESS));
virtualUserTable.addMapping(source, Mapping.group(address2));
- assertThat(virtualUserTable.getMappings(user, domain)).hasSize(2);
+ assertThat(virtualUserTable.getMappings(USER, domain)).hasSize(2);
}
@Test
- public void removeGroupMappingShouldDelete() throws ErrorMappingException, RecipientRewriteTableException {
- String user = "test";
+ public void removeGroupMappingShouldDelete() throws Exception {
Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
String address2 = "test@james";
- MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source = MappingSource.fromUser(USER, domain);
- virtualUserTable.addMapping(source, Mapping.group(address));
+ virtualUserTable.addMapping(source, Mapping.group(ADDRESS));
virtualUserTable.addMapping(source, Mapping.group(address2));
- virtualUserTable.removeMapping(source, Mapping.group(address));
+ virtualUserTable.removeMapping(source, Mapping.group(ADDRESS));
virtualUserTable.removeMapping(source, Mapping.group(address2));
- assertThat(virtualUserTable.getMappings(user, domain))
+ assertThat(virtualUserTable.getMappings(USER, domain))
.isEqualTo(MappingsImpl.empty());
}
@Test
- public void listSourcesShouldReturnWhenHasMapping() throws RecipientRewriteTableException {
- String user = "test";
- Domain domain = Domain.LOCALHOST;
- String address = "test@localhost2";
- MappingSource source = MappingSource.fromUser(user, domain);
- Mapping mapping = Mapping.group(address);
+ public void listSourcesShouldReturnWhenHasMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.group(ADDRESS);
virtualUserTable.addMapping(source, mapping);
assertThat(virtualUserTable.listSources(mapping)).contains(source);
}
@Test
- public void listSourceShouldReturnWhenMultipleSourceMapping() throws RecipientRewriteTableException {
- String user = "test";
- Domain domain = Domain.of("james");
- String address = "test@localhost2";
-
- MappingSource source = MappingSource.fromUser(user, domain);
+ public void listSourcesShouldReturnWhenMultipleSourceMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.of("james"));
MappingSource source2 = MappingSource.fromDomain(Domain.LOCALHOST);
- Mapping mapping = Mapping.group(address);
+ Mapping mapping = Mapping.group(ADDRESS);
virtualUserTable.addMapping(source, mapping);
virtualUserTable.addMapping(source2, mapping);
assertThat(virtualUserTable.listSources(mapping)).contains(source, source2);
}
+
+ @Test
+ public void listSourcesShouldReturnWhenHasForwardMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.forward("forward");
+
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThat(virtualUserTable.listSources(mapping)).contains(source);
+ }
+
+ @Test
+ public void listSourcesShouldReturnWhenHasAddressMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.address("address");
+
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThat(virtualUserTable.listSources(mapping)).contains(source);
+ }
+
+ @Test
+ public void listSourcesShouldThrowExceptionWhenHasRegexMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.regex("regex");
+
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThatThrownBy(() -> virtualUserTable.listSources(mapping))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void listSourcesShouldThrowExceptionWhenHasDomainMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.domain(Domain.of("domain"));
+
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThatThrownBy(() -> virtualUserTable.listSources(mapping))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void listSourcesShouldThrowExceptionWhenHasErrorMapping() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping mapping = Mapping.error("error");
+
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThatThrownBy(() -> virtualUserTable.listSources(mapping))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void listSourcesShouldReturnEmptyWhenMappingDoesNotExist() throws Exception {
+ MappingSource source = MappingSource.fromUser(USER, Domain.LOCALHOST);
+ Mapping domainMapping = Mapping.domain(Domain.of("domain"));
+ Mapping groupMapping = Mapping.group("group");
+
+ virtualUserTable.addMapping(source, domainMapping);
+
+ assertThat(virtualUserTable.listSources(groupMapping)).isEmpty();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/14] james-project git commit: JAMES-2555 Make ReIndexing APIs
more REST friendly
Posted by bt...@apache.org.
JAMES-2555 Make ReIndexing APIs more REST friendly
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/985b9a4a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/985b9a4a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/985b9a4a
Branch: refs/heads/master
Commit: 985b9a4a75bfa75c331cba6cbf835c043185dbdb
Parents: 8ab8d8b
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Dec 3 10:51:49 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:33:30 2018 +0700
----------------------------------------------------------------------
.../WebAdminServerIntegrationTest.java | 4 +-
.../routes/MessageIdReindexingRoutes.java | 11 ++-
.../james/webadmin/routes/ReindexingRoutes.java | 60 ++++---------
.../webadmin/routes/ReindexingRoutesTest.java | 93 ++++++++++++--------
src/site/markdown/server/manage-webadmin.md | 16 ++--
5 files changed, 89 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/985b9a4a/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 482d7d6..61e690b 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
@@ -71,7 +71,7 @@ public class WebAdminServerIntegrationTest {
@ClassRule
public static DockerCassandraRule cassandra = new DockerCassandraRule();
-
+
@Rule
public CassandraJmapTestRule cassandraJmapTestRule = CassandraJmapTestRule.defaultTestRule();
@@ -327,7 +327,7 @@ public class WebAdminServerIntegrationTest {
.body(containsString("\"tags\":[\"MailQueues\"]"))
.body(containsString("\"tags\":[\"Address Forwards\"]"))
.body(containsString("\"tags\":[\"Address Groups\"]"))
- .body(containsString("{\"name\":\"ReIndexing\"}"))
+ .body(containsString("{\"name\":\"ReIndexing (mailboxes)\"}"))
.body(containsString("{\"name\":\"MessageIdReIndexing\"}"));
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/985b9a4a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MessageIdReindexingRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MessageIdReindexingRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MessageIdReindexingRoutes.java
index 7031d6a..d98206f 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MessageIdReindexingRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MessageIdReindexingRoutes.java
@@ -19,8 +19,6 @@
package org.apache.james.webadmin.routes;
-import static org.apache.james.webadmin.routes.ReindexingRoutes.BASE_PATH;
-
import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -50,11 +48,12 @@ import spark.Response;
import spark.Service;
@Api(tags = "MessageIdReIndexing")
-@Path("/mailboxIndex")
+@Path("/messages")
@Produces("application/json")
public class MessageIdReindexingRoutes implements Routes {
private static final String MESSAGE_ID_PARAM = ":messageId";
- private static final String MESSAGE_PATH = BASE_PATH + "/messages/" + MESSAGE_ID_PARAM;
+ private static final String BASE_PATH = "/messages";
+ private static final String MESSAGE_PATH = BASE_PATH + "/" + MESSAGE_ID_PARAM;
private final TaskManager taskManager;
private final MessageId.Factory messageIdFactory;
@@ -62,7 +61,7 @@ public class MessageIdReindexingRoutes implements Routes {
private final JsonTransformer jsonTransformer;
@Inject
- public MessageIdReindexingRoutes(TaskManager taskManager, MessageId.Factory messageIdFactory, MessageIdReIndexer reIndexer, JsonTransformer jsonTransformer) {
+ MessageIdReindexingRoutes(TaskManager taskManager, MessageId.Factory messageIdFactory, MessageIdReIndexer reIndexer, JsonTransformer jsonTransformer) {
this.taskManager = taskManager;
this.messageIdFactory = messageIdFactory;
this.reIndexer = reIndexer;
@@ -80,7 +79,7 @@ public class MessageIdReindexingRoutes implements Routes {
}
@POST
- @Path("/messages/{messageId}")
+ @Path("/{messageId}")
@ApiOperation(value = "Re-indexes one email in the different mailboxes containing it")
@ApiImplicitParams({
@ApiImplicitParam(
http://git-wip-us.apache.org/repos/asf/james-project/blob/985b9a4a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
index 28b10cc..8c5a773 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
@@ -39,6 +39,8 @@ import org.apache.james.webadmin.utils.ErrorResponder;
import org.apache.james.webadmin.utils.JsonTransformer;
import org.eclipse.jetty.http.HttpStatus;
+import com.google.common.base.Strings;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -49,8 +51,8 @@ import spark.Request;
import spark.Response;
import spark.Service;
-@Api(tags = "ReIndexing")
-@Path("/mailboxIndex")
+@Api(tags = "ReIndexing (mailboxes)")
+@Path("/mailboxes")
@Produces("application/json")
public class ReindexingRoutes implements Routes {
@FunctionalInterface
@@ -58,12 +60,11 @@ public class ReindexingRoutes implements Routes {
Task generate() throws MailboxException;
}
- static final String BASE_PATH = "/mailboxIndex";
- private static final String USER_PARAM = ":user";
+ private static final String BASE_PATH = "/mailboxes";
+ private static final String USER_QUERY_PARAM = "user";
private static final String MAILBOX_PARAM = ":mailbox";
private static final String UID_PARAM = ":uid";
- private static final String USER_PATH = BASE_PATH + "/users/" + USER_PARAM;
- private static final String MAILBOX_PATH = BASE_PATH + "/mailboxes/" + MAILBOX_PARAM;
+ private static final String MAILBOX_PATH = BASE_PATH + "/" + MAILBOX_PARAM;
private static final String MESSAGE_PATH = MAILBOX_PATH + "/mails/" + UID_PARAM;
private final TaskManager taskManager;
@@ -72,7 +73,7 @@ public class ReindexingRoutes implements Routes {
private final JsonTransformer jsonTransformer;
@Inject
- public ReindexingRoutes(TaskManager taskManager, MailboxId.Factory mailboxIdFactory, ReIndexer reIndexer, JsonTransformer jsonTransformer) {
+ ReindexingRoutes(TaskManager taskManager, MailboxId.Factory mailboxIdFactory, ReIndexer reIndexer, JsonTransformer jsonTransformer) {
this.taskManager = taskManager;
this.mailboxIdFactory = mailboxIdFactory;
this.reIndexer = reIndexer;
@@ -87,7 +88,6 @@ public class ReindexingRoutes implements Routes {
@Override
public void define(Service service) {
service.post(BASE_PATH, this::reIndexAll, jsonTransformer);
- service.post(USER_PATH, this::reIndexUser, jsonTransformer);
service.post(MAILBOX_PATH, this::reIndexMailbox, jsonTransformer);
service.post(MESSAGE_PATH, this::reIndexMessage, jsonTransformer);
}
@@ -103,51 +103,29 @@ public class ReindexingRoutes implements Routes {
dataType = "String",
defaultValue = "none",
example = "?task=reIndex",
- value = "Compulsory. Only supported value is `reIndex`")
- })
- @ApiResponses(value = {
- @ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class),
- @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."),
- @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message")
- })
- private TaskIdDto reIndexAll(Request request, Response response) {
- return wrap(request, response,
- () -> reIndexer.reIndex());
- }
-
- @POST
- @Path("/users/{user}")
- @ApiOperation(value = "Re-indexes all the mails of a user")
- @ApiImplicitParams({
- @ApiImplicitParam(
- required = true,
- name = "task",
- paramType = "query parameter",
- dataType = "String",
- defaultValue = "none",
- example = "?task=reIndex",
value = "Compulsory. Only supported value is `reIndex`"),
@ApiImplicitParam(
- required = true,
name = "user",
- paramType = "path parameter",
+ paramType = "query parameter",
dataType = "String",
defaultValue = "none",
- example = "benoit@apache.org",
- value = "Compulsory. Needs to be a valid username")
+ example = "?user=toto%40domain.tld",
+ value = "optional. If present, only mailboxes of that user will be reIndexed.")
})
@ApiResponses(value = {
@ApiResponse(code = HttpStatus.CREATED_201, message = "Task is created", response = TaskIdDto.class),
@ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."),
@ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - details in the returned error message")
})
- private TaskIdDto reIndexUser(Request request, Response response) {
- return wrap(request, response,
- () -> reIndexer.reIndex(extractUser(request)));
+ private TaskIdDto reIndexAll(Request request, Response response) {
+ if (Strings.isNullOrEmpty(request.queryParams(USER_QUERY_PARAM))) {
+ return wrap(request, response, reIndexer::reIndex);
+ }
+ return wrap(request, response, () -> reIndexer.reIndex(extractUser(request)));
}
@POST
- @Path("/mailboxes/{mailboxId}")
+ @Path("/{mailboxId}")
@ApiOperation(value = "Re-indexes all the mails in a mailbox")
@ApiImplicitParams({
@ApiImplicitParam(
@@ -185,7 +163,7 @@ public class ReindexingRoutes implements Routes {
}
@POST
- @Path("/mailboxes/{mailboxId}/mails/{uid}")
+ @Path("/{mailboxId}/mails/{uid}")
@ApiOperation(value = "Re-indexes a single email")
@ApiImplicitParams({
@ApiImplicitParam(
@@ -244,7 +222,7 @@ public class ReindexingRoutes implements Routes {
private User extractUser(Request request) {
try {
- return User.fromUsername(request.params(USER_PARAM));
+ return User.fromUsername(request.queryParams(USER_QUERY_PARAM));
} catch (Exception e) {
throw ErrorResponder.builder()
.statusCode(HttpStatus.BAD_REQUEST_400)
http://git-wip-us.apache.org/repos/asf/james-project/blob/985b9a4a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
index 38d0205..86c2b52 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
@@ -121,7 +121,7 @@ class ReindexingRoutesTest {
@Test
void fullReprocessingShouldFailWithNoTask() {
when()
- .post("/mailboxIndex")
+ .post("/mailboxes")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -132,7 +132,7 @@ class ReindexingRoutesTest {
@Test
void fullReprocessingShouldFailWithBadTask() {
when()
- .post("/mailboxIndex?task=bad")
+ .post("/mailboxes?task=bad")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -146,7 +146,7 @@ class ReindexingRoutesTest {
@Test
void fullReprocessingShouldNotFailWhenNoMail() {
String taskId = with()
- .post("/mailboxIndex?task=reIndex")
+ .post("/mailboxes?task=reIndex")
.jsonPath()
.get("taskId");
@@ -175,7 +175,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = with()
- .post("/mailboxIndex?task=reIndex")
+ .post("/mailboxes?task=reIndex")
.jsonPath()
.get("taskId");
@@ -207,7 +207,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = with()
- .post("/mailboxIndex?task=reIndex")
+ .post("/mailboxes?task=reIndex")
.jsonPath()
.get("taskId");
@@ -240,8 +240,10 @@ class ReindexingRoutesTest {
class Validation {
@Test
void userReprocessingShouldFailWithNoTask() {
- when()
- .post("/mailboxIndex/users/" + USERNAME)
+ given()
+ .queryParam("user", USERNAME)
+ .when()
+ .post("/mailboxes")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -251,8 +253,11 @@ class ReindexingRoutesTest {
@Test
void userReprocessingShouldFailWithBadTask() {
- when()
- .post("/mailboxIndex/users/" + USERNAME + "?task=bad")
+ given()
+ .queryParam("user", USERNAME)
+ .queryParam("task", "bad")
+ .when()
+ .post("/mailboxes")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -262,8 +267,11 @@ class ReindexingRoutesTest {
@Test
void userReprocessingShouldFailWithBadUser() {
- when()
- .post("/mailboxIndex/users/bad@bad@bad?task=reIndex")
+ given()
+ .queryParam("user", "bad@bad@bad")
+ .queryParam("task", "reIndex")
+ .when()
+ .post("/mailboxes")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -276,8 +284,11 @@ class ReindexingRoutesTest {
class TaskDetails {
@Test
void userReprocessingShouldNotFailWhenNoMail() {
- String taskId = with()
- .post("/mailboxIndex/users/" + USERNAME + "?task=reIndex")
+ String taskId = given()
+ .queryParam("user", USERNAME)
+ .queryParam("task", "reIndex")
+ .when()
+ .post("/mailboxes")
.jsonPath()
.get("taskId");
@@ -306,8 +317,11 @@ class ReindexingRoutesTest {
MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
systemSession);
- String taskId = with()
- .post("/mailboxIndex/users/" + USERNAME + "?task=reIndex")
+ String taskId = given()
+ .queryParam("user", USERNAME)
+ .queryParam("task", "reIndex")
+ .when()
+ .post("/mailboxes")
.jsonPath()
.get("taskId");
@@ -339,8 +353,11 @@ class ReindexingRoutesTest {
MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
systemSession);
- String taskId = with()
- .post("/mailboxIndex/users/" + USERNAME + "?task=reIndex")
+ String taskId = given()
+ .queryParam("user", USERNAME)
+ .queryParam("task", "reIndex")
+ .when()
+ .post("/mailboxes")
.jsonPath()
.get("taskId");
@@ -378,7 +395,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize())
+ .post("/mailboxes/" + mailboxId.serialize())
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -392,7 +409,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "?task=bad")
+ .post("/mailboxes/" + mailboxId.serialize() + "?task=bad")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -403,7 +420,7 @@ class ReindexingRoutesTest {
@Test
void mailboxReprocessingShouldFailWithBadMailboxId() {
when()
- .post("/mailboxIndex/mailboxes/bad?task=reIndex")
+ .post("/mailboxes/bad?task=reIndex")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -414,7 +431,7 @@ class ReindexingRoutesTest {
@Test
void mailboxReprocessingShouldFailWithNonExistentMailboxId() {
when()
- .post("/mailboxIndex/mailboxes/36?task=reIndex")
+ .post("/mailboxes/36?task=reIndex")
.then()
.statusCode(HttpStatus.NOT_FOUND_404)
.body("statusCode", is(404))
@@ -431,7 +448,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
+ .post("/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -461,7 +478,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
+ .post("/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -494,7 +511,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
+ .post("/mailboxes/" + mailboxId.serialize() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -532,7 +549,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "/mails/7")
+ .post("/mailboxes/" + mailboxId.serialize() + "/mails/7")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -546,7 +563,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "/mails/7?task=bad")
+ .post("/mailboxes/" + mailboxId.serialize() + "/mails/7?task=bad")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -557,7 +574,7 @@ class ReindexingRoutesTest {
@Test
void messageReprocessingShouldFailWithBadMailboxId() {
when()
- .post("/mailboxIndex/mailboxes/bad/mails/7?task=reIndex")
+ .post("/mailboxes/bad/mails/7?task=reIndex")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -568,7 +585,7 @@ class ReindexingRoutesTest {
@Test
void messageReprocessingShouldFailWithNonExistentMailboxId() {
when()
- .post("/mailboxIndex/mailboxes/36/mails/7?task=reIndex")
+ .post("/mailboxes/36/mails/7?task=reIndex")
.then()
.statusCode(HttpStatus.NOT_FOUND_404)
.body("statusCode", is(404))
@@ -579,7 +596,7 @@ class ReindexingRoutesTest {
@Test
void messageReprocessingShouldFailWithBadUid() {
when()
- .post("/mailboxIndex/mailboxes/36/mails/bad?task=reIndex")
+ .post("/mailboxes/36/mails/bad?task=reIndex")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -596,7 +613,7 @@ class ReindexingRoutesTest {
MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "/mails/1?task=reIndex")
+ .post("/mailboxes/" + mailboxId.serialize() + "/mails/1?task=reIndex")
.jsonPath()
.get("taskId");
@@ -625,7 +642,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "/mails/"
+ .post("/mailboxes/" + mailboxId.serialize() + "/mails/"
+ composedMessageId.getUid().asLong() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -658,7 +675,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/mailboxes/" + mailboxId.serialize() + "/mails/"
+ .post("/mailboxes/" + mailboxId.serialize() + "/mails/"
+ createdMessage.getUid().asLong() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -691,7 +708,7 @@ class ReindexingRoutesTest {
@Test
void messageIdReprocessingShouldFailWithNoTask() {
when()
- .post("/mailboxIndex/messages/7")
+ .post("/messages/7")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -702,7 +719,7 @@ class ReindexingRoutesTest {
@Test
void messageIdReprocessingShouldFailWithBadTask() {
when()
- .post("/mailboxIndex/messages/7?task=bad")
+ .post("/messages/7?task=bad")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -713,7 +730,7 @@ class ReindexingRoutesTest {
@Test
void messageIdReprocessingShouldFailWithBadMessageId() {
when()
- .post("/mailboxIndex/messages/bad?task=reIndex")
+ .post("/messages/bad?task=reIndex")
.then()
.statusCode(HttpStatus.BAD_REQUEST_400)
.body("statusCode", is(400))
@@ -727,7 +744,7 @@ class ReindexingRoutesTest {
@Test
void messageIdReprocessingShouldNotFailWhenUidNotFound() {
String taskId = when()
- .post("/mailboxIndex/messages/1?task=reIndex")
+ .post("/messages/1?task=reIndex")
.jsonPath()
.get("taskId");
@@ -755,7 +772,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/messages/" + composedMessageId.getMessageId().serialize() + "?task=reIndex")
+ .post("/messages/" + composedMessageId.getMessageId().serialize() + "?task=reIndex")
.jsonPath()
.get("taskId");
@@ -786,7 +803,7 @@ class ReindexingRoutesTest {
systemSession);
String taskId = when()
- .post("/mailboxIndex/messages/" + composedMessageId.getMessageId().serialize() + "?task=reIndex")
+ .post("/messages/" + composedMessageId.getMessageId().serialize() + "?task=reIndex")
.jsonPath()
.get("taskId");
http://git-wip-us.apache.org/repos/asf/james-project/blob/985b9a4a/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 e1547f9..2ba0255 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -2117,7 +2117,7 @@ concurrent changes done during the reIndexing might be ignored.
### ReIndexing all mails
```
-curl -XPOST http://ip:port/mailboxIndex?task=reIndex
+curl -XPOST http://ip:port/mailboxes?task=reIndex
```
Will schedule a task for reIndexing all the mails stored on this James server.
@@ -2160,10 +2160,10 @@ concurrent changes done during the reIndexing might be ignored.
### ReIndexing a user mails
```
-curl -XPOST http://ip:port/mailboxIndex/users/bob@domain.com?task=reIndex
+curl -XPOST http://ip:port/mailboxes?task=reIndex,user=bob%40domain.com
```
-Will schedule a task for reIndexing all the mails in "bob@domain.com" mailboxes.
+Will schedule a task for reIndexing all the mails in "bob@domain.com" mailboxes (encoded above).
The response to that request will be the scheduled `taskId` :
@@ -2204,7 +2204,7 @@ concurrent changes done during the reIndexing might be ignored.
### ReIndexing a mailbox mails
```
-curl -XPOST http://ip:port/mailboxIndex/mailboxes/{mailboxId}?task=reIndex
+curl -XPOST http://ip:port/mailboxes/{mailboxId}?task=reIndex
```
Will schedule a task for reIndexing all the mails in one mailbox.
@@ -2234,7 +2234,7 @@ The scheduled task will have the following type `mailboxReIndexing` and the foll
```
{
- "mailboxPath":"#private:bob@domain.com:INBOX",
+ "mailboxId":"{mailboxId}",
"successfullyReprocessMailCount":18,
"failedReprocessedMailCount": 1
}
@@ -2250,7 +2250,7 @@ concurrent changes done during the reIndexing might be ignored.
### ReIndexing a single mail
```
-curl -XPOST http://ip:port/mailboxIndex/mailboxes/{mailboxId}/uid/36?task=reIndex
+curl -XPOST http://ip:port/mailboxes/{mailboxId}/uid/36?task=reIndex
```
Will schedule a task for reIndexing a single email.
@@ -2280,7 +2280,7 @@ The scheduled task will have the following type `messageReIndexing` and the foll
```
{
- "mailboxPath":"#private:bob@domain.com:INBOX",
+ "mailboxId":"{mailboxId}",
"uid":18
}
```
@@ -2292,7 +2292,7 @@ Warning: Canceling this task should be considered unsafe as it will leave the cu
### ReIndexing a single mail by messageId
```
-curl -XPOST http://ip:port/mailboxIndex/messages/{messageId}?task=reIndex
+curl -XPOST http://ip:port/messages/{messageId}?task=reIndex
```
Will schedule a task for reIndexing a single email in all the mailboxes containing it.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/14] james-project git commit: MAILBOX-355
PropagateLookupRightListener should retrieve MailboxPath rather than read it
from the event
Posted by bt...@apache.org.
MAILBOX-355 PropagateLookupRightListener should retrieve MailboxPath rather than read
it from the event
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/16e4d9f9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/16e4d9f9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/16e4d9f9
Branch: refs/heads/master
Commit: 16e4d9f93d411cebbf4f39d8420f379e357b692c
Parents: a788cf3
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 14:32:48 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
.../event/PropagateLookupRightListener.java | 51 +++++++++++---------
.../event/PropagateLookupRightListenerTest.java | 2 +-
2 files changed, 28 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/16e4d9f9/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
index 7767a94..88b4b48 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.RightManager;
import org.apache.james.mailbox.acl.ACLDiff;
@@ -40,10 +41,12 @@ public class PropagateLookupRightListener implements MailboxListener {
private static final Logger LOGGER = LoggerFactory.getLogger(PropagateLookupRightListener.class);
private final RightManager rightManager;
+ private final MailboxManager mailboxManager;
@Inject
- public PropagateLookupRightListener(RightManager rightManager) {
+ PropagateLookupRightListener(RightManager rightManager, MailboxManager mailboxManager) {
this.rightManager = rightManager;
+ this.mailboxManager = mailboxManager;
}
@Override
@@ -53,36 +56,36 @@ public class PropagateLookupRightListener implements MailboxListener {
@Override
public void event(Event event) {
- MailboxSession mailboxSession = event.getSession();
-
- if (event instanceof MailboxACLUpdated) {
- MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event;
+ try {
+ MailboxSession mailboxSession = event.getSession();
- updateLookupRightOnParent(mailboxSession, aclUpdateEvent.getMailboxPath(), aclUpdateEvent.getAclDiff());
- } else if (event instanceof MailboxRenamed) {
- MailboxRenamed renamedEvent = (MailboxRenamed) event;
- updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath());
- }
- }
+ if (event instanceof MailboxACLUpdated) {
+ MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event;
+ MailboxPath mailboxPath = mailboxManager.getMailbox(aclUpdateEvent.getMailboxId(), mailboxSession).getMailboxPath();
- private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) {
- try {
- MailboxACL acl = rightManager.listRights(path, session);
- listAncestors(session, path)
- .forEach(parentMailboxPath ->
- updateLookupRight(
- session,
- parentMailboxPath,
- acl.getEntries()
- .entrySet()
- .stream()
- .map(entry -> new Entry(entry.getKey(), entry.getValue()))
- ));
+ updateLookupRightOnParent(mailboxSession, mailboxPath, aclUpdateEvent.getAclDiff());
+ } else if (event instanceof MailboxRenamed) {
+ MailboxRenamed renamedEvent = (MailboxRenamed) event;
+ updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath());
+ }
} catch (MailboxException e) {
throw new RuntimeException(e);
}
}
+ private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) throws MailboxException {
+ MailboxACL acl = rightManager.listRights(path, session);
+ listAncestors(session, path)
+ .forEach(parentMailboxPath ->
+ updateLookupRight(
+ session,
+ parentMailboxPath,
+ acl.getEntries()
+ .entrySet()
+ .stream()
+ .map(entry -> new Entry(entry.getKey(), entry.getValue()))));
+ }
+
private void updateLookupRightOnParent(MailboxSession mailboxSession, MailboxPath mailboxPath, ACLDiff aclDiff) {
listAncestors(mailboxSession, mailboxPath)
.forEach(path ->
http://git-wip-us.apache.org/repos/asf/james-project/blob/16e4d9f9/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
index d89f1bc..2bfdcde 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
@@ -80,7 +80,7 @@ public class PropagateLookupRightListenerTest {
storeRightManager = resources.getStoreRightManager();
mailboxMapper = storeMailboxManager.getMapperFactory();
- testee = new PropagateLookupRightListener(storeRightManager);
+ testee = new PropagateLookupRightListener(storeRightManager, storeMailboxManager);
storeMailboxManager.addGlobalListener(testee, mailboxSession);
parentMailboxId = storeMailboxManager.createMailbox(PARENT_MAILBOX, mailboxSession).get();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/14] james-project git commit: MAILBOX-355 SpamAssassinListener
should use SystemMailboxProvider
Posted by bt...@apache.org.
MAILBOX-355 SpamAssassinListener should use SystemMailboxProvider
This allow a centralized knowledge of what is a system mailbox - the fact that role
is name encoded should not leak out of SystemMailboxProvider
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a788cf3b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a788cf3b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a788cf3b
Branch: refs/heads/master
Commit: a788cf3b3b0c7bde7113494094d3997afae3e75f
Parents: 3412083
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 14:27:35 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
mailbox/plugin/spamassassin/pom.xml | 12 +++++++
.../spamassassin/SpamAssassinListener.java | 36 ++++++++++----------
.../spamassassin/SpamAssassinListenerTest.java | 20 +++++++----
server/container/guice/mailbox/pom.xml | 4 ---
.../org/apache/james/modules/MailboxModule.java | 6 ++++
.../java/org/apache/james/jmap/JMAPModule.java | 4 ---
6 files changed, 49 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/mailbox/plugin/spamassassin/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/pom.xml b/mailbox/plugin/spamassassin/pom.xml
index c644ada..6ea92f4 100644
--- a/mailbox/plugin/spamassassin/pom.xml
+++ b/mailbox/plugin/spamassassin/pom.xml
@@ -39,6 +39,12 @@
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
@@ -53,6 +59,12 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>apache-james-spamassassin</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
index 3f3f73a..04fd6c8 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
@@ -25,10 +25,9 @@ import javax.inject.Inject;
import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.event.EventFactory;
import org.apache.james.mailbox.store.event.MessageMoveEvent;
import org.apache.james.mailbox.store.event.SpamEventListener;
@@ -47,13 +46,13 @@ public class SpamAssassinListener implements SpamEventListener {
private static final Logger LOGGER = LoggerFactory.getLogger(SpamAssassinListener.class);
private final SpamAssassin spamAssassin;
- private final MailboxSessionMapperFactory mapperFactory;
+ private final SystemMailboxesProvider systemMailboxesProvider;
private final ExecutionMode executionMode;
@Inject
- public SpamAssassinListener(SpamAssassin spamAssassin, MailboxSessionMapperFactory mapperFactory, ExecutionMode executionMode) {
+ SpamAssassinListener(SpamAssassin spamAssassin, SystemMailboxesProvider systemMailboxesProvider, ExecutionMode executionMode) {
this.spamAssassin = spamAssassin;
- this.mapperFactory = mapperFactory;
+ this.systemMailboxesProvider = systemMailboxesProvider;
this.executionMode = executionMode;
}
@@ -83,7 +82,7 @@ public class SpamAssassinListener implements SpamEventListener {
}
if (event instanceof EventFactory.AddedImpl) {
EventFactory.AddedImpl addedEvent = (EventFactory.AddedImpl) event;
- if (addedEvent.getMailboxPath().isInbox()) {
+ if (isAppendedToInbox(addedEvent)) {
List<InputStream> contents = addedEvent.getAvailableMessages()
.values()
.stream()
@@ -94,6 +93,16 @@ public class SpamAssassinListener implements SpamEventListener {
}
}
+ private boolean isAppendedToInbox(EventFactory.AddedImpl addedEvent) {
+ try {
+ return systemMailboxesProvider.findMailbox(Role.INBOX, addedEvent.getSession())
+ .getId().equals(addedEvent.getMailboxId());
+ } catch (MailboxException e) {
+ LOGGER.warn("Could not resolve Inbox mailbox", e);
+ return false;
+ }
+ }
+
public ImmutableList<InputStream> retrieveMessages(MessageMoveEvent messageMoveEvent) {
return messageMoveEvent.getMessages()
.values()
@@ -105,7 +114,7 @@ public class SpamAssassinListener implements SpamEventListener {
@VisibleForTesting
boolean isMessageMovedToSpamMailbox(MessageMoveEvent event) {
try {
- MailboxId spamMailboxId = getMailboxId(event, Role.SPAM);
+ MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getSession()).getId();
return event.getMessageMoves().addedMailboxIds().contains(spamMailboxId);
} catch (MailboxException e) {
@@ -117,8 +126,8 @@ public class SpamAssassinListener implements SpamEventListener {
@VisibleForTesting
boolean isMessageMovedOutOfSpamMailbox(MessageMoveEvent event) {
try {
- MailboxId spamMailboxId = getMailboxId(event, Role.SPAM);
- MailboxId trashMailboxId = getMailboxId(event, Role.TRASH);
+ MailboxId spamMailboxId = systemMailboxesProvider.findMailbox(Role.SPAM, event.getSession()).getId();
+ MailboxId trashMailboxId = systemMailboxesProvider.findMailbox(Role.TRASH, event.getSession()).getId();
return event.getMessageMoves().removedMailboxIds().contains(spamMailboxId)
&& !event.getMessageMoves().addedMailboxIds().contains(trashMailboxId);
@@ -127,13 +136,4 @@ public class SpamAssassinListener implements SpamEventListener {
return false;
}
}
-
- private MailboxId getMailboxId(MessageMoveEvent event, Role role) throws MailboxException {
- String userName = event.getSession().getUser().getUserName();
- MailboxPath mailboxPath = MailboxPath.forUser(userName, role.getDefaultMailbox());
-
- return mapperFactory.getMailboxMapper(event.getSession())
- .findMailboxByPath(mailboxPath)
- .getMailboxId();
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 3426ecf..37d0162 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -33,14 +33,18 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.james.mailbox.DefaultMailboxes;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageMoves;
import org.apache.james.mailbox.model.TestMessageId;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.SimpleMessageMetaData;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.mailbox.store.event.EventFactory;
import org.apache.james.mailbox.store.event.EventFactory.AddedImpl;
import org.apache.james.mailbox.store.event.MessageMoveEvent;
@@ -57,10 +61,9 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
public class SpamAssassinListenerTest {
-
public static final String USER = "user";
- public static final MockMailboxSession MAILBOX_SESSION = new MockMailboxSession(USER);
- public static final int UID_VALIDITY = 43;
+ private static final MockMailboxSession MAILBOX_SESSION = new MockMailboxSession(USER);
+ private static final int UID_VALIDITY = 43;
private SpamAssassin spamAssassin;
private SpamAssassinListener listener;
private SimpleMailbox inbox;
@@ -74,9 +77,12 @@ public class SpamAssassinListenerTest {
private MailboxMapper mailboxMapper;
@Before
- public void setup() throws MailboxException {
+ public void setup() throws Exception {
+ StoreMailboxManager mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver());
+ SystemMailboxesProviderImpl systemMailboxesProvider = new SystemMailboxesProviderImpl(mailboxManager);
+
spamAssassin = mock(SpamAssassin.class);
- InMemoryMailboxSessionMapperFactory mapperFactory = new InMemoryMailboxSessionMapperFactory();
+ MailboxSessionMapperFactory mapperFactory = mailboxManager.getMapperFactory();
mailboxMapper = mapperFactory.getMailboxMapper(MAILBOX_SESSION);
inbox = new SimpleMailbox(MailboxPath.forUser(USER, DefaultMailboxes.INBOX), UID_VALIDITY);
inboxId = mailboxMapper.save(inbox);
@@ -87,7 +93,7 @@ public class SpamAssassinListenerTest {
spamCapitalMailboxId = mailboxMapper.save(new SimpleMailbox(MailboxPath.forUser(USER, "SPAM"), UID_VALIDITY));
trashMailboxId = mailboxMapper.save(new SimpleMailbox(MailboxPath.forUser(USER, "Trash"), UID_VALIDITY));
- listener = new SpamAssassinListener(spamAssassin, mapperFactory, MailboxListener.ExecutionMode.SYNCHRONOUS);
+ listener = new SpamAssassinListener(spamAssassin, systemMailboxesProvider, MailboxListener.ExecutionMode.SYNCHRONOUS);
}
@After
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/server/container/guice/mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/pom.xml b/server/container/guice/mailbox/pom.xml
index bade4e0..51053c1 100644
--- a/server/container/guice/mailbox/pom.xml
+++ b/server/container/guice/mailbox/pom.xml
@@ -38,10 +38,6 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
- <artifactId>apache-james-mailbox-store</artifactId>
- </dependency>
- <dependency>
- <groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-configuration</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
index 674fa56..f95e235 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
@@ -18,10 +18,12 @@
****************************************************************/
package org.apache.james.modules;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.utils.GuiceProbe;
import com.google.inject.AbstractModule;
@@ -42,6 +44,10 @@ public class MailboxModule extends AbstractModule {
bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
bind(SimpleGroupMembershipResolver.class).in(Scopes.SINGLETON);
bind(GroupMembershipResolver.class).to(SimpleGroupMembershipResolver.class);
+
+
+ bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
+ bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a788cf3b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
index c15bf7b..c35225b 100644
--- a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -41,8 +41,6 @@ import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
-import org.apache.james.mailbox.SystemMailboxesProvider;
-import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.modules.server.CamelMailetContainerModule;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.server.core.configuration.FileConfigurationProvider;
@@ -94,7 +92,6 @@ public class JMAPModule extends AbstractModule {
bind(RequestHandler.class).in(Scopes.SINGLETON);
bind(UploadHandler.class).in(Scopes.SINGLETON);
bind(JsoupHtmlTextExtractor.class).in(Scopes.SINGLETON);
- bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
bind(HtmlTextExtractor.class).to(JsoupHtmlTextExtractor.class);
Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(RequiredCapabilitiesPrecondition.class);
@@ -103,7 +100,6 @@ public class JMAPModule extends AbstractModule {
transportProcessorChecks.addBinding().toInstance(VACATION_MAILET_CHECK);
transportProcessorChecks.addBinding().toInstance(FILTERING_MAILET_CHECK);
- bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
bind(MailQueueItemDecoratorFactory.class).to(PostDequeueDecoratorFactory.class).in(Scopes.SINGLETON);
Multibinder.newSetBinder(binder(), MailboxListener.class).addBinding().to(PropagateLookupRightListener.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/14] james-project git commit: MAILBOX-355 SetMessagesMethodTest
should rely on MailboxId
Posted by bt...@apache.org.
MAILBOX-355 SetMessagesMethodTest should rely on MailboxId
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/387861af
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/387861af
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/387861af
Branch: refs/heads/master
Commit: 387861af615b87885eadd710b978d11aa6f160f4
Parents: e877c0b
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 14:35:58 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:24 2018 +0700
----------------------------------------------------------------------
.../james/jmap/methods/integration/SetMessagesMethodTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/387861af/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index a4c3b70..ff955e3 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -2334,15 +2334,15 @@ public abstract class SetMessagesMethodTest {
calmlyAwait.atMost(5, TimeUnit.SECONDS).until(() -> events.stream()
- .anyMatch(event -> isAddedToOutboxEvent(messageId, event)));
+ .anyMatch(event -> isAddedToOutboxEvent(messageId, event, outboxId)));
}
- private boolean isAddedToOutboxEvent(String messageId, Event event) {
+ private boolean isAddedToOutboxEvent(String messageId, Event event, String outboxId) {
if (!(event instanceof EventFactory.AddedImpl)) {
return false;
}
EventFactory.AddedImpl added = (EventFactory.AddedImpl) event;
- return added.getMailboxPath().equals(MailboxPath.forUser(USERNAME, DefaultMailboxes.OUTBOX))
+ return added.getMailboxId().serialize().equals(outboxId)
&& added.getUids().size() == 1
&& added.getMetaData(added.getUids().get(0)).getMessageId().serialize().equals(messageId);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/14] james-project git commit: JAMES-2596 Add listSources API to
RecipientRewriteTable
Posted by bt...@apache.org.
JAMES-2596 Add listSources API to RecipientRewriteTable
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4c0b4515
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4c0b4515
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4c0b4515
Branch: refs/heads/master
Commit: 4c0b45157d224c32c7381866fc610498f4477cd5
Parents: d78ea34
Author: datph <dp...@linagora.com>
Authored: Fri Nov 16 17:56:35 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:33:18 2018 +0700
----------------------------------------------------------------------
.../james/rrt/api/RecipientRewriteTable.java | 3 +++
.../rrt/lib/AbstractRecipientRewriteTable.java | 9 ++++++-
.../user/lib/AbstractJamesUsersRepository.java | 8 ++++++
.../lib/AbstractRecipientRewriteTableTest.java | 28 ++++++++++++++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c0b4515/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index 7e3ed27..0b21317 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.rrt.api;
+import java.util.List;
import java.util.Map;
import org.apache.james.core.Domain;
@@ -106,6 +107,8 @@ public interface RecipientRewriteTable {
*/
Map<MappingSource, Mappings> getAllMappings() throws RecipientRewriteTableException;
+ List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException;
+
class ErrorMappingException extends Exception {
private static final long serialVersionUID = 2348752938798L;
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c0b4515/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
index 7eefdcc..fca0778 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.rrt.lib;
+import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Pattern;
@@ -96,7 +97,8 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
@Override
public Mappings getMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
- return getMappings(User.fromLocalPartWithDomain(user, domain), mappingLimit);
+ Mappings mappings = getMappings(User.fromLocalPartWithDomain(user, domain), mappingLimit);
+ return mappings;
}
private Mappings getMappings(User user, int mappingLimit) throws ErrorMappingException, RecipientRewriteTableException {
@@ -297,6 +299,11 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
removeMapping(source, mapping);
}
+ @Override
+ public List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
+ return null;
+ }
+
/**
* Return a Map which holds all Mappings
*
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c0b4515/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
index 491accb..811fb0c 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
@@ -21,6 +21,7 @@ package org.apache.james.user.lib;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.commons.configuration.ConfigurationException;
@@ -42,6 +43,8 @@ import org.apache.james.user.lib.model.DefaultJamesUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.ImmutableList;
+
/**
* A partial implementation of a Repository to store users.
* <p>
@@ -288,4 +291,9 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
public void removeGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException {
throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable");
}
+
+ @Override
+ public List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
+ return ImmutableList.of();
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c0b4515/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
index 17bb88e..abf05bb 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
@@ -354,4 +354,32 @@ public abstract class AbstractRecipientRewriteTableTest {
assertThat(virtualUserTable.getMappings(user, domain))
.isEqualTo(MappingsImpl.empty());
}
+
+ @Test
+ public void listSourcesShouldReturnWhenHasMapping() throws RecipientRewriteTableException {
+ String user = "test";
+ Domain domain = Domain.LOCALHOST;
+ String address = "test@localhost2";
+ MappingSource source = MappingSource.fromUser(user, domain);
+ Mapping mapping = Mapping.group(address);
+ virtualUserTable.addMapping(source, mapping);
+
+ assertThat(virtualUserTable.listSources(mapping)).contains(source);
+ }
+
+ @Test
+ public void listSourceShouldReturnWhenMultipleSourceMapping() throws RecipientRewriteTableException {
+ String user = "test";
+ Domain domain = Domain.of("james");
+ String address = "test@localhost2";
+
+ MappingSource source = MappingSource.fromUser(user, domain);
+ MappingSource source2 = MappingSource.fromDomain(Domain.LOCALHOST);
+ Mapping mapping = Mapping.group(address);
+
+ virtualUserTable.addMapping(source, mapping);
+ virtualUserTable.addMapping(source2, mapping);
+
+ assertThat(virtualUserTable.listSources(mapping)).contains(source, source2);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/14] james-project git commit: MAILBOX-355
MailboxOperationLoggingListener should rely on MailboxId
Posted by bt...@apache.org.
MAILBOX-355 MailboxOperationLoggingListener should rely on MailboxId
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6fe88912
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6fe88912
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6fe88912
Branch: refs/heads/master
Commit: 6fe88912201a2c0d9026f4c2a0dec26822572bb6
Parents: 577d661
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:02:22 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
.../cassandra/MailboxOperationLoggingListener.java | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6fe88912/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java
index f6bdfb8..8d8ae40 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java
@@ -19,6 +19,7 @@
package org.apache.james.mailbox.cassandra;
+import static org.apache.james.mailbox.cassandra.GhostMailbox.MAILBOX_ID;
import static org.apache.james.mailbox.cassandra.GhostMailbox.MAILBOX_NAME;
import static org.apache.james.mailbox.cassandra.GhostMailbox.TYPE;
@@ -44,25 +45,22 @@ public class MailboxOperationLoggingListener implements MailboxListener {
if (event instanceof MailboxRenamed) {
MailboxRenamed mailboxRenamed = (MailboxRenamed) event;
GhostMailbox.logger()
+ .addField(MAILBOX_ID, mailboxRenamed.getMailboxId())
.addField(MAILBOX_NAME, mailboxRenamed.getNewPath())
.addField(TYPE, ADDED)
.log(logger -> logger.info("Mailbox renamed event"));
- GhostMailbox.logger()
- .addField(MAILBOX_NAME, mailboxRenamed.getMailboxPath())
- .addField(TYPE, REMOVED)
- .log(logger -> logger.info("Mailbox renamed event"));
}
if (event instanceof MailboxDeletion) {
MailboxDeletion mailboxDeletion = (MailboxDeletion) event;
GhostMailbox.logger()
- .addField(MAILBOX_NAME, mailboxDeletion.getMailboxPath())
+ .addField(MAILBOX_ID, mailboxDeletion.getMailboxId())
.addField(TYPE, REMOVED)
.log(logger -> logger.info("Mailbox deleted event"));
}
if (event instanceof MailboxAdded) {
MailboxAdded mailboxAdded = (MailboxAdded) event;
GhostMailbox.logger()
- .addField(MAILBOX_NAME, mailboxAdded.getMailboxPath())
+ .addField(MAILBOX_ID, mailboxAdded.getMailboxId())
.addField(TYPE, ADDED)
.log(logger -> logger.info("Mailbox added event"));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/14] james-project git commit: MAILBOX-355 MailboxManagertest
should assert MailboxId carried in events
Posted by bt...@apache.org.
MAILBOX-355 MailboxManagertest should assert MailboxId carried in events
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/577d661f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/577d661f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/577d661f
Branch: refs/heads/master
Commit: 577d661f351ada8be0f516989ee5f4346d96e430
Parents: 387861a
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:37:03 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:24 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/MailboxManagerTest.java | 25 ++++++++++----------
1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/577d661f/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 59593cb..6a22dab 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -364,6 +364,7 @@ public abstract class MailboxManagerTest {
private final QuotaRoot quotaRoot = QuotaRoot.quotaRoot("#private&USER_1", Optional.empty());
private EventCollector listener;
private MailboxPath inbox;
+ private MailboxId inboxId;
private MessageManager inboxManager;
private MailboxPath newPath;
@@ -374,7 +375,7 @@ public abstract class MailboxManagerTest {
newPath = MailboxPath.forUser(USER_1, "specialMailbox");
listener = new EventCollector();
- mailboxManager.createMailbox(inbox, session);
+ inboxId = mailboxManager.createMailbox(inbox, session).get();
inboxManager = mailboxManager.getMailbox(inbox, session);
}
@@ -390,7 +391,7 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.MailboxDeletion) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(inbox))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(inboxId))
.satisfies(event -> assertThat(event.getQuotaRoot()).isEqualTo(quotaRoot))
.satisfies(event -> assertThat(event.getDeletedMessageCount()).isEqualTo(QuotaCount.count(0)))
.satisfies(event -> assertThat(event.getTotalDeletedSize()).isEqualTo(QuotaSize.size(0)));
@@ -401,14 +402,14 @@ public abstract class MailboxManagerTest {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Quota));
mailboxManager.addGlobalListener(listener, session);
- mailboxManager.createMailbox(newPath, session);
+ Optional<MailboxId> newId = mailboxManager.createMailbox(newPath, session);
assertThat(listener.getEvents())
.filteredOn(event -> event instanceof MailboxListener.MailboxAdded)
.hasSize(1)
.extracting(event -> (MailboxListener.MailboxAdded) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(newPath));
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(newId.get()));
}
@Test
@@ -446,7 +447,7 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.Added) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(inbox))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(inboxId))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
@@ -463,7 +464,7 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.Expunged) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(inbox))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(inboxId))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
@@ -479,14 +480,14 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.FlagsUpdated) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(inbox))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(inboxId))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
@Test
void moveShouldFireAddedEventInTargetMailbox() throws Exception {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Move));
- mailboxManager.createMailbox(newPath, session);
+ Optional<MailboxId> targetMailboxId = mailboxManager.createMailbox(newPath, session);
inboxManager.appendMessage(AppendCommand.builder().build(message), session);
mailboxManager.addGlobalListener(listener, session);
@@ -497,7 +498,7 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.Added) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(newPath))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(targetMailboxId.get()))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
@@ -515,13 +516,13 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.Expunged) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(inbox))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(inboxId))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
@Test
void copyShouldFireAddedEventInTargetMailbox() throws Exception {
- mailboxManager.createMailbox(newPath, session);
+ Optional<MailboxId> targetMailboxId = mailboxManager.createMailbox(newPath, session);
inboxManager.appendMessage(AppendCommand.builder().build(message), session);
mailboxManager.addGlobalListener(listener, session);
@@ -532,7 +533,7 @@ public abstract class MailboxManagerTest {
.hasSize(1)
.extracting(event -> (MailboxListener.Added) event)
.element(0)
- .satisfies(event -> assertThat(event.getMailboxPath()).isEqualTo(newPath))
+ .satisfies(event -> assertThat(event.getMailboxId()).isEqualTo(targetMailboxId.get()))
.satisfies(event -> assertThat(event.getUids()).hasSize(1));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/14] james-project git commit: JAMES-2596 Implement default
behavior for listSources method
Posted by bt...@apache.org.
JAMES-2596 Implement default behavior for listSources method
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/80f655ce
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/80f655ce
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/80f655ce
Branch: refs/heads/master
Commit: 80f655cec2b24ee1ee7b9ee2c7f23fad6960afdd
Parents: 4c0b451
Author: datph <dp...@linagora.com>
Authored: Fri Nov 30 16:28:08 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:33:18 2018 +0700
----------------------------------------------------------------------
.../james/rrt/api/RecipientRewriteTable.java | 27 +++++++++++++++++++-
.../rrt/lib/AbstractRecipientRewriteTable.java | 9 +------
.../user/lib/AbstractJamesUsersRepository.java | 6 +----
3 files changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/80f655ce/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
index 0b21317..c21ba3a 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/api/RecipientRewriteTable.java
@@ -26,6 +26,8 @@ import org.apache.james.rrt.lib.Mapping;
import org.apache.james.rrt.lib.MappingSource;
import org.apache.james.rrt.lib.Mappings;
+import com.google.common.collect.ImmutableList;
+
/**
* Interface which should be implemented of classes which map recipients.
*/
@@ -107,7 +109,30 @@ public interface RecipientRewriteTable {
*/
Map<MappingSource, Mappings> getAllMappings() throws RecipientRewriteTableException;
- List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException;
+ default List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
+ if (!isSupportedListSources(mapping)) {
+ return ImmutableList.of();
+ }
+
+ return getAllMappings().entrySet().stream()
+ .filter(entry -> filterMapping(entry, mapping))
+ .map(Map.Entry::getKey)
+ .collect(ImmutableList.toImmutableList());
+ }
+
+ default boolean filterMapping(Map.Entry<MappingSource, Mappings> entry, Mapping mapping) {
+ return entry.getValue()
+ .asStream()
+ .anyMatch(map -> map.equals(mapping));
+ }
+
+ default boolean isSupportedListSources(Mapping mapping) {
+ return listSourcesSupportedType.stream()
+ .anyMatch(type -> type.equals(mapping.getType()));
+ }
+
+ List<Mapping.Type> listSourcesSupportedType = ImmutableList
+ .of(Mapping.Type.Group, Mapping.Type.Forward, Mapping.Type.Address);
class ErrorMappingException extends Exception {
http://git-wip-us.apache.org/repos/asf/james-project/blob/80f655ce/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
index fca0778..7eefdcc 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java
@@ -18,7 +18,6 @@
****************************************************************/
package org.apache.james.rrt.lib;
-import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Pattern;
@@ -97,8 +96,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
@Override
public Mappings getMappings(String user, Domain domain) throws ErrorMappingException, RecipientRewriteTableException {
- Mappings mappings = getMappings(User.fromLocalPartWithDomain(user, domain), mappingLimit);
- return mappings;
+ return getMappings(User.fromLocalPartWithDomain(user, domain), mappingLimit);
}
private Mappings getMappings(User user, int mappingLimit) throws ErrorMappingException, RecipientRewriteTableException {
@@ -299,11 +297,6 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
removeMapping(source, mapping);
}
- @Override
- public List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
- return null;
- }
-
/**
* Return a Map which holds all Mappings
*
http://git-wip-us.apache.org/repos/asf/james-project/blob/80f655ce/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
index 811fb0c..3b5d205 100644
--- a/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/user/lib/AbstractJamesUsersRepository.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -291,9 +292,4 @@ public abstract class AbstractJamesUsersRepository extends AbstractUsersReposito
public void removeGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException {
throw new RecipientRewriteTableException("Read-Only RecipientRewriteTable");
}
-
- @Override
- public List<MappingSource> listSources(Mapping mapping) throws RecipientRewriteTableException {
- return ImmutableList.of();
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/14] james-project git commit: MAILBOX-355 Delete Event
serialization
Posted by bt...@apache.org.
MAILBOX-355 Delete Event serialization
A new scala based version will be proposed.
Removing previous code makes subsequent changes easier.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e877c0b2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e877c0b2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e877c0b2
Branch: refs/heads/master
Commit: e877c0b2215e53c455c4f9f883c4369dd3770ad9
Parents: 9494a11
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:30:27 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:24 2018 +0700
----------------------------------------------------------------------
.../resources/META-INF/spring/event-system.xml | 4 -
.../store/json/JacksonEventSerializer.java | 227 ------------------
.../mailbox/store/json/JsonEventSerializer.java | 32 ---
.../store/json/event/EventConverter.java | 232 -------------------
.../json/event/EventNotValidException.java | 26 ---
.../store/json/event/MailboxConverter.java | 91 --------
.../json/event/dto/EventDataTransferObject.java | 203 ----------------
.../mailbox/store/json/event/dto/EventType.java | 32 ---
.../json/event/dto/FlagsDataTransferObject.java | 83 -------
.../event/dto/LocaleDataTransferObject.java | 49 ----
.../event/dto/MailboxDataTransferObject.java | 143 ------------
.../dto/MailboxPathDataTransferObject.java | 49 ----
.../dto/MailboxSessionDataTransferObject.java | 111 ---------
.../dto/MessageMetaDataDataTransferObject.java | 95 --------
.../dto/UpdatedFlagsDataTransferObject.java | 56 -----
.../mailbox/store/json/EventSerializerTest.java | 165 -------------
.../store/json/JsonEventSerializerTest.java | 37 ---
17 files changed, 1635 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
index 44eace7..2bdc06e 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
@@ -28,10 +28,6 @@
<constructor-arg index="1" ref="event-registry"/>
</bean>
- <bean id="event-converter" class="org.apache.james.mailbox.store.json.event.EventConverter" lazy-init="true">
- <constructor-arg index="0" ref="mailbox-converter"/>
- </bean>
-
<bean id="synchronous-event-delivery" class="org.apache.james.mailbox.store.event.SynchronousEventDelivery" lazy-init="true">
<constructor-arg index="0" ref="metricFactory"/>
</bean>
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
deleted file mode 100644
index 6710b58..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
+++ /dev/null
@@ -1,227 +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.json;
-
-import java.io.IOException;
-import java.util.Optional;
-
-import org.apache.james.core.Domain;
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageId.Factory;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.store.event.EventSerializer;
-import org.apache.james.mailbox.store.json.event.EventConverter;
-import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.ObjectCodec;
-import com.fasterxml.jackson.core.TreeNode;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.KeyDeserializer;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.databind.node.TextNode;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.github.fge.lambdas.Throwing;
-
-public class JacksonEventSerializer implements EventSerializer {
-
- private final EventConverter eventConverter;
- private final ObjectMapper objectMapper;
-
- public JacksonEventSerializer(EventConverter eventConverter, ObjectMapper objectMapper) {
- this.eventConverter = eventConverter;
- this.objectMapper = objectMapper;
- }
-
- @Override
- public byte[] serializeEvent(MailboxListener.MailboxEvent event) throws Exception {
- return objectMapper.writeValueAsBytes(eventConverter.convertToDataTransferObject(event));
- }
-
- @Override
- public MailboxListener.MailboxEvent deSerializeEvent(byte[] serializedEvent) throws Exception {
- EventDataTransferObject eventDataTransferObject = objectMapper.readValue(serializedEvent, EventDataTransferObject.class);
- return eventConverter.retrieveEvent(eventDataTransferObject);
- }
-
- public static ObjectMapper configureObjectMapper(ObjectMapper objectMapper, MessageId.Factory messageIdFactory) {
- SimpleModule module = new SimpleModule();
- module.addDeserializer(MessageUid.class, new MessageUidDeserializer());
- module.addKeyDeserializer(MessageUid.class, new MessageUidKeyDeserializer());
- module.addSerializer(MessageUid.class, new MessageUidSerializer());
- module.addKeySerializer(MessageUid.class, new MessageUidKeySerializer());
- module.addSerializer(MessageId.class, new MessageIdSerializer());
- module.addDeserializer(MessageId.class, new MessageIdDeserializer(messageIdFactory));
- module.addSerializer(QuotaRoot.class, new QuotaRootSerializer());
- module.addDeserializer(QuotaRoot.class, new QuotaRootDeserializer());
- module.addSerializer(QuotaCount.class, new QuotaCountSerializer());
- module.addDeserializer(QuotaCount.class, new QuotaCountDeserializer());
- module.addSerializer(QuotaSize.class, new QuotaSizeSerializer());
- module.addDeserializer(QuotaSize.class, new QuotaSizeDeserializer());
- objectMapper.registerModules(module, new Jdk8Module());
- return objectMapper;
- }
-
- public static class MessageUidDeserializer extends JsonDeserializer<MessageUid> {
-
- @Override
- public MessageUid deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
- return MessageUid.of(Long.parseLong(parser.getValueAsString()));
- }
-
- }
-
- public static class MessageUidSerializer extends JsonSerializer<MessageUid> {
-
- @Override
- public void serialize(MessageUid value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeString(String.valueOf(value.asLong()));
- }
-
- }
-
- public static class MessageUidKeyDeserializer extends KeyDeserializer {
-
- @Override
- public Object deserializeKey(String key, DeserializationContext context) throws IOException, JsonProcessingException {
- return MessageUid.of(Long.parseLong(key));
- }
-
- }
-
- public static class MessageUidKeySerializer extends JsonSerializer<MessageUid> {
-
- @Override
- public void serialize(MessageUid value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeFieldName(String.valueOf(value.asLong()));
- }
-
- }
-
- public static class MessageIdSerializer extends JsonSerializer<MessageId> {
-
- @Override
- public void serialize(MessageId value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeString(String.valueOf(value.serialize()));
- }
-
- }
-
- public static class MessageIdDeserializer extends JsonDeserializer<MessageId> {
- private final Factory factory;
-
- public MessageIdDeserializer(MessageId.Factory factory) {
- this.factory = factory;
- }
-
- @Override
- public MessageId deserialize(JsonParser p, DeserializationContext context) throws IOException, JsonProcessingException {
- return factory.fromString(p.getValueAsString());
- }
-
- }
-
- private static final String QUOTA_ROOT_VALUE_FIELD = "value";
- private static final String QUOTA_ROOT_DOMAIN_FIELD = "domain";
-
- public static class QuotaRootSerializer extends JsonSerializer<QuotaRoot> {
-
- @Override
- public void serialize(QuotaRoot value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeStartObject();
- generator.writeStringField(QUOTA_ROOT_VALUE_FIELD, value.getValue());
- value.getDomain()
- .ifPresent(Throwing.consumer(domain -> generator.writeStringField(QUOTA_ROOT_DOMAIN_FIELD, domain.asString())));
- generator.writeEndObject();
- }
-
- }
-
- public static class QuotaRootDeserializer extends JsonDeserializer<QuotaRoot> {
-
- @Override
- public QuotaRoot deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
- ObjectCodec codec = parser.getCodec();
- TreeNode node = codec.readTree(parser);
- return QuotaRoot.quotaRoot(value(node), domain(node));
- }
-
- private String value(TreeNode node) throws IOException, JsonParseException {
- TextNode value = (TextNode) node.get(QUOTA_ROOT_VALUE_FIELD);
- return value.asText();
- }
-
- private Optional<Domain> domain(TreeNode node) throws IOException, JsonParseException {
- TreeNode value = node.get(QUOTA_ROOT_DOMAIN_FIELD);
- if (value == null || value.isMissingNode()) {
- return Optional.empty();
- }
- return Optional.ofNullable(node.asToken().asString()).map(Domain::of);
- }
-
- }
-
- public static class QuotaCountSerializer extends JsonSerializer<QuotaCount> {
-
- @Override
- public void serialize(QuotaCount value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeNumber(value.asLong());
- }
-
- }
-
- public static class QuotaCountDeserializer extends JsonDeserializer<QuotaCount> {
-
- @Override
- public QuotaCount deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
- return QuotaCount.count(parser.getLongValue());
- }
-
- }
-
- public static class QuotaSizeSerializer extends JsonSerializer<QuotaSize> {
-
- @Override
- public void serialize(QuotaSize value, JsonGenerator generator, SerializerProvider serializers) throws IOException, JsonProcessingException {
- generator.writeNumber(value.asLong());
- }
-
- }
-
- public static class QuotaSizeDeserializer extends JsonDeserializer<QuotaSize> {
-
- @Override
- public QuotaSize deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
- return QuotaSize.size(parser.getLongValue());
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java
deleted file mode 100644
index 5ec4ff4..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java
+++ /dev/null
@@ -1,32 +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.json;
-
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.json.event.EventConverter;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class JsonEventSerializer extends JacksonEventSerializer {
-
- public JsonEventSerializer(EventConverter eventConverter, MessageId.Factory messageIdFactory) {
- super(eventConverter, configureObjectMapper(new ObjectMapper(), messageIdFactory));
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
deleted file mode 100644
index d92d077..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
+++ /dev/null
@@ -1,232 +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.json.event;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
-import org.apache.james.mailbox.store.json.event.dto.EventType;
-import org.apache.james.mailbox.store.json.event.dto.MailboxDataTransferObject;
-import org.apache.james.mailbox.store.json.event.dto.MailboxPathDataTransferObject;
-import org.apache.james.mailbox.store.json.event.dto.MailboxSessionDataTransferObject;
-import org.apache.james.mailbox.store.json.event.dto.MessageMetaDataDataTransferObject;
-import org.apache.james.mailbox.store.json.event.dto.UpdatedFlagsDataTransferObject;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.github.steveash.guavate.Guavate;
-import com.google.common.collect.ImmutableMap;
-
-public class EventConverter {
-
- private static final Logger LOG = LoggerFactory.getLogger(EventConverter.class);
-
- private final EventFactory eventFactory;
- private final MailboxConverter mailboxConverter;
-
- public EventConverter(MailboxConverter mailboxConverter) {
- this.eventFactory = new EventFactory();
- this.mailboxConverter = mailboxConverter;
- }
-
- public EventDataTransferObject convertToDataTransferObject(MailboxListener.MailboxEvent event) throws Exception {
- MailboxDataTransferObject mailboxDataTransferObject = mailboxConverter.extractMailboxDataTransferObject(event);
- if (event instanceof MailboxListener.Added) {
- return constructMeteDataHoldingEventProxy(EventType.ADDED,
- event.getSession(),
- mailboxDataTransferObject,
- ((MailboxListener.Added) event).getUids(),
- (MailboxListener.Added) event);
- } else if (event instanceof MailboxListener.Expunged) {
- return constructMeteDataHoldingEventProxy(EventType.DELETED,
- event.getSession(), mailboxDataTransferObject,
- ((MailboxListener.Expunged) event).getUids(),
- (MailboxListener.Expunged) event);
- } else if (event instanceof MailboxListener.FlagsUpdated) {
- return constructFalgsUpdatedProxy(event.getSession(),
- mailboxDataTransferObject,
- ((MailboxListener.FlagsUpdated) event).getUids(),
- ((MailboxListener.FlagsUpdated) event).getUpdatedFlags());
- } else if (event instanceof MailboxListener.MailboxRenamed) {
- return constructMailboxRenamedProxy(event.getSession(),
- mailboxDataTransferObject,
- event.getMailboxPath());
- } else if (event instanceof MailboxListener.MailboxDeletion) {
- MailboxListener.MailboxDeletion deletionEvent = (MailboxListener.MailboxDeletion) event;
- return constructMailboxDeletionProxy(EventType.MAILBOX_DELETED,
- event.getSession(),
- mailboxDataTransferObject,
- deletionEvent.getQuotaRoot(),
- deletionEvent.getDeletedMessageCount(),
- deletionEvent.getTotalDeletedSize());
- } else if (event instanceof MailboxListener.MailboxAdded) {
- return constructMailboxAddedProxy(EventType.MAILBOX_ADDED,
- event.getSession(),
- mailboxDataTransferObject);
- } else {
- throw new Exception("You are trying to serialize an event that can't be serialized");
- }
- }
-
- public MailboxListener.MailboxEvent retrieveEvent(EventDataTransferObject eventDataTransferObject) throws Exception {
- Mailbox mailbox = mailboxConverter.retrieveMailbox(eventDataTransferObject.getMailbox());
- switch (eventDataTransferObject.getType()) {
- case ADDED:
- return eventFactory.added(eventDataTransferObject.getSession().getMailboxSession(),
- retrieveMetadata(eventDataTransferObject.getMetaDataProxyMap()),
- mailbox,
- ImmutableMap.<MessageUid, MailboxMessage>of());
- case DELETED:
- return eventFactory.expunged(eventDataTransferObject.getSession().getMailboxSession(),
- retrieveMetadata(eventDataTransferObject.getMetaDataProxyMap()),
- mailbox);
- case FLAGS:
- return eventFactory.flagsUpdated(eventDataTransferObject.getSession().getMailboxSession(),
- eventDataTransferObject.getUids(),
- mailbox,
- retrieveUpdatedFlags(eventDataTransferObject.getUpdatedFlags()));
- case MAILBOX_ADDED:
- return eventFactory.mailboxAdded(eventDataTransferObject.getSession().getMailboxSession(), mailbox);
- case MAILBOX_DELETED:
- return eventFactory.mailboxDeleted(eventDataTransferObject.getSession().getMailboxSession(), mailbox,
- eventDataTransferObject.getQuotaRoot().orElseThrow(() -> new EventNotValidException("Not a Deletion event, missing quotaRoot")),
- eventDataTransferObject.getDeletedMessageCount().orElseThrow(() -> new EventNotValidException("Not a Deletion event, missing quotaCount")),
- eventDataTransferObject.getTotalDeletedSize().orElseThrow(() -> new EventNotValidException("Not a Deletion event, missing quotaSize")));
- case MAILBOX_RENAMED:
- return eventFactory.mailboxRenamed(eventDataTransferObject.getSession().getMailboxSession(),
- eventDataTransferObject.getFrom().getPath(),
- mailbox);
- default:
- throw new Exception("Can not deserialize unknown event");
- }
- }
-
- private EventDataTransferObject constructMailboxAddedProxy(EventType eventType,
- MailboxSession mailboxSession,
- MailboxDataTransferObject mailboxIntermediate) {
- return EventDataTransferObject.builder()
- .type(eventType)
- .session(new MailboxSessionDataTransferObject(mailboxSession))
- .mailbox(mailboxIntermediate)
- .build();
- }
-
- private EventDataTransferObject constructMailboxDeletionProxy(EventType eventType,
- MailboxSession mailboxSession,
- MailboxDataTransferObject mailboxIntermediate,
- QuotaRoot quotaRoot,
- QuotaCount deletedMessageCount,
- QuotaSize totalDeletedSize) {
- return EventDataTransferObject.builder()
- .type(eventType)
- .session(new MailboxSessionDataTransferObject(mailboxSession))
- .mailbox(mailboxIntermediate)
- .quotaRoot(Optional.of(quotaRoot))
- .deletedMessageCount(Optional.of(deletedMessageCount))
- .totalDeletedSize(Optional.of(totalDeletedSize))
- .build();
- }
-
- private EventDataTransferObject constructMailboxRenamedProxy(MailboxSession mailboxSession,
- MailboxDataTransferObject mailboxIntermediate,
- MailboxPath from) {
- return EventDataTransferObject.builder()
- .type(EventType.MAILBOX_RENAMED)
- .session(new MailboxSessionDataTransferObject(mailboxSession))
- .mailbox(mailboxIntermediate)
- .from(new MailboxPathDataTransferObject(from))
- .build();
- }
-
- private EventDataTransferObject constructFalgsUpdatedProxy(MailboxSession session,
- MailboxDataTransferObject mailboxIntermediate,
- List<MessageUid> uids,
- List<UpdatedFlags> updatedFlagsList) {
- List<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObjects = updatedFlagsList.stream()
- .map(UpdatedFlagsDataTransferObject::new)
- .collect(Guavate.toImmutableList());
- return EventDataTransferObject.builder()
- .type(EventType.FLAGS)
- .session(new MailboxSessionDataTransferObject(session))
- .mailbox(mailboxIntermediate)
- .uids(uids)
- .updatedFlags(updatedFlagsDataTransferObjects)
- .build();
- }
-
- private EventDataTransferObject constructMeteDataHoldingEventProxy(EventType eventType,
- MailboxSession mailboxSession,
- MailboxDataTransferObject mailboxIntermediate,
- List<MessageUid> uids,
- MailboxListener.MetaDataHoldingEvent event) {
- HashMap<MessageUid, MessageMetaDataDataTransferObject> metaDataProxyMap = new HashMap<>();
- for (MessageUid uid : uids) {
- metaDataProxyMap.put(uid, new MessageMetaDataDataTransferObject(
- event.getMetaData(uid)
- ));
- }
- return EventDataTransferObject.builder()
- .type(eventType)
- .session(new MailboxSessionDataTransferObject(mailboxSession))
- .mailbox(mailboxIntermediate)
- .uids(uids)
- .metaData(metaDataProxyMap)
- .build();
- }
-
- private SortedMap<MessageUid, MessageMetaData> retrieveMetadata(Map<MessageUid, MessageMetaDataDataTransferObject> metaDataProxyMap) {
- if (metaDataProxyMap != null) {
- TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
- Set<Map.Entry<MessageUid, MessageMetaDataDataTransferObject>> entrySet = metaDataProxyMap.entrySet();
- for (Map.Entry<MessageUid, MessageMetaDataDataTransferObject> entry : entrySet) {
- result.put(entry.getKey(), entry.getValue().getMetadata());
- }
- return result;
- } else {
- LOG.warn("Event serialization problem : No metadata");
- return null;
- }
- }
-
- private List<UpdatedFlags> retrieveUpdatedFlags(List<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObject) {
- return updatedFlagsDataTransferObject.stream()
- .map(UpdatedFlagsDataTransferObject::retrieveUpdatedFlags)
- .collect(Guavate.toImmutableList());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
deleted file mode 100644
index f4536be..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
+++ /dev/null
@@ -1,26 +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.json.event;
-
-public class EventNotValidException extends Exception {
-
- public EventNotValidException(String message) {
- super(message);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java
deleted file mode 100644
index e2273fd..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java
+++ /dev/null
@@ -1,91 +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.json.event;
-
-import java.io.IOException;
-
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.json.MailboxACLJsonConverter;
-import org.apache.james.mailbox.store.json.event.dto.MailboxDataTransferObject;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
-import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-public class MailboxConverter {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MailboxConverter.class);
-
- private final MailboxIdDeserializer mailboxIdDeserializer;
-
- public MailboxConverter(MailboxIdDeserializer mailboxIdDeserializer) {
- this.mailboxIdDeserializer = mailboxIdDeserializer;
- }
-
- public Mailbox retrieveMailbox(MailboxDataTransferObject mailboxDataTransferObject) {
- SimpleMailbox mailbox = new SimpleMailbox(new MailboxPath(mailboxDataTransferObject.getNamespace(),
- mailboxDataTransferObject.getUser(),
- mailboxDataTransferObject.getName()),
- mailboxDataTransferObject.getUidValidity());
- try {
- mailbox.setACL(MailboxACLJsonConverter.toACL(mailboxDataTransferObject.getSerializedACL()));
- mailbox.setMailboxId(mailboxIdDeserializer.deserialize(mailboxDataTransferObject.getSerializedMailboxId()));
- } catch (IOException e) {
- LOGGER.warn("Failed to deserialize ACL", e);
- } catch (MailboxIdDeserialisationException e) {
- LOGGER.warn("Failed to deserialize mailbox ID", e);
- }
- return mailbox;
- }
-
- public MailboxDataTransferObject convertMailboxDataTransferObject(Mailbox mailbox) {
- return MailboxDataTransferObject.builder()
- .serializedMailboxId(mailbox.getMailboxId().serialize())
- .namespace(mailbox.getNamespace())
- .user(mailbox.getUser())
- .name(mailbox.getName())
- .uidValidity(mailbox.getUidValidity())
- .serializedACL(getSerializedACL(mailbox))
- .build();
- }
-
- public MailboxDataTransferObject extractMailboxDataTransferObject(MailboxListener.MailboxEvent event) {
- if (event instanceof EventFactory.MailboxAware) {
- return convertMailboxDataTransferObject(((EventFactory.MailboxAware) event).getMailbox());
- } else {
- throw new RuntimeException("Unsupported event class : " + event.getClass().getCanonicalName());
- }
- }
-
- private String getSerializedACL(Mailbox mailbox) {
- try {
- return MailboxACLJsonConverter.toJson(mailbox.getACL());
- } catch (JsonProcessingException e) {
- return "{\"entries\":{}}";
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
deleted file mode 100644
index 0041a21..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
+++ /dev/null
@@ -1,203 +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.json.event.dto;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.QuotaRoot;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class EventDataTransferObject {
-
- public static class Builder {
-
- private EventType type;
- private MailboxDataTransferObject mailbox;
- private MailboxSessionDataTransferObject session;
- private List<MessageUid> uids;
- private Map<MessageUid, MessageMetaDataDataTransferObject> metaData;
- private List<UpdatedFlagsDataTransferObject> updatedFlags;
- private MailboxPathDataTransferObject from;
- private Optional<QuotaRoot> quotaRoot;
- private Optional<QuotaCount> deletedMessageCount;
- private Optional<QuotaSize> totalDeletedSize;
-
- public Builder type(EventType type) {
- this.type = type;
- return this;
- }
-
- public Builder mailbox(MailboxDataTransferObject mailbox) {
- this.mailbox = mailbox;
- return this;
- }
-
- public Builder session(MailboxSessionDataTransferObject session) {
- this.session = session;
- return this;
- }
-
- public Builder from(MailboxPathDataTransferObject from) {
- this.from = from;
- return this;
- }
-
- public Builder uids(List<MessageUid> uids) {
- this.uids = uids;
- return this;
- }
-
- public Builder metaData(Map<MessageUid, MessageMetaDataDataTransferObject> metaData) {
- this.metaData = metaData;
- return this;
- }
-
- public Builder updatedFlags(List<UpdatedFlagsDataTransferObject> updatedFlagsList) {
- this.updatedFlags = updatedFlagsList;
- return this;
- }
-
- public Builder quotaRoot(Optional<QuotaRoot> quotaRoot) {
- this.quotaRoot = quotaRoot;
- return this;
- }
-
- public Builder deletedMessageCount(Optional<QuotaCount> deletedMessageCount) {
- this.deletedMessageCount = deletedMessageCount;
- return this;
- }
-
- public Builder totalDeletedSize(Optional<QuotaSize> totalDeletedSize) {
- this.totalDeletedSize = totalDeletedSize;
- return this;
- }
-
- public EventDataTransferObject build() {
- return new EventDataTransferObject(type, mailbox, session, uids, metaData, updatedFlags, from, quotaRoot, deletedMessageCount, totalDeletedSize);
- }
-
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- @JsonProperty()
- private EventType type;
- @JsonProperty()
- private MailboxDataTransferObject mailbox;
- @JsonProperty()
- private MailboxSessionDataTransferObject session;
- @JsonProperty()
- private List<MessageUid> uids;
- @JsonProperty()
- private Map<MessageUid, MessageMetaDataDataTransferObject> metaData;
- @JsonProperty()
- private List<UpdatedFlagsDataTransferObject> updatedFlags;
- @JsonProperty()
- private MailboxPathDataTransferObject from;
- @JsonProperty()
- private Optional<QuotaRoot> quotaRoot;
- @JsonProperty()
- private Optional<QuotaCount> deletedMessageCount;
- @JsonProperty()
- private Optional<QuotaSize> totalDeletedSize;
-
- public EventDataTransferObject() {}
-
- public EventDataTransferObject(EventType type,
- MailboxDataTransferObject mailbox,
- MailboxSessionDataTransferObject session,
- List<MessageUid> uids,
- Map<MessageUid, MessageMetaDataDataTransferObject> metaData,
- List<UpdatedFlagsDataTransferObject> updatedFlags,
- MailboxPathDataTransferObject from,
- Optional<QuotaRoot> quotaRoot,
- Optional<QuotaCount> deletedMessageCount,
- Optional<QuotaSize> totalDeletedSize) {
- this.type = type;
- this.mailbox = mailbox;
- this.session = session;
- this.uids = uids;
- this.metaData = metaData;
- this.updatedFlags = updatedFlags;
- this.from = from;
- this.quotaRoot = quotaRoot;
- this.deletedMessageCount = deletedMessageCount;
- this.totalDeletedSize = totalDeletedSize;
- }
-
- @JsonIgnore
- public EventType getType() {
- return type;
- }
-
- @JsonIgnore
- public MailboxDataTransferObject getMailbox() {
- return mailbox;
- }
-
- @JsonIgnore
- public MailboxSessionDataTransferObject getSession() {
- return session;
- }
-
- @JsonIgnore
- public List<MessageUid> getUids() {
- return uids;
- }
-
- @JsonIgnore
- public Map<MessageUid, MessageMetaDataDataTransferObject> getMetaDataProxyMap() {
- return metaData;
- }
-
- @JsonIgnore
- public List<UpdatedFlagsDataTransferObject> getUpdatedFlags() {
- return updatedFlags;
- }
-
- @JsonIgnore
- public MailboxPathDataTransferObject getFrom() {
- return from;
- }
-
- @JsonIgnore
- public Optional<QuotaRoot> getQuotaRoot() {
- return quotaRoot;
- }
-
- @JsonIgnore
- public Optional<QuotaCount> getDeletedMessageCount() {
- return deletedMessageCount;
- }
-
- @JsonIgnore
- public Optional<QuotaSize> getTotalDeletedSize() {
- return totalDeletedSize;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java
deleted file mode 100644
index d3beae3..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java
+++ /dev/null
@@ -1,32 +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.json.event.dto;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-
-@JsonFormat(shape = JsonFormat.Shape.NUMBER)
-public enum EventType {
- ADDED,
- DELETED,
- FLAGS,
- MAILBOX_RENAMED,
- MAILBOX_ADDED,
- MAILBOX_DELETED
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java
deleted file mode 100644
index 08515ab..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java
+++ /dev/null
@@ -1,83 +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.json.event.dto;
-
-import javax.mail.Flags;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class FlagsDataTransferObject {
- @JsonProperty()
- private boolean answered;
- @JsonProperty()
- private boolean flagged;
- @JsonProperty()
- private boolean recent;
- @JsonProperty()
- private boolean deleted;
- @JsonProperty()
- private boolean draft;
- @JsonProperty()
- private boolean seen;
- @JsonProperty()
- private String[] userFlags;
-
- public FlagsDataTransferObject() {
-
- }
-
- public FlagsDataTransferObject(Flags flags) {
- this.answered = flags.contains(Flags.Flag.ANSWERED);
- this.flagged = flags.contains(Flags.Flag.FLAGGED);
- this.recent = flags.contains(Flags.Flag.RECENT);
- this.deleted = flags.contains(Flags.Flag.DELETED);
- this.draft = flags.contains(Flags.Flag.DRAFT);
- this.seen = flags.contains(Flags.Flag.SEEN);
- this.userFlags = flags.getUserFlags();
- }
-
- @JsonIgnore
- public Flags getFlags() {
- Flags result = new Flags();
- if (answered) {
- result.add(Flags.Flag.ANSWERED);
- }
- if (flagged) {
- result.add(Flags.Flag.FLAGGED);
- }
- if (recent) {
- result.add(Flags.Flag.RECENT);
- }
- if (deleted) {
- result.add(Flags.Flag.DELETED);
- }
- if (draft) {
- result.add(Flags.Flag.DRAFT);
- }
- if (seen) {
- result.add(Flags.Flag.SEEN);
- }
- for (String flag : userFlags) {
- result.add(flag);
- }
- return result;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java
deleted file mode 100644
index dfbf307..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java
+++ /dev/null
@@ -1,49 +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.json.event.dto;
-
-import java.util.Locale;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class LocaleDataTransferObject {
- @JsonProperty()
- private String country;
- @JsonProperty()
- private String variant;
- @JsonProperty()
- private String language;
-
- public LocaleDataTransferObject() {
-
- }
-
- public LocaleDataTransferObject(Locale locale) {
- this.country = locale.getCountry();
- this.variant = locale.getVariant();
- this.language = locale.getLanguage();
- }
-
- @JsonIgnore
- public Locale getLocale() {
- return new Locale(language, country, variant);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java
deleted file mode 100644
index f7fdfa5..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java
+++ /dev/null
@@ -1,143 +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.json.event.dto;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class MailboxDataTransferObject {
-
- public static class Builder {
- private String serializedMailboxId;
- private String namespace;
- private String user;
- private String name;
- private long uidValidity;
- private String serializedACL;
-
- private Builder() {
-
- }
-
- public Builder serializedMailboxId(String serializedMailboxId) {
- this.serializedMailboxId = serializedMailboxId;
- return this;
- }
-
- public Builder namespace(String namespace) {
- this.namespace = namespace;
- return this;
- }
-
- public Builder user(String user) {
- this.user = user;
- return this;
- }
-
- public Builder name(String name) {
- this.name = name;
- return this;
- }
-
- public Builder uidValidity(long uidValidity) {
- this.uidValidity = uidValidity;
- return this;
- }
-
- public Builder serializedACL(String serializedACL) {
- this.serializedACL = serializedACL;
- return this;
- }
-
- public MailboxDataTransferObject build() {
- return new MailboxDataTransferObject(serializedMailboxId,
- namespace,
- user,
- name,
- uidValidity,
- serializedACL);
- }
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- @JsonProperty()
- private String serializedMailboxId;
- @JsonProperty()
- private String namespace;
- @JsonProperty()
- private String user;
- @JsonProperty()
- private String name;
- @JsonProperty()
- private long uidValidity;
- @JsonProperty()
- private String serializedACL;
-
- public MailboxDataTransferObject() {
-
- }
-
- private MailboxDataTransferObject(String serializedMailboxId,
- String namespace,
- String user,
- String name,
- long uidValidity,
- String serializedACL) {
- this.serializedMailboxId = serializedMailboxId;
- this.namespace = namespace;
- this.user = user;
- this.name = name;
- this.uidValidity = uidValidity;
- this.serializedACL = serializedACL;
- }
-
- @JsonIgnore
- public String getSerializedMailboxId() {
- return serializedMailboxId;
- }
-
- @JsonIgnore
- public String getNamespace() {
- return namespace;
- }
-
- @JsonIgnore
- public String getUser() {
- return user;
- }
-
- @JsonIgnore
- public String getName() {
- return name;
- }
-
- @JsonIgnore
- public long getUidValidity() {
- return uidValidity;
- }
-
- @JsonIgnore
- public String getSerializedACL() {
- return serializedACL;
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java
deleted file mode 100644
index f2755bb..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java
+++ /dev/null
@@ -1,49 +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.json.event.dto;
-
-import org.apache.james.mailbox.model.MailboxPath;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class MailboxPathDataTransferObject {
- @JsonProperty()
- private String user;
- @JsonProperty()
- private String namespace;
- @JsonProperty()
- private String name;
-
- public MailboxPathDataTransferObject() {
-
- }
-
- public MailboxPathDataTransferObject(MailboxPath path) {
- this.user = path.getUser();
- this.name = path.getName();
- this.namespace = path.getNamespace();
- }
-
- @JsonIgnore
- public MailboxPath getPath() {
- return new MailboxPath(namespace, user, name);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java
deleted file mode 100644
index 2c59ba0..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java
+++ /dev/null
@@ -1,111 +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.json.event.dto;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.store.SimpleMailboxSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.Lists;
-
-public class MailboxSessionDataTransferObject {
- @JsonProperty()
- private long sessionId;
- @JsonProperty()
- private String username;
- @JsonProperty()
- private List<String> sharedSpaces;
- @JsonProperty()
- private String otherUserSpace;
- @JsonProperty()
- private char separator;
- @JsonProperty()
- private List<LocaleDataTransferObject> locales;
- @JsonProperty("r")
- private int sessionType;
-
- private static final Logger LOG = LoggerFactory.getLogger(MailboxSessionDataTransferObject.class);
-
- public MailboxSessionDataTransferObject() {
-
- }
-
- public MailboxSessionDataTransferObject(MailboxSession session) {
- username = session.getUser().getUserName();
- sharedSpaces = new ArrayList<>(session.getSharedSpaces());
- otherUserSpace = session.getOtherUsersSpace();
- separator = session.getPathDelimiter();
- sessionType = extractSessionType(session);
- sessionId = session.getSessionId();
- locales = Lists.transform(session.getUser().getLocalePreferences(), LocaleDataTransferObject::new);
- }
-
- @JsonIgnore
- public MailboxSession getMailboxSession() {
- return new SimpleMailboxSession(sessionId,
- username,
- "",
- retrieveLocales(),
- sharedSpaces,
- otherUserSpace,
- separator,
- retrieveSessionType());
- }
-
- private List<Locale> retrieveLocales() {
- if (locales != null) {
- return Lists.transform(locales, LocaleDataTransferObject::getLocale);
- } else {
- return new ArrayList<>();
- }
- }
-
- private MailboxSession.SessionType retrieveSessionType() {
- switch (this.sessionType) {
- case 0:
- return MailboxSession.SessionType.User;
- case 1:
- return MailboxSession.SessionType.System;
- default:
- LOG.warn("Unknown session type number while deserializing. Assuming user instead");
- return MailboxSession.SessionType.User;
- }
- }
-
- private int extractSessionType(MailboxSession session) {
- switch (session.getType()) {
- case User:
- return 0;
- case System:
- return 1;
- default:
- LOG.warn("Unknow session type while serializing mailbox session");
- return 0;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java
deleted file mode 100644
index 91c36e0..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java
+++ /dev/null
@@ -1,95 +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.json.event.dto;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class MessageMetaDataDataTransferObject {
- @JsonProperty()
- private long uid;
- @JsonProperty()
- private long modseq;
- @JsonProperty()
- private FlagsDataTransferObject flags;
- @JsonProperty()
- private long size;
- @JsonProperty()
- private String date;
- @JsonProperty
- private MessageId messageId;
-
- private static final Logger LOG = LoggerFactory.getLogger(MessageMetaDataDataTransferObject.class);
-
- private static final ThreadLocal<SimpleDateFormat> simpleDateFormat = ThreadLocal.withInitial(
- () -> new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
-
- private static Date parse(String date) throws ParseException {
- if (date != null) {
- return simpleDateFormat.get().parse(date);
- } else {
- return null;
- }
- }
-
- private static String format(Date date) {
- if (date != null) {
- return simpleDateFormat.get().format(date);
- } else {
- return null;
- }
- }
-
-
- public MessageMetaDataDataTransferObject() {
-
- }
-
- public MessageMetaDataDataTransferObject(MessageMetaData metadata) {
- this.uid = metadata.getUid().asLong();
- this.modseq = metadata.getModSeq();
- this.flags = new FlagsDataTransferObject(metadata.getFlags());
- this.size = metadata.getSize();
- this.date = format(metadata.getInternalDate());
- this.messageId = metadata.getMessageId();
- }
-
- @JsonIgnore
- public SimpleMessageMetaData getMetadata() {
- try {
- return new SimpleMessageMetaData(MessageUid.of(uid), modseq, flags.getFlags(), size, parse(date), messageId);
- } catch (ParseException parseException) {
- LOG.error("Parse exception while parsing date while deserializing metadata upon event serialization. Using nowadays date instead.", parseException);
- return new SimpleMessageMetaData(MessageUid.of(uid), modseq, flags.getFlags(), size, new Date(), messageId);
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java
deleted file mode 100644
index b5cdda0..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java
+++ /dev/null
@@ -1,56 +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.json.event.dto;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.UpdatedFlags;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class UpdatedFlagsDataTransferObject {
- @JsonProperty("uid")
- private long uid;
- @JsonProperty("modseq")
- private long modseq;
- @JsonProperty("oldFlags")
- private FlagsDataTransferObject oldFlags;
- @JsonProperty("newFlags")
- private FlagsDataTransferObject newFlags;
-
- public UpdatedFlagsDataTransferObject() {
- }
-
- public UpdatedFlagsDataTransferObject(UpdatedFlags updatedFlags) {
- this.uid = updatedFlags.getUid().asLong();
- this.modseq = updatedFlags.getModSeq();
- this.oldFlags = new FlagsDataTransferObject(updatedFlags.getOldFlags());
- this.newFlags = new FlagsDataTransferObject(updatedFlags.getNewFlags());
- }
-
- public UpdatedFlags retrieveUpdatedFlags() {
- return UpdatedFlags.builder()
- .uid(MessageUid.of(uid))
- .modSeq(modseq)
- .oldFlags(oldFlags.getFlags())
- .newFlags(newFlags.getFlags())
- .build();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
deleted file mode 100644
index f6d68b8..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
+++ /dev/null
@@ -1,165 +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.json;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Optional;
-import java.util.TreeMap;
-
-import javax.mail.Flags;
-
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.model.TestId;
-import org.apache.james.mailbox.model.TestMessageId;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
-import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.event.EventSerializer;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-
-public abstract class EventSerializerTest {
-
- public static final MessageUid UID = MessageUid.of(42);
- public static final long MOD_SEQ = 24L;
- public static final Flags FLAGS = new Flags();
- public static final UpdatedFlags UPDATED_FLAGS = UpdatedFlags.builder()
- .uid(UID)
- .modSeq(MOD_SEQ)
- .oldFlags(FLAGS)
- .newFlags(new Flags(Flags.Flag.SEEN))
- .build();
- public static final long SIZE = 45L;
- private static final MessageId MESSAGE_ID = new TestMessageId.Factory().generate();
- public static final SimpleMessageMetaData MESSAGE_META_DATA = new SimpleMessageMetaData(UID, MOD_SEQ, FLAGS, SIZE, null, MESSAGE_ID);
- public static final MailboxPath FROM = new MailboxPath("namespace", "user", "name");
-
- private EventSerializer serializer;
- private EventFactory eventFactory;
- private MailboxSession mailboxSession;
- private SimpleMailbox mailbox;
-
- abstract EventSerializer createSerializer();
-
- @Before
- public void setUp() {
- eventFactory = new EventFactory();
- serializer = createSerializer();
- mailboxSession = new MockMailboxSession("benwa");
- mailbox = new SimpleMailbox(MailboxPath.forUser("benwa", "name"), 42);
- mailbox.setMailboxId(TestId.of(28L));
- }
-
- @Test
- public void addedEventShouldBeWellConverted() throws Exception {
- TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<>();
- treeMap.put(UID, MESSAGE_META_DATA);
- MailboxListener.MailboxEvent event = eventFactory.added(mailboxSession, treeMap, mailbox, ImmutableMap.<MessageUid, MailboxMessage>of());
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxEvent deserializedEvent = serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.Added.class);
- assertThat(((MailboxListener.Added)deserializedEvent).getUids()).containsOnly(UID);
- MessageMetaData messageMetaData = ((MailboxListener.Added)deserializedEvent).getMetaData(UID);
- assertThat(messageMetaData).isEqualTo(MESSAGE_META_DATA);
- assertThat(messageMetaData.getMessageId()).isEqualTo(MESSAGE_ID);
- }
-
- @Test
- public void expungedEventShouldBeWellConverted() throws Exception {
- TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<>();
- treeMap.put(UID, MESSAGE_META_DATA);
- MailboxListener.MailboxEvent event = eventFactory.expunged(mailboxSession, treeMap, mailbox);
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxEvent deserializedEvent = serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.Expunged.class);
- assertThat(((MailboxListener.Expunged)deserializedEvent).getUids()).containsOnly(UID);
- MessageMetaData messageMetaData = ((MailboxListener.Expunged)deserializedEvent).getMetaData(UID);
- assertThat(messageMetaData).isEqualTo(MESSAGE_META_DATA);
- assertThat(messageMetaData.getMessageId()).isEqualTo(MESSAGE_ID);
- }
-
- @Test
- public void flagsUpdatedEventShouldBeWellConverted() throws Exception {
- MailboxListener.MailboxEvent event = eventFactory.flagsUpdated(mailboxSession, Lists.newArrayList(UID), mailbox, Lists.newArrayList(UPDATED_FLAGS));
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxEvent deserializedEvent = serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.FlagsUpdated.class);
- assertThat(((MailboxListener.FlagsUpdated)event).getUpdatedFlags()).containsOnly(UPDATED_FLAGS);
- }
-
- @Test
- public void mailboxAddedShouldBeWellConverted() throws Exception {
- MailboxListener.MailboxEvent event = eventFactory.mailboxAdded(mailboxSession, mailbox);
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxEvent deserializedEvent = serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxAdded.class);
- }
-
- @Test
- public void mailboxDeletionShouldBeWellConverted() throws Exception {
- QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
- QuotaCount quotaCount = QuotaCount.count(123);
- QuotaSize quotaSize = QuotaSize.size(456);
- MailboxListener.MailboxDeletion event = eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, quotaSize);
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxDeletion deserializedEvent = (MailboxListener.MailboxDeletion) serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxDeletion.class);
- assertThat(deserializedEvent.getQuotaRoot()).isEqualTo(quotaRoot);
- assertThat(deserializedEvent.getDeletedMessageCount()).isEqualTo(quotaCount);
- assertThat(deserializedEvent.getTotalDeletedSize()).isEqualTo(quotaSize);
- }
-
- @Test
- public void mailboxRenamedShouldBeWellConverted() throws Exception {
- MailboxListener.MailboxEvent event = eventFactory.mailboxRenamed(mailboxSession, FROM, mailbox);
- byte[] serializedEvent = serializer.serializeEvent(event);
- MailboxListener.MailboxEvent deserializedEvent = serializer.deSerializeEvent(serializedEvent);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
- assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxRenamed.class);
- assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e877c0b2/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java
deleted file mode 100644
index ac7a6c9..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java
+++ /dev/null
@@ -1,37 +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.json;
-
-import org.apache.james.mailbox.model.TestMessageId;
-import org.apache.james.mailbox.store.TestIdDeserializer;
-import org.apache.james.mailbox.store.event.EventSerializer;
-import org.apache.james.mailbox.store.json.event.EventConverter;
-import org.apache.james.mailbox.store.json.event.MailboxConverter;
-
-public class JsonEventSerializerTest extends EventSerializerTest {
-
- @Override
- EventSerializer createSerializer() {
- return new JsonEventSerializer(
- new EventConverter(
- new MailboxConverter(new TestIdDeserializer())),
- new TestMessageId.Factory());
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/14] james-project git commit: MAILBOX-355 Solve intelliJ warnings
in DefaultUserQuotaRootResolverTest
Posted by bt...@apache.org.
MAILBOX-355 Solve intelliJ warnings in DefaultUserQuotaRootResolverTest
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9494a119
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9494a119
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9494a119
Branch: refs/heads/master
Commit: 9494a119d26844e063aa5d2afca66ab20d0037c0
Parents: 985b9a4
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:10:28 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:33:30 2018 +0700
----------------------------------------------------------------------
.../quota/DefaultUserQuotaRootResolverTest.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9494a119/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
index 92b9f6c..367d476 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
@@ -40,10 +40,10 @@ public class DefaultUserQuotaRootResolverTest {
public static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
public static final SimpleMailbox MAILBOX = new SimpleMailbox(MAILBOX_PATH, 10);
- public static final MailboxPath PATH_LIKE = MailboxPath.forUser("benwa", "%");
- public static final MailboxPath MAILBOX_PATH_2 = MailboxPath.forUser("benwa", "test");
- public static final SimpleMailbox MAILBOX_2 = new SimpleMailbox(MAILBOX_PATH_2, 10);
- public static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("#private&benwa", Optional.empty());
+ private static final MailboxPath PATH_LIKE = MailboxPath.forUser("benwa", "%");
+ private static final MailboxPath MAILBOX_PATH_2 = MailboxPath.forUser("benwa", "test");
+ private static final SimpleMailbox MAILBOX_2 = new SimpleMailbox(MAILBOX_PATH_2, 10);
+ private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("#private&benwa", Optional.empty());
private DefaultUserQuotaRootResolver testee;
private MailboxSessionMapperFactory mockedFactory;
@@ -55,22 +55,22 @@ public class DefaultUserQuotaRootResolverTest {
}
@Test
- public void getQuotaRootShouldReturnUserRelatedQuotaRoot() throws Exception {
+ public void getQuotaRootShouldReturnUserRelatedQuotaRoot() {
assertThat(testee.getQuotaRoot(MAILBOX_PATH)).isEqualTo(QUOTA_ROOT);
}
@Test(expected = IllegalArgumentException.class)
- public void getQuotaRootShouldThrowWhenNamespaceContainsSeparator() throws Exception {
+ public void getQuotaRootShouldThrowWhenNamespaceContainsSeparator() {
testee.getQuotaRoot(new MailboxPath("#pr&ivate", "benwa", "INBOX"));
}
@Test(expected = IllegalArgumentException.class)
- public void getQuotaRootShouldThrowWhenUserContainsSeparator() throws Exception {
+ public void getQuotaRootShouldThrowWhenUserContainsSeparator() {
testee.getQuotaRoot(MailboxPath.forUser("ben&wa", "INBOX"));
}
@Test
- public void getQuotaRootShouldWorkWhenUserIsNull() throws Exception {
+ public void getQuotaRootShouldWorkWhenUserIsNull() {
QuotaRoot quotaRoot = testee.getQuotaRoot(new MailboxPath("#private", null, "INBOX"));
assertThat(quotaRoot).isEqualTo(QuotaRoot.quotaRoot("#private", Optional.empty()));
@@ -78,7 +78,7 @@ public class DefaultUserQuotaRootResolverTest {
@Test
public void retrieveAssociatedMailboxesShouldWork() throws Exception {
- final MailboxMapper mockedMapper = mock(MailboxMapper.class);
+ MailboxMapper mockedMapper = mock(MailboxMapper.class);
when(mockedFactory.getMailboxMapper(null)).thenReturn(mockedMapper);
when(mockedMapper.findMailboxWithPathLike(PATH_LIKE)).thenReturn(Lists.newArrayList(MAILBOX, MAILBOX_2));
assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, null)).containsOnly(MAILBOX_PATH, MAILBOX_PATH_2);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[14/14] james-project git commit: MAILBOX-355
ListeningCurrentQuotaUpdater should rely on MailboxId
Posted by bt...@apache.org.
MAILBOX-355 ListeningCurrentQuotaUpdater should rely on MailboxId
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5b05b944
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5b05b944
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5b05b944
Branch: refs/heads/master
Commit: 5b05b9445f46e0b9421dd00b1db6e4b57c4111d3
Parents: e7e5ba6
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 10:28:50 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/quota/QuotaRootResolver.java | 3 ++
.../quota/DefaultUserQuotaRootResolver.java | 12 +++++
.../quota/ListeningCurrentQuotaUpdater.java | 4 +-
.../quota/DefaultUserQuotaRootResolverTest.java | 21 ++++++--
.../quota/ListeningCurrentQuotaUpdaterTest.java | 54 ++++++++++++++------
5 files changed, 73 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5b05b944/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
index 83d5f64..38aa4e6 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/QuotaRootResolver.java
@@ -23,6 +23,7 @@ import java.util.List;
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.MailboxPath;
import org.apache.james.mailbox.model.QuotaRoot;
@@ -37,6 +38,8 @@ public interface QuotaRootResolver {
*/
QuotaRoot getQuotaRoot(MailboxPath mailboxPath) throws MailboxException;
+ QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException;
+
QuotaRoot fromString(String serializedQuotaRoot) throws MailboxException;
List<MailboxPath> retrieveAssociatedMailboxes(QuotaRoot quotaRoot, MailboxSession mailboxSession) throws MailboxException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/5b05b944/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
index 09a55c9..2340ff1 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
@@ -28,6 +28,7 @@ import org.apache.james.core.User;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.quota.UserQuotaRootResolver;
@@ -68,6 +69,17 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver {
}
@Override
+ public QuotaRoot getQuotaRoot(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
+ User user = User.fromUsername(
+ factory.getMailboxMapper(mailboxSession)
+ .findMailboxById(mailboxId)
+ .generateAssociatedPath()
+ .getUser());
+
+ return forUser(user);
+ }
+
+ @Override
public QuotaRoot fromString(String serializedQuotaRoot) throws MailboxException {
List<String> parts = toParts(serializedQuotaRoot);
User user = User.fromUsername(parts.get(1));
http://git-wip-us.apache.org/repos/asf/james-project/blob/5b05b944/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 86d67c3..5f9da05 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -60,11 +60,11 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat
try {
if (event instanceof Added) {
Added addedEvent = (Added) event;
- QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxPath());
+ QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId(), event.getSession());
handleAddedEvent(addedEvent, quotaRoot);
} else if (event instanceof Expunged) {
Expunged expungedEvent = (Expunged) event;
- QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxPath());
+ QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId(), event.getSession());
handleExpungedEvent(expungedEvent, quotaRoot);
} else if (event instanceof MailboxDeletion) {
MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
http://git-wip-us.apache.org/repos/asf/james-project/blob/5b05b944/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
index 367d476..f5f98ff 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
@@ -25,9 +25,12 @@ import static org.mockito.Mockito.when;
import java.util.Optional;
+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.MailboxPath;
import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.TestId;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -44,6 +47,8 @@ public class DefaultUserQuotaRootResolverTest {
private static final MailboxPath MAILBOX_PATH_2 = MailboxPath.forUser("benwa", "test");
private static final SimpleMailbox MAILBOX_2 = new SimpleMailbox(MAILBOX_PATH_2, 10);
private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("#private&benwa", Optional.empty());
+ private static final MailboxId MAILBOX_ID = TestId.of(42);
+ public static final MailboxSession MAILBOX_SESSION = null;
private DefaultUserQuotaRootResolver testee;
private MailboxSessionMapperFactory mockedFactory;
@@ -79,14 +84,24 @@ public class DefaultUserQuotaRootResolverTest {
@Test
public void retrieveAssociatedMailboxesShouldWork() throws Exception {
MailboxMapper mockedMapper = mock(MailboxMapper.class);
- when(mockedFactory.getMailboxMapper(null)).thenReturn(mockedMapper);
+ when(mockedFactory.getMailboxMapper(MAILBOX_SESSION)).thenReturn(mockedMapper);
when(mockedMapper.findMailboxWithPathLike(PATH_LIKE)).thenReturn(Lists.newArrayList(MAILBOX, MAILBOX_2));
- assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, null)).containsOnly(MAILBOX_PATH, MAILBOX_PATH_2);
+
+ assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, MAILBOX_SESSION)).containsOnly(MAILBOX_PATH, MAILBOX_PATH_2);
+ }
+
+ @Test
+ public void getQuotaRootShouldReturnUserValueWhenCalledWithMailboxId() throws Exception {
+ MailboxMapper mockedMapper = mock(MailboxMapper.class);
+ when(mockedFactory.getMailboxMapper(MAILBOX_SESSION)).thenReturn(mockedMapper);
+ when(mockedMapper.findMailboxById(MAILBOX_ID)).thenReturn(MAILBOX);
+
+ assertThat(testee.getQuotaRoot(MAILBOX_ID, MAILBOX_SESSION)).isEqualTo(QUOTA_ROOT);
}
@Test(expected = MailboxException.class)
public void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() throws Exception {
- testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), null);
+ testee.retrieveAssociatedMailboxes(QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), MAILBOX_SESSION);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5b05b944/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index 2c5de61..a14dd30 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -19,6 +19,8 @@
package org.apache.james.mailbox.store.quota;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -33,9 +35,12 @@ import javax.mail.Flags;
import org.apache.james.core.quota.QuotaCount;
import org.apache.james.core.quota.QuotaSize;
import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.TestId;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.SimpleMessageMetaData;
@@ -48,9 +53,10 @@ import com.google.common.collect.Lists;
public class ListeningCurrentQuotaUpdaterTest {
- public static final int SIZE = 45;
- public static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("benwa", "INBOX");
- public static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", Optional.empty());
+ private static final int SIZE = 45;
+ private static final MailboxId MAILBOX_ID = TestId.of(42);
+ private static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa", Optional.empty());
+ private static final MailboxSession MAILBOX_SESSION = new MockMailboxSession("benwa");
private StoreCurrentQuotaManager mockedCurrentQuotaManager;
private QuotaRootResolver mockedQuotaRootResolver;
@@ -70,9 +76,12 @@ public class ListeningCurrentQuotaUpdaterTest {
when(added.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(added.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
- when(added.getMailboxPath()).thenReturn(MAILBOX_PATH);
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(added.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(added.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+
testee.event(added);
+
verify(mockedCurrentQuotaManager).increase(QUOTA_ROOT, 2, 2 * SIZE);
}
@@ -82,9 +91,12 @@ public class ListeningCurrentQuotaUpdaterTest {
when(expunged.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date(), new DefaultMessageId()));
when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
- when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH);
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+
testee.event(expunged);
+
verify(mockedCurrentQuotaManager).decrease(QUOTA_ROOT, 2, 2 * SIZE);
}
@@ -92,9 +104,12 @@ public class ListeningCurrentQuotaUpdaterTest {
public void emptyExpungedEventShouldNotTriggerDecrease() throws Exception {
MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
when(expunged.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
- when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH);
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(expunged.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(expunged.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+
testee.event(expunged);
+
verify(mockedCurrentQuotaManager, never()).decrease(QUOTA_ROOT, 0, 0);
}
@@ -102,32 +117,39 @@ public class ListeningCurrentQuotaUpdaterTest {
public void emptyAddedEventShouldNotTriggerDecrease() throws Exception {
MailboxListener.Added added = mock(MailboxListener.Added.class);
when(added.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
- when(added.getMailboxPath()).thenReturn(MAILBOX_PATH);
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(added.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(added.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+
testee.event(added);
+
verify(mockedCurrentQuotaManager, never()).increase(QUOTA_ROOT, 0, 0);
}
@Test
public void mailboxDeletionEventShouldDecreaseCurrentQuotaValues() throws Exception {
MailboxListener.MailboxDeletion deletion = mock(MailboxListener.MailboxDeletion.class);
- when(deletion.getMailboxPath()).thenReturn(MAILBOX_PATH);
when(deletion.getQuotaRoot()).thenReturn(QUOTA_ROOT);
when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(10));
when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(5));
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
+
testee.event(deletion);
+
verify(mockedCurrentQuotaManager).decrease(QUOTA_ROOT, 10, 5);
}
@Test
public void mailboxDeletionEventShouldDoNothingWhenEmptyMailbox() throws Exception {
MailboxListener.MailboxDeletion deletion = mock(MailboxListener.MailboxDeletion.class);
- when(deletion.getMailboxPath()).thenReturn(MAILBOX_PATH);
when(deletion.getQuotaRoot()).thenReturn(QUOTA_ROOT);
when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(0));
when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(0));
- when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(deletion.getMailboxId()).thenReturn(MAILBOX_ID);
+ when(deletion.getSession()).thenReturn(MAILBOX_SESSION);
+ when(mockedQuotaRootResolver.getQuotaRoot(eq(MAILBOX_ID), any(MailboxSession.class))).thenReturn(QUOTA_ROOT);
testee.event(deletion);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/14] james-project git commit: MAILBOX-355 Move
SystemMailboxesProvider to Mailbox-Api
Posted by bt...@apache.org.
MAILBOX-355 Move SystemMailboxesProvider to Mailbox-Api
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3412083e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3412083e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3412083e
Branch: refs/heads/master
Commit: 3412083e85f8845e1f30a496b63ea526fc438442
Parents: 5b05b94
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 12:05:17 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/SystemMailboxesProvider.java | 34 +++++++++
.../exception/MailboxRoleNotFoundException.java | 36 +++++++++
.../store/SystemMailboxesProviderImpl.java | 79 ++++++++++++++++++++
.../store/SystemMailboxesProviderImplTest.java | 74 ++++++++++++++++++
server/container/guice/protocols/jmap/pom.xml | 4 +
.../java/org/apache/james/jmap/JMAPModule.java | 4 +-
.../MailboxRoleNotFoundException.java | 36 ---------
.../james/jmap/methods/SendMDNProcessor.java | 2 +-
.../methods/SetMessagesCreationProcessor.java | 2 +-
.../methods/SetMessagesUpdateProcessor.java | 2 +-
.../james/jmap/send/PostDequeueDecorator.java | 4 +-
.../jmap/send/PostDequeueDecoratorFactory.java | 2 +-
.../jmap/utils/SystemMailboxesProvider.java | 37 ---------
.../jmap/utils/SystemMailboxesProviderImpl.java | 78 -------------------
.../SetMessagesCreationProcessorTest.java | 2 +-
.../methods/SetMessagesUpdateProcessorTest.java | 2 +-
.../jmap/send/PostDequeueDecoratorTest.java | 4 +-
.../utils/SystemMailboxesProviderImplTest.java | 74 ------------------
18 files changed, 239 insertions(+), 237 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java b/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
new file mode 100644
index 0000000..2b2dd9f
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/SystemMailboxesProvider.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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;
+
+import java.util.stream.Stream;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxRoleNotFoundException;
+
+public interface SystemMailboxesProvider {
+ Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException;
+
+ default MessageManager findMailbox(Role role, MailboxSession session) throws MailboxException {
+ return getMailboxByRole(role, session).findAny()
+ .orElseThrow(() -> new MailboxRoleNotFoundException(role));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxRoleNotFoundException.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxRoleNotFoundException.java b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxRoleNotFoundException.java
new file mode 100644
index 0000000..f92f879
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/MailboxRoleNotFoundException.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.exception;
+
+import org.apache.james.mailbox.Role;
+
+public class MailboxRoleNotFoundException extends RuntimeException {
+
+ private final Role role;
+
+ public MailboxRoleNotFoundException(Role role) {
+ super(String.format("Could not find any mailbox with role '%s'", role.serialize()));
+ this.role = role;
+ }
+
+ public Role getRole() {
+ return role;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
new file mode 100644
index 0000000..0045d70
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
@@ -0,0 +1,79 @@
+/****************************************************************
+ * 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 java.util.stream.Stream;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
+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.model.search.PrefixedWildcard;
+
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.ThrowingFunction;
+import com.google.common.annotations.VisibleForTesting;
+
+public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
+
+ private final MailboxManager mailboxManager;
+
+ @Inject
+ @VisibleForTesting
+ public SystemMailboxesProviderImpl(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ }
+
+ @Override
+ public Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException {
+ MailboxPath mailboxPath = MailboxPath.forUser(session.getUser().getUserName(), aRole.getDefaultMailbox());
+ try {
+ return Stream.of(mailboxManager.getMailbox(mailboxPath, session));
+ } catch (MailboxNotFoundException e) {
+ return searchMessageManagerByMailboxRole(aRole, session);
+ }
+ }
+
+ private boolean hasRole(Role aRole, MailboxPath mailBoxPath) {
+ return Role.from(mailBoxPath.getName())
+ .map(aRole::equals)
+ .orElse(false);
+ }
+
+ private Stream<MessageManager> searchMessageManagerByMailboxRole(Role aRole, MailboxSession session) throws MailboxException {
+ ThrowingFunction<MailboxPath, MessageManager> loadMailbox = path -> mailboxManager.getMailbox(path, session);
+ MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
+ .expression(new PrefixedWildcard(aRole.getDefaultMailbox()))
+ .build();
+ return mailboxManager.search(mailboxQuery, session)
+ .stream()
+ .map(MailboxMetaData::getPath)
+ .filter(path -> hasRole(aRole, path))
+ .map(Throwing.function(loadMailbox).sneakyThrow());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
new file mode 100644
index 0000000..f100a27
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.fixture.MailboxFixture;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class SystemMailboxesProviderImplTest {
+
+ private MailboxSession mailboxSession = new MockMailboxSession(MailboxFixture.ALICE);
+ private SystemMailboxesProviderImpl systemMailboxProvider;
+
+ private MailboxManager mailboxManager;
+
+ private MessageManager inboxMessageManager;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Before
+ public void setUp() throws Exception {
+ mailboxManager = mock(MailboxManager.class);
+ inboxMessageManager = mock(MessageManager.class);
+
+ systemMailboxProvider = new SystemMailboxesProviderImpl(mailboxManager);
+ }
+
+ @Test
+ public void getMailboxByRoleShouldReturnEmptyWhenNoMailbox() throws Exception {
+ when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenThrow(MailboxNotFoundException.class);
+
+ assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession)).isEmpty();
+ }
+
+ @Test
+ public void getMailboxByRoleShouldReturnMailboxByRole() throws Exception {
+ when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenReturn(inboxMessageManager);
+
+ assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession))
+ .hasSize(1)
+ .containsOnly(inboxMessageManager);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/container/guice/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/pom.xml b/server/container/guice/protocols/jmap/pom.xml
index 2d4191e..f870ff8 100644
--- a/server/container/guice/protocols/jmap/pom.xml
+++ b/server/container/guice/protocols/jmap/pom.xml
@@ -43,6 +43,10 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-store</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
index 6ce551e..c15bf7b 100644
--- a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -36,13 +36,13 @@ import org.apache.james.jmap.methods.RequestHandler;
import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
import org.apache.james.jmap.utils.HtmlTextExtractor;
import org.apache.james.jmap.utils.JsoupHtmlTextExtractor;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
-import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
import org.apache.james.jwt.JwtConfiguration;
import org.apache.james.lifecycle.api.Configurable;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
+import org.apache.james.mailbox.SystemMailboxesProvider;
+import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.modules.server.CamelMailetContainerModule;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
import org.apache.james.server.core.configuration.FileConfigurationProvider;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxRoleNotFoundException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxRoleNotFoundException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxRoleNotFoundException.java
deleted file mode 100644
index 89d63a1..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/exceptions/MailboxRoleNotFoundException.java
+++ /dev/null
@@ -1,36 +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.jmap.exceptions;
-
-import org.apache.james.mailbox.Role;
-
-public class MailboxRoleNotFoundException extends RuntimeException {
-
- private final Role role;
-
- public MailboxRoleNotFoundException(Role role) {
- super(String.format("Could not find any mailbox with role '%s'", role.serialize()));
- this.role = role;
- }
-
- public Role getRole() {
- return role;
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
index b828900..7f71259 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SendMDNProcessor.java
@@ -37,11 +37,11 @@ import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.OverQuotaException;
import org.apache.james.mailbox.model.Attachment;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 090dfed..f4f30ef 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -49,11 +49,11 @@ import org.apache.james.jmap.model.SetMessagesError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.jmap.model.SetMessagesResponse.Builder;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.exception.OverQuotaException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index fd7f17b..f183f9e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -46,12 +46,12 @@ import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.jmap.model.UpdateMessagePatch;
import org.apache.james.jmap.utils.KeywordsCombiner;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.exception.OverQuotaException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
index 814ba8c..a42af65 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -24,15 +24,15 @@ import java.util.List;
import javax.mail.Flags;
import javax.mail.Flags.Flag;
-import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxRoleNotFoundException;
import org.apache.james.mailbox.model.FetchGroupImpl;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageId;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
index 5114fe8..ee8128e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
@@ -21,9 +21,9 @@ package org.apache.james.jmap.send;
import javax.inject.Inject;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MessageIdManager;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.model.MessageId.Factory;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
deleted file mode 100644
index 57e41bf..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
+++ /dev/null
@@ -1,37 +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.jmap.utils;
-
-import java.util.stream.Stream;
-
-import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.Role;
-import org.apache.james.mailbox.exception.MailboxException;
-
-public interface SystemMailboxesProvider {
- Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException;
-
- default MessageManager findMailbox(Role role, MailboxSession session) throws MailboxException {
- return getMailboxByRole(role, session).findAny()
- .orElseThrow(() -> new MailboxRoleNotFoundException(role));
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
deleted file mode 100644
index 50bd057..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
+++ /dev/null
@@ -1,78 +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.jmap.utils;
-
-import java.util.stream.Stream;
-
-import javax.inject.Inject;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.Role;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
-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.model.search.PrefixedWildcard;
-
-import com.github.fge.lambdas.Throwing;
-import com.github.fge.lambdas.functions.ThrowingFunction;
-import com.google.common.annotations.VisibleForTesting;
-
-public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
-
- private final MailboxManager mailboxManager;
-
- @Inject
- @VisibleForTesting
- public SystemMailboxesProviderImpl(MailboxManager mailboxManager) {
- this.mailboxManager = mailboxManager;
- }
-
- @Override
- public Stream<MessageManager> getMailboxByRole(Role aRole, MailboxSession session) throws MailboxException {
- MailboxPath mailboxPath = MailboxPath.forUser(session.getUser().getUserName(), aRole.getDefaultMailbox());
- try {
- return Stream.of(mailboxManager.getMailbox(mailboxPath, session));
- } catch (MailboxNotFoundException e) {
- return searchMessageManagerByMailboxRole(aRole, session);
- }
- }
-
- private boolean hasRole(Role aRole, MailboxPath mailBoxPath) {
- return Role.from(mailBoxPath.getName())
- .map(aRole::equals)
- .orElse(false);
- }
-
- private Stream<MessageManager> searchMessageManagerByMailboxRole(Role aRole, MailboxSession session) throws MailboxException {
- ThrowingFunction<MailboxPath, MessageManager> loadMailbox = path -> mailboxManager.getMailbox(path, session);
- MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
- .expression(new PrefixedWildcard(aRole.getDefaultMailbox()))
- .build();
- return mailboxManager.search(mailboxQuery, session)
- .stream()
- .map(MailboxMetaData::getPath)
- .filter(path -> hasRole(aRole, path))
- .map(Throwing.function(loadMailbox).sneakyThrow());
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index 0c93184..b93ed0f 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -46,7 +46,6 @@ import org.apache.james.jmap.send.MailFactory;
import org.apache.james.jmap.send.MailMetadata;
import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.HtmlTextExtractor;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.BlobManager;
import org.apache.james.mailbox.MailboxManager;
@@ -55,6 +54,7 @@ import org.apache.james.mailbox.MessageIdManager;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.Role;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.inmemory.InMemoryId;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
index 8fde32d..13c2989 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
@@ -28,8 +28,8 @@ import org.apache.james.jmap.model.MessageProperties;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.jmap.model.UpdateMessagePatch;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MessageIdManager;
+import org.apache.james.mailbox.SystemMailboxesProvider;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.TestMessageId;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
index 9bdec79..80affe6 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
@@ -32,8 +32,6 @@ import java.nio.charset.StandardCharsets;
import javax.mail.Flags;
import javax.mail.Flags.Flag;
-import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
-import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
import org.apache.james.mailbox.DefaultMailboxes;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageIdManager;
@@ -42,6 +40,7 @@ import org.apache.james.mailbox.MessageManager.AppendCommand;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxRoleNotFoundException;
import org.apache.james.mailbox.inmemory.InMemoryMessageId;
import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
import org.apache.james.mailbox.model.ComposedMessageId;
@@ -52,6 +51,7 @@ import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResultIterator;
import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.SystemMailboxesProviderImpl;
import org.apache.james.mime4j.dom.Message;
import org.apache.james.queue.api.MailQueue;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
http://git-wip-us.apache.org/repos/asf/james-project/blob/3412083e/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
deleted file mode 100644
index 04dbaa0..0000000
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/SystemMailboxesProviderImplTest.java
+++ /dev/null
@@ -1,74 +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.jmap.utils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.Role;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
-import org.apache.james.mailbox.fixture.MailboxFixture;
-import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class SystemMailboxesProviderImplTest {
-
- private MailboxSession mailboxSession = new MockMailboxSession(MailboxFixture.ALICE);
- private SystemMailboxesProviderImpl systemMailboxProvider;
-
- private MailboxManager mailboxManager;
-
- private MessageManager inboxMessageManager;
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Before
- public void setUp() throws Exception {
- mailboxManager = mock(MailboxManager.class);
- inboxMessageManager = mock(MessageManager.class);
-
- systemMailboxProvider = new SystemMailboxesProviderImpl(mailboxManager);
- }
-
- @Test
- public void getMailboxByRoleShouldReturnEmptyWhenNoMailbox() throws Exception {
- when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenThrow(MailboxNotFoundException.class);
-
- assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession)).isEmpty();
- }
-
- @Test
- public void getMailboxByRoleShouldReturnMailboxByRole() throws Exception {
- when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenReturn(inboxMessageManager);
-
- assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession))
- .hasSize(1)
- .containsOnly(inboxMessageManager);
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/14] james-project git commit: MAILBOX-355 SelectedMailboxImpl
should not track MailboxPath change
Posted by bt...@apache.org.
MAILBOX-355 SelectedMailboxImpl should not track MailboxPath change
We should rather read it from the MailboxManager.
Note that SelectedMailbox::getPath now throws. Then error handling can not rely on it.
Logging mailboxId is a good solution for this.
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e7e5ba68
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e7e5ba68
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e7e5ba68
Branch: refs/heads/master
Commit: e7e5ba68ad459120e9ebb5ea4a8705ac4a705103
Parents: 6fe8891
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Dec 4 09:58:50 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Dec 5 16:34:25 2018 +0700
----------------------------------------------------------------------
.../james/imap/api/process/SelectedMailbox.java | 3 ++-
.../processor/AbstractMessageRangeProcessor.java | 4 ++--
.../james/imap/processor/CloseProcessor.java | 2 +-
.../james/imap/processor/ExpungeProcessor.java | 2 +-
.../james/imap/processor/IdleProcessor.java | 4 ++--
.../james/imap/processor/SearchProcessor.java | 5 +++--
.../james/imap/processor/StoreProcessor.java | 4 ++--
.../imap/processor/base/SelectedMailboxImpl.java | 18 +++++++-----------
.../imap/processor/fetch/FetchProcessor.java | 4 ++--
.../processor/base/MailboxEventAnalyserTest.java | 6 ++++--
.../processor/base/SelectedMailboxImplTest.java | 4 ++--
.../james/imapserver/netty/IMAPMDCContext.java | 2 +-
12 files changed, 29 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
index 4157de8..a0a1425 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/process/SelectedMailbox.java
@@ -25,6 +25,7 @@ import java.util.Optional;
import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
@@ -89,7 +90,7 @@ public interface SelectedMailbox {
*
* @return path
*/
- MailboxPath getPath();
+ MailboxPath getPath() throws MailboxException;
/**
* Return the mailboxId of the selected Mailbox.
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
index d76c76e..b3ec4d7 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
@@ -107,11 +107,11 @@ public abstract class AbstractMessageRangeProcessor<M extends AbstractMessageRan
}
} catch (MessageRangeException e) {
LOGGER.debug("{} failed from mailbox {} to {} for invalid sequence-set {}",
- getOperationName(), currentMailbox.getPath(), targetMailbox, idSet, e);
+ getOperationName(), currentMailbox.getMailboxId(), targetMailbox, idSet, e);
taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
LOGGER.error("{} failed from mailbox {} to {} for sequence-set {}",
- getOperationName(), currentMailbox.getPath(), targetMailbox, idSet, e);
+ getOperationName(), currentMailbox.getMailboxId(), targetMailbox, idSet, e);
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
index 2bb518c..19fa829 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
@@ -64,7 +64,7 @@ public class CloseProcessor extends AbstractMailboxProcessor<CloseRequest> {
}
} catch (MailboxException e) {
- LOGGER.error("Close failed for mailbox {}", session.getSelected().getPath(), e);
+ LOGGER.error("Close failed for mailbox {}", session.getSelected().getMailboxId(), e);
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
index aa4d577..a0ab2fa 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
@@ -103,7 +103,7 @@ public class ExpungeProcessor extends AbstractMailboxProcessor<ExpungeRequest> i
LOGGER.debug("Expunge failed", e);
taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
- LOGGER.error("Expunge failed for mailbox {}", session.getSelected().getPath(), e);
+ LOGGER.error("Expunge failed for mailbox {}", session.getSelected().getMailboxId(), e);
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
index 684c9e9..0018458 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
@@ -114,7 +114,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme
try {
mailboxManager.removeListener(sm.getMailboxId(), idleListener, mailboxSession);
} catch (MailboxException e) {
- LOGGER.error("Unable to remove idle listener for mailbox {}", sm.getPath(), e);
+ LOGGER.error("Unable to remove idle listener for mailbox {}", sm.getMailboxId(), e);
}
}
session.popLineHandler();
@@ -163,7 +163,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme
} catch (MailboxException e) {
- LOGGER.error("Enable idle for {} failed", session.getSelected().getPath(), e);
+ LOGGER.error("Enable idle for {} failed", session.getSelected().getMailboxId(), e);
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
index c7e9301..f074eec 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.TreeSet;
+
import javax.mail.Flags.Flag;
import org.apache.james.imap.api.ImapCommand;
@@ -203,10 +204,10 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
unsolicitedResponses(session, responder, omitExpunged, useUids);
okComplete(command, tag, responder);
} catch (MessageRangeException e) {
- LOGGER.debug("Search failed in mailbox {} because of an invalid sequence-set ", session.getSelected().getPath(), e);
+ LOGGER.debug("Search failed in mailbox {} because of an invalid sequence-set ", session.getSelected().getMailboxId(), e);
taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
- LOGGER.error("Search failed in mailbox {}", session.getSelected().getPath(), e);
+ LOGGER.error("Search failed in mailbox {}", session.getSelected().getMailboxId(), e);
no(command, tag, responder, HumanReadableText.SEARCH_FAILED);
if (resultOptions.contains(SearchResultOption.SAVE)) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
index c15fa1f..27e86d5 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
@@ -209,10 +209,10 @@ public class StoreProcessor extends AbstractMailboxProcessor<StoreRequest> {
}
}
} catch (MessageRangeException e) {
- LOGGER.debug("Store failed for mailbox {} because of an invalid sequence-set {}", session.getSelected().getPath(), idSet, e);
+ LOGGER.debug("Store failed for mailbox {} because of an invalid sequence-set {}", session.getSelected().getMailboxId(), idSet, e);
taggedBad(imapCommand, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
- LOGGER.error("Store failed for mailbox {} and sequence-set {}", session.getSelected().getPath(), idSet, e);
+ LOGGER.error("Store failed for mailbox {} and sequence-set {}", session.getSelected().getMailboxId(), idSet, e);
no(imapCommand, tag, responder, HumanReadableText.SAVE_FAILED);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
index f0eb68e..d2aabf1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
@@ -63,7 +63,6 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
private final MailboxManager mailboxManager;
private final MailboxId mailboxId;
- private MailboxPath path;
private final ImapSession session;
@@ -79,6 +78,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
private final Flags applicableFlags;
private boolean applicableFlagsChanged;
+ private final MailboxSession mailboxSession;
public SelectedMailboxImpl(MailboxManager mailboxManager, ImapSession session, MailboxPath path) throws MailboxException {
this.session = session;
@@ -87,9 +87,8 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
// Ignore events from our session
setSilentFlagChanges(true);
- this.path = path;
- MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+ mailboxSession = ImapSessionUtils.getMailboxSession(session);
uidMsnConverter = new UidMsnConverter();
@@ -162,8 +161,8 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
}
@Override
- public synchronized MailboxPath getPath() {
- return path;
+ public MailboxPath getPath() throws MailboxException {
+ return mailboxManager.getMailbox(mailboxId, mailboxSession).getMailboxPath();
}
@Override
@@ -329,7 +328,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
private void mailboxEvent(MailboxEvent mailboxEvent) {
// Check if the event was for the mailbox we are observing
- if (mailboxEvent.getMailboxPath().equals(getPath())) {
+ if (mailboxEvent.getMailboxId().equals(getMailboxId())) {
final long eventSessionId = mailboxEvent.getSession().getSessionId();
if (mailboxEvent instanceof MessageEvent) {
final MessageEvent messageEvent = (MessageEvent) mailboxEvent;
@@ -367,8 +366,8 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
while (flags.hasNext()) {
if (Flag.RECENT.equals(flags.next())) {
- MailboxPath path = sm.getPath();
- if (path != null && path.equals(mailboxEvent.getMailboxPath())) {
+ MailboxId id = sm.getMailboxId();
+ if (id != null && id.equals(mailboxEvent.getMailboxId())) {
sm.addRecent(u.getUid());
}
}
@@ -404,9 +403,6 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
if (eventSessionId != sessionId) {
isDeletedByOtherSession = true;
}
- } else if (mailboxEvent instanceof MailboxRenamed) {
- final MailboxRenamed mailboxRenamed = (MailboxRenamed) mailboxEvent;
- path = mailboxRenamed.getNewPath();
}
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index 611f2f1..0a32dc3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -125,10 +125,10 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
unsolicitedResponses(session, responder, omitExpunged, useUids);
okComplete(command, tag, responder);
} catch (MessageRangeException e) {
- LOGGER.debug("Fetch failed for mailbox {} because of invalid sequence-set {}", session.getSelected().getPath(), idSet, e);
+ LOGGER.debug("Fetch failed for mailbox {} because of invalid sequence-set {}", session.getSelected().getMailboxId(), idSet, e);
taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
- LOGGER.error("Fetch failed for mailbox {} and sequence-set {}", session.getSelected().getPath(), idSet, e);
+ LOGGER.error("Fetch failed for mailbox {} and sequence-set {}", session.getSelected().getMailboxId(), idSet, e);
no(command, tag, responder, HumanReadableText.SEARCH_FAILED);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 48c6fd8..5cd3449 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -105,13 +105,15 @@ public class MailboxEventAnalyserTest {
.thenReturn(messageManager);
when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))
.thenReturn(messageManager);
+ when(mailboxManager.getMailbox(any(MailboxId.class), any(MailboxSession.class)))
+ .thenReturn(messageManager);
MessageResult messageResult = mock(MessageResult.class);
when(messageResult.getMailboxId()).thenReturn(MAILBOX_ID);
when(messageResult.getUid()).thenReturn(MESSAGE_UID);
- when(messageManager.getApplicableFlags(any()))
- .thenReturn(new Flags());
+ when(messageManager.getApplicableFlags(any())).thenReturn(new Flags());
+ when(messageManager.getId()).thenReturn(MAILBOX_ID);
when(messageManager.search(any(), any()))
.thenReturn(ImmutableList.of(MESSAGE_UID).iterator());
when(messageManager.getMessages(any(), any(), any()))
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 12daae0..e923b2a 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -97,8 +97,8 @@ public class SelectedMailboxImplTest {
when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mock(MailboxSession.class));
- when(mailbox.generateAssociatedPath())
- .thenReturn(mailboxPath);
+ when(mailbox.generateAssociatedPath()).thenReturn(mailboxPath);
+ when(mailbox.getMailboxId()).thenReturn(mailboxId);
}
@After
http://git-wip-us.apache.org/repos/asf/james-project/blob/e7e5ba68/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
index 35ccf32..a0d5710 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
@@ -72,7 +72,7 @@ public class IMAPMDCContext {
private static MDCBuilder from(Optional<SelectedMailbox> selectedMailbox) {
return selectedMailbox
.map(value -> MDCBuilder.create()
- .addContext("selectedMailbox", value.getPath().asString()))
+ .addContext("selectedMailbox", value.getMailboxId().serialize()))
.orElse(MDCBuilder.create());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org