james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [03/14] james-project git commit: JAMES-2596 Add listSources API to RecipientRewriteTable
Date Wed, 05 Dec 2018 09:44:34 GMT
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 <dphamhoang@linagora.com>
Authored: Fri Nov 16 17:56:35 2018 +0700
Committer: Benoit Tellier <btellier@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


Mime
View raw message