james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [09/11] james-project git commit: MAILBOX-316 MailboxMapper should return an aclDiff when setACL and later on we use aclDiff for listener
Date Wed, 15 Nov 2017 08:02:07 GMT
MAILBOX-316 MailboxMapper should return an aclDiff when setACL
and later on we use aclDiff for listener


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

Branch: refs/heads/master
Commit: 93ad42bb39908630fe0e00bf86d874ccfc29b078
Parents: fdeaa5f
Author: quynhn <qnguyen@linagora.com>
Authored: Thu Nov 9 17:22:34 2017 +0700
Committer: quynhn <qnguyen@linagora.com>
Committed: Wed Nov 15 09:36:39 2017 +0700

----------------------------------------------------------------------
 .../mailbox/caching/CachingMailboxMapper.java   |  4 ++-
 .../cassandra/mail/CassandraMailboxMapper.java  |  4 +--
 .../mailbox/hbase/mail/HBaseMailboxMapper.java  |  4 ++-
 .../mailbox/jcr/mail/JCRMailboxMapper.java      |  4 ++-
 .../mailbox/jpa/mail/JPAMailboxMapper.java      |  4 ++-
 .../jpa/mail/TransactionalMailboxMapper.java    |  4 +--
 .../maildir/mail/MaildirMailboxMapper.java      |  4 ++-
 .../inmemory/mail/InMemoryMailboxMapper.java    |  4 ++-
 .../james/mailbox/store/StoreRightManager.java  |  4 +--
 .../james/mailbox/store/mail/MailboxMapper.java |  2 +-
 .../store/TestMailboxSessionMapperFactory.java  |  2 +-
 .../store/mail/model/MailboxMapperACLTest.java  | 33 ++++++++++++++++++++
 12 files changed, 58 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
index 3e8cb23..0d85d87 100644
--- a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
+++ b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMailboxMapper.java
@@ -117,8 +117,10 @@ public class CachingMailboxMapper implements MailboxMapper {
 	}
 
 	@Override
-	public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+	public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+		MailboxACL oldMailboxAcl = mailbox.getACL();
 		mailbox.setACL(mailboxACL);
+		return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
 	}
 
 	private void invalidate(Mailbox mailbox) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
index 05b9440..c9566f6 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
@@ -228,9 +228,9 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
         CassandraId cassandraId = (CassandraId) mailbox.getMailboxId();
-        cassandraACLMapper.setACL(cassandraId, mailboxACL);
+        return cassandraACLMapper.setACL(cassandraId, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
index a58e01a..b5926e4 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMapper.java
@@ -426,8 +426,10 @@ public class HBaseMailboxMapper extends HBaseNonTransactionalMapper implements
M
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        MailboxACL oldMailboxAcl = mailbox.getACL();
         mailbox.setACL(mailboxACL);
+        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
index 099178b..7f36287 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMailboxMapper.java
@@ -263,8 +263,10 @@ public class JCRMailboxMapper extends AbstractJCRScalingMapper implements
Mailbo
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        MailboxACL oldMailboxAcl = mailbox.getACL();
         mailbox.setACL(mailboxACL);
+        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
index 4077bc9..d3ba362 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
@@ -232,8 +232,10 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements
MailboxM
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        MailboxACL oldMailboxAcl = mailbox.getACL();
         mailbox.setACL(mailboxACL);
+        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
index 6149f5c..c1ba844 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
@@ -86,8 +86,8 @@ public class TransactionalMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
-        wrapped.setACL(mailbox, mailboxACL);
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        return wrapped.setACL(mailbox, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index d8c541f..e9b9e1d 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -347,10 +347,12 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements
Mail
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        MailboxACL oldAcl = mailbox.getACL();
         MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
         folder.setACL(session, mailboxACL);
         mailbox.setACL(mailboxACL);
+        return ACLDiff.computeDiff(oldAcl, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
index de29e84..09fa357 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
@@ -167,8 +167,10 @@ public class InMemoryMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+        MailboxACL oldMailboxAcl = mailbox.getACL();
         mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(mailboxACL);
+        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 6ccff13..ef4a31b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -45,7 +45,6 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.transaction.Mapper;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
@@ -207,9 +206,8 @@ public class StoreRightManager implements RightManager {
     }
 
     private void setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox,
MailboxSession session) throws MailboxException {
-        mapper.execute(Mapper.toTransaction(() -> mapper.setACL(mailbox, mailboxACL)));
+        ACLDiff aclDiff = mapper.setACL(mailbox, mailboxACL);
 
-        ACLDiff aclDiff = ACLDiff.computeDiff(mailbox.getACL(), mailboxACL);
         dispatcher.aclUpdated(session, mailbox.generateAssociatedPath(), aclDiff);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
index d419e7a..8f68d5c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
@@ -121,7 +121,7 @@ public interface MailboxMapper extends Mapper {
      * @param mailbox Mailbox for whom we want to update ACL
      * @param mailboxACL New value of the ACL for this mailbox
      */
-    void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException;
+    ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException;
 
     /**
      * Return a unmodifable {@link List} of all {@link Mailbox} 

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
index f82f66e..f356d94 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestMailboxSessionMapperFactory.java
@@ -144,7 +144,7 @@ public class TestMailboxSessionMapperFactory extends MailboxSessionMapperFactory
             }
 
             @Override
-            public void setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
+            public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException
{
                 throw new NotImplementedException("Not implemented");
             }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/93ad42bb/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
index aba69b9..2232a7d 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
@@ -20,7 +20,10 @@
 package org.apache.james.mailbox.store.mail.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import org.apache.james.mailbox.acl.ACLDiff;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.EntryKey;
@@ -412,4 +415,34 @@ public abstract class MailboxMapperACLTest {
             .hasSize(1)
             .containsEntry(key, rights);
     }
+
+    @Test
+    public void setACLShouldReturnACLDiff() throws MailboxException {
+        EntryKey key = EntryKey.createUserEntryKey("user");
+        Rfc4314Rights rights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox,
Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
+
+        ACLDiff expectAclDiff = ACLDiff.computeDiff(MailboxACL.EMPTY, MailboxACL.EMPTY.apply(
+            MailboxACL.command()
+                .key(key)
+                .rights(rights)
+                .asAddition()));
+
+        assertThat(mailboxMapper.setACL(benwaInboxMailbox,
+            new MailboxACL(ImmutableMap.of(key, rights)))).isEqualTo(expectAclDiff);
+    }
+
+    @Test
+    public void updateACLShouldReturnACLDiff() throws MailboxException {
+        EntryKey key = EntryKey.createUserEntryKey("user");
+        Rfc4314Rights rights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox,
Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
+
+        MailboxACL.ACLCommand aclCommand = MailboxACL.command()
+            .key(key)
+            .rights(rights)
+            .asAddition();
+
+        ACLDiff expectAclDiff = ACLDiff.computeDiff(MailboxACL.EMPTY, MailboxACL.EMPTY.apply(aclCommand));
+
+        assertThat(mailboxMapper.updateACL(benwaInboxMailbox, aclCommand)).isEqualTo(expectAclDiff);
+    }
 }


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