james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/5] james-project git commit: JAMES-2121 Also slightly improve internal add method for mappings
Date Fri, 01 Sep 2017 10:40:07 GMT
JAMES-2121 Also slightly improve internal add method for mappings


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/589f347f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/589f347f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/589f347f

Branch: refs/heads/master
Commit: 589f347f4cb113418087dc496c41ae0112c30ada
Parents: abcaa55
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Aug 30 17:21:34 2017 +0200
Committer: benwa <btellier@linagora.com>
Committed: Fri Sep 1 17:26:22 2017 +0700

----------------------------------------------------------------------
 .../CassandraRecipientRewriteTable.java         |  4 ++--
 .../rrt/file/XMLRecipientRewriteTable.java      |  2 +-
 .../rrt/hbase/HBaseRecipientRewriteTable.java   |  4 ++--
 .../rrt/jdbc/JDBCRecipientRewriteTable.java     | 12 ++++------
 .../james/rrt/jpa/JPARecipientRewriteTable.java |  9 +++----
 .../rrt/lib/AbstractRecipientRewriteTable.java  | 10 ++++----
 .../org/apache/james/rrt/lib/MappingsImpl.java  |  2 +-
 .../rrt/memory/MemoryRecipientRewriteTable.java | 25 +++++++++-----------
 8 files changed, 29 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
index 1c124b5..963060a 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
@@ -91,11 +91,11 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
     }
 
     @Override
-    protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         executor.executeVoid(insertStatement.bind()
             .setString(USER, getFixedUser(user))
             .setString(DOMAIN, getFixedDomain(domain))
-            .setString(MAPPING, mapping))
+            .setString(MAPPING, mapping.asString()))
             .join();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
index 99dba38..bab777e 100644
--- a/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
+++ b/server/data/data-file/src/main/java/org/apache/james/rrt/file/XMLRecipientRewriteTable.java
@@ -92,7 +92,7 @@ public class XMLRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     }
 
     @Override
-    protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         throw new RecipientRewriteTableException("Read-Only implementation");
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
index 0ab3eb3..93709ab 100644
--- a/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
+++ b/server/data/data-hbase/src/main/java/org/apache/james/rrt/hbase/HBaseRecipientRewriteTable.java
@@ -58,7 +58,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
      * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#addMappingInternal(String,
String, String)
      */
     @Override
-    protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
@@ -66,7 +66,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doAddMapping(fixedUser, fixedDomain, mapping);
+            doAddMapping(fixedUser, fixedDomain, mapping.asString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
index 2f2f6b1..fccd1e7 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/rrt/jdbc/JDBCRecipientRewriteTable.java
@@ -194,20 +194,16 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable
{
 
     }
 
-    /**
-     * @throws RecipientRewriteTableException
-     * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#addMappingInternal(String,
-     *      String, String)
-     */
-    protected void addMappingInternal(String user, String domain, String regex) throws RecipientRewriteTableException
{
+    @Override
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
         if (map != null && map.size() != 0) {
-            Mappings updatedMappings = MappingsImpl.from(map).add(regex).build();
+            Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         }
-        doAddMapping(fixedUser, fixedDomain, regex);
+        doAddMapping(fixedUser, fixedDomain, mapping.asString());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
index aac5456..8e11b95 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/rrt/jpa/JPARecipientRewriteTable.java
@@ -61,11 +61,8 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable
{
         this.entityManagerFactory = entityManagerFactory;
     }
 
-    /**
-     * @throws RecipientRewriteTableException
-     * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#addMappingInternal(String,
String, String)
-     */
-    protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    @Override
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
@@ -73,7 +70,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable
{
             Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build();
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doAddMapping(fixedUser, fixedDomain, mapping);
+            doAddMapping(fixedUser, fixedDomain, mapping.asString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/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 5fae77e..ff40572 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
@@ -195,7 +195,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
 
         checkMapping(user, domain, MappingImpl.regex(regex));
         LOGGER.info("Add regex mapping => " + regex + " for user: " + user + " domain:
" + domain);
-        addMappingInternal(user, domain, RecipientRewriteTable.REGEX_PREFIX + regex);
+        addMappingInternal(user, domain, MappingImpl.regex(regex));
 
     }
 
@@ -227,7 +227,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
         }
         checkMapping(user, domain, MappingImpl.address(address));
         LOGGER.info("Add address mapping => " + address + " for user: " + user + " domain:
" + domain);
-        addMappingInternal(user, domain, address);
+        addMappingInternal(user, domain, MappingImpl.address(address));
 
     }
 
@@ -254,7 +254,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
     public void addErrorMapping(String user, String domain, String error) throws RecipientRewriteTableException
{
         checkMapping(user, domain, MappingImpl.error(error));
         LOGGER.info("Add error mapping => " + error + " for user: " + user + " domain:
" + domain);
-        addMappingInternal(user, domain, RecipientRewriteTable.ERROR_PREFIX + error);
+        addMappingInternal(user, domain, MappingImpl.error(error));
 
     }
 
@@ -339,7 +339,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      */
     public void addAliasDomainMapping(String aliasDomain, String realDomain) throws RecipientRewriteTableException
{
         LOGGER.info("Add domain mapping: " + aliasDomain + " => " + realDomain);
-        addMappingInternal(null, aliasDomain, RecipientRewriteTable.ALIASDOMAIN_PREFIX +
realDomain);
+        addMappingInternal(null, aliasDomain, MappingImpl.domain(realDomain));
     }
 
     /**
@@ -362,7 +362,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      *            the mapping
      * @throws RecipientRewriteTableException
      */
-    protected abstract void addMappingInternal(String user, String domain, String mapping)
throws RecipientRewriteTableException;
+    protected abstract void addMappingInternal(String user, String domain, Mapping mapping)
throws RecipientRewriteTableException;
 
     /**
      * Remove mapping

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
index c8932de..2267829 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java
@@ -68,7 +68,7 @@ public class MappingsImpl implements Mappings, Serializable {
             .build();
     }
     
-    private static MappingsImpl fromMappings(Stream<Mapping> mappings) {
+    public static MappingsImpl fromMappings(Stream<Mapping> mappings) {
         return mappings
             .reduce(builder(), (builder, mapping) -> builder.add(mapping), (builder1,
builder2) -> builder1.addAll(builder2.build()))
             .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/589f347f/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
index 84525ab..a95de2d 100644
--- a/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
+++ b/server/data/data-memory/src/main/java/org/apache/james/rrt/memory/MemoryRecipientRewriteTable.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Stream;
 
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
@@ -32,8 +33,6 @@ import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 
 import com.google.common.base.Objects;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimaps;
 
@@ -42,9 +41,9 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     private static class InMemoryMappingEntry {
         private final String user;
         private final String domain;
-        private final String mapping;
+        private final Mapping mapping;
 
-        public InMemoryMappingEntry(String user, String domain, String mapping) {
+        public InMemoryMappingEntry(String user, String domain, Mapping mapping) {
             this.user = user;
             this.domain = domain;
             this.mapping = mapping;
@@ -58,7 +57,7 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             return domain;
         }
 
-        public String getMapping() {
+        public Mapping getMapping() {
             return mapping;
         }
 
@@ -92,13 +91,13 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     }
 
     @Override
-    protected void addMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void addMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         mappingEntries.add(new InMemoryMappingEntry(getFixedUser(user), getFixedDomain(domain),
mapping));
     }
 
     @Override
     protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
-        mappingEntries.remove(new InMemoryMappingEntry(getFixedUser(user), getFixedDomain(domain),
mapping.asString()));
+        mappingEntries.remove(new InMemoryMappingEntry(getFixedUser(user), getFixedDomain(domain),
mapping));
     }
 
     @Override
@@ -125,7 +124,7 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
         Map<String, Collection<Mappings>> userMappingsMap = Multimaps.transformEntries(
             Multimaps.index(mappingEntries, InMemoryMappingEntry::asKey),
             (Maps.EntryTransformer<String, InMemoryMappingEntry, Mappings>)
-                (s, mappingEntry) -> MappingsImpl.fromRawString(mappingEntry.getMapping()))
+                (s, mappingEntry) -> MappingsImpl.fromMappings(Stream.of(mappingEntry.getMapping())))
             .asMap();
         return Maps.transformEntries(userMappingsMap,
             (s, mappingsList) -> {
@@ -138,12 +137,10 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     }
 
     private Optional<Mappings> retrieveMappings(final String user, final String domain)
{
-        List<String> userEntries = Lists.newArrayList(
-            Iterables.transform(
-                Iterables.filter(mappingEntries,
-                    mappingEntry -> user.equals(mappingEntry.getUser()) && domain.equals(mappingEntry.getDomain())),
-                InMemoryMappingEntry::getMapping));
-        return MappingsImpl.fromCollection(userEntries).toOptional();
+        Stream<Mapping> userEntries = mappingEntries.stream()
+            .filter(mappingEntry -> user.equals(mappingEntry.getUser()) && domain.equals(mappingEntry.getDomain()))
+            .map(InMemoryMappingEntry::getMapping);
+        return MappingsImpl.fromMappings(userEntries).toOptional();
     }
 
 }


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