james-server-dev mailing list archives

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


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

Branch: refs/heads/master
Commit: abcaa55878342e8c4b3cd2d171a6e9ecf827db71
Parents: d899575
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Aug 30 16:57:38 2017 +0200
Committer: benwa <btellier@linagora.com>
Committed: Fri Sep 1 17:26:22 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/rrt/lib/Mappings.java    |  2 +-
 .../cassandra/CassandraRecipientRewriteTable.java  |  5 +++--
 .../james/rrt/file/XMLRecipientRewriteTable.java   |  3 ++-
 .../rrt/file/XMLRecipientRewriteTableTest.java     |  9 +++++----
 .../rrt/hbase/HBaseRecipientRewriteTable.java      | 17 +++++++++--------
 .../james/rrt/jdbc/JDBCRecipientRewriteTable.java  | 11 ++++-------
 .../james/rrt/jpa/JPARecipientRewriteTable.java    | 10 ++++------
 .../rrt/lib/AbstractRecipientRewriteTable.java     | 10 +++++-----
 .../java/org/apache/james/rrt/lib/MappingImpl.java |  1 -
 .../org/apache/james/rrt/lib/MappingsImpl.java     |  3 +--
 .../rrt/memory/MemoryRecipientRewriteTable.java    |  5 +++--
 11 files changed, 37 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
index a4f27ff..4fdd8f1 100644
--- a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
+++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/Mappings.java
@@ -30,7 +30,7 @@ public interface Mappings extends Iterable<Mapping> {
 
     int size();
 
-    Mappings remove(String mapping);
+    Mappings remove(Mapping mapping);
 
     boolean isEmpty();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 60642e2..1c124b5 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
@@ -36,6 +36,7 @@ import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 
@@ -99,11 +100,11 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
     }
 
     @Override
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         executor.executeVoid(deleteStatement.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/abcaa558/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 6132f3f..99dba38 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
@@ -25,6 +25,7 @@ import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.rrt.lib.RecipientRewriteTableUtil;
@@ -96,7 +97,7 @@ public class XMLRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     }
 
     @Override
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    protected void removeMappingInternal(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/abcaa558/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
index 108c191..0a11783 100644
--- a/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/rrt/file/XMLRecipientRewriteTableTest.java
@@ -26,6 +26,7 @@ import org.apache.james.rrt.api.RecipientRewriteTable;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest;
+import org.apache.james.rrt.lib.MappingImpl;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.rrt.lib.MappingsImpl.Builder;
@@ -110,13 +111,13 @@ public class XMLRecipientRewriteTableTest extends AbstractRecipientRewriteTableT
         removeMappingsFromConfig(user, domain, mappings);
 
         if (type == ERROR_TYPE) {
-            mappings = mappings.remove(RecipientRewriteTable.ERROR_PREFIX + mapping);
+            mappings = mappings.remove(MappingImpl.error(mapping));
         } else if (type == REGEX_TYPE) {
-            mappings = mappings.remove(RecipientRewriteTable.REGEX_PREFIX + mapping);
+            mappings = mappings.remove(MappingImpl.regex(mapping));
         } else if (type == ADDRESS_TYPE) {
-            mappings = mappings.remove(mapping);
+            mappings = mappings.remove(MappingImpl.address(mapping));
         } else if (type == ALIASDOMAIN_TYPE) {
-            mappings = mappings.remove(RecipientRewriteTable.ALIASDOMAIN_PREFIX + mapping);
+            mappings = mappings.remove(MappingImpl.domain(mapping));
         }
 
         if (mappings.size() > 0) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 42731c2..0ab3eb3 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
@@ -24,12 +24,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 
-import org.apache.james.rrt.api.RecipientRewriteTableException;
-import org.apache.james.rrt.hbase.def.HRecipientRewriteTable;
-import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
-import org.apache.james.rrt.lib.Mappings;
-import org.apache.james.rrt.lib.MappingsImpl;
-import org.apache.james.system.hbase.TablePool;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
@@ -39,6 +33,13 @@ import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.james.rrt.api.RecipientRewriteTableException;
+import org.apache.james.rrt.hbase.def.HRecipientRewriteTable;
+import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
+import org.apache.james.rrt.lib.Mappings;
+import org.apache.james.rrt.lib.MappingsImpl;
+import org.apache.james.system.hbase.TablePool;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -206,7 +207,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
      * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String,
String, String)
      */
     @Override
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
+    protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
             RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
@@ -215,7 +216,7 @@ public class HBaseRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doRemoveMapping(fixedUser, fixedDomain, mapping);
+            doRemoveMapping(fixedUser, fixedDomain, mapping.asString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 3c27de2..2f2f6b1 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
@@ -38,6 +38,7 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.util.sql.JDBCUtil;
@@ -310,12 +311,8 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable
{
         return null;
     }
 
-    /**
-     * @throws RecipientRewriteTableException
-     * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String,
-     *      String, String)
-     */
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    @Override
+    protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
@@ -323,7 +320,7 @@ public class JDBCRecipientRewriteTable extends AbstractRecipientRewriteTable
{
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doRemoveMapping(fixedUser, fixedDomain, mapping);
+            doRemoveMapping(fixedUser, fixedDomain, mapping.asString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 b19760e..aac5456 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
@@ -32,6 +32,7 @@ import javax.persistence.PersistenceUnit;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.jpa.model.JPARecipientRewrite;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.slf4j.Logger;
@@ -171,11 +172,8 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable
{
         return null;
     }
 
-    /**
-     * @throws RecipientRewriteTableException
-     * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#removeMappingInternal(String,
String, String)
-     */
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
+    @Override
+    protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
         String fixedUser = getFixedUser(user);
         String fixedDomain = getFixedDomain(domain);
         Mappings map = getUserDomainMappings(fixedUser, fixedDomain);
@@ -183,7 +181,7 @@ public class JPARecipientRewriteTable extends AbstractRecipientRewriteTable
{
             Mappings updatedMappings = map.remove(mapping);
             doUpdateMapping(fixedUser, fixedDomain, updatedMappings.serialize());
         } else {
-            doRemoveMapping(fixedUser, fixedDomain, mapping);
+            doRemoveMapping(fixedUser, fixedDomain, mapping.asString());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 6af844b..5fae77e 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
@@ -205,7 +205,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      */
     public void removeRegexMapping(String user, String domain, String regex) throws RecipientRewriteTableException
{
         LOGGER.info("Remove regex mapping => " + regex + " for user: " + user + " domain:
" + domain);
-        removeMappingInternal(user, domain, RecipientRewriteTable.REGEX_PREFIX + regex);
+        removeMappingInternal(user, domain, MappingImpl.regex(regex));
     }
 
     /**
@@ -244,7 +244,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
             }
         }
         LOGGER.info("Remove address mapping => " + address + " for user: " + user + "
domain: " + domain);
-        removeMappingInternal(user, domain, address);
+        removeMappingInternal(user, domain, MappingImpl.address(address));
     }
 
     /**
@@ -264,7 +264,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      */
     public void removeErrorMapping(String user, String domain, String error) throws RecipientRewriteTableException
{
         LOGGER.info("Remove error mapping => " + error + " for user: " + user + " domain:
" + domain);
-        removeMappingInternal(user, domain, RecipientRewriteTable.ERROR_PREFIX + error);
+        removeMappingInternal(user, domain, MappingImpl.error(error));
     }
 
     /**
@@ -348,7 +348,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      */
     public void removeAliasDomainMapping(String aliasDomain, String realDomain) throws RecipientRewriteTableException
{
         LOGGER.info("Remove domain mapping: " + aliasDomain + " => " + realDomain);
-        removeMappingInternal(null, aliasDomain, RecipientRewriteTable.ALIASDOMAIN_PREFIX
+ realDomain);
+        removeMappingInternal(null, aliasDomain, MappingImpl.domain(realDomain));
     }
 
     /**
@@ -375,7 +375,7 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT
      *            the mapping
      * @throws RecipientRewriteTableException
      */
-    protected abstract void removeMappingInternal(String user, String domain, String mapping)
throws RecipientRewriteTableException;
+    protected abstract void removeMappingInternal(String user, String domain, Mapping mapping)
throws RecipientRewriteTableException;
 
     /**
      * Return Collection of all mappings for the given username and domain

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
index ebf1fd5..4f0c97a 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingImpl.java
@@ -34,7 +34,6 @@ public class MappingImpl implements Mapping, Serializable {
 
     private static final String ADDRESS_PREFIX = "";
 
-
     public static MappingImpl of(String mapping) {
         return new MappingImpl("", mapping);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 a9b61da..c8932de 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
@@ -137,8 +137,7 @@ public class MappingsImpl implements Mappings, Serializable {
     }
 
     @Override
-    public Mappings remove(String mappingAsString) {
-        MappingImpl mapping = MappingImpl.of(mappingAsString);
+    public Mappings remove(Mapping mapping) {
         if (mappings.contains(mapping)) {
             ArrayList<Mapping> updatedMappings = Lists.newArrayList(mappings);
             updatedMappings.remove(mapping);

http://git-wip-us.apache.org/repos/asf/james-project/blob/abcaa558/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 86b07ab..84525ab 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
@@ -27,6 +27,7 @@ import java.util.Optional;
 
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.AbstractRecipientRewriteTable;
+import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 
@@ -96,8 +97,8 @@ public class MemoryRecipientRewriteTable extends AbstractRecipientRewriteTable
{
     }
 
     @Override
-    protected void removeMappingInternal(String user, String domain, String mapping) throws
RecipientRewriteTableException {
-        mappingEntries.remove(new InMemoryMappingEntry(getFixedUser(user), getFixedDomain(domain),
mapping));
+    protected void removeMappingInternal(String user, String domain, Mapping mapping) throws
RecipientRewriteTableException {
+        mappingEntries.remove(new InMemoryMappingEntry(getFixedUser(user), getFixedDomain(domain),
mapping.asString()));
     }
 
     @Override


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