james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1690003 - in /james/server/trunk: ./ container/cli/ container/cli/src/main/java/org/apache/james/cli/ container/cli/src/main/java/org/apache/james/cli/probe/ container/cli/src/main/java/org/apache/james/cli/probe/impl/ container/cli/src/ma...
Date Thu, 09 Jul 2015 07:43:21 GMT
Author: btellier
Date: Thu Jul  9 07:43:20 2015
New Revision: 1690003

URL: http://svn.apache.org/r1690003
Log:
JAMES-1584 Command to delete a specific mailbox

Modified:
    james/server/trunk/container/cli/pom.xml
    james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
    james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
    james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
    james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
    james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
    james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
    james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
    james/server/trunk/pom.xml

Modified: james/server/trunk/container/cli/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/pom.xml?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/cli/pom.xml (original)
+++ james/server/trunk/container/cli/pom.xml Thu Jul  9 07:43:20 2015
@@ -41,11 +41,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.james</groupId>
-            <artifactId>james-server-spring</artifactId>
+            <artifactId>james-server-mailbox-adapter</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.james</groupId>
-            <artifactId>james-server-mailbox-adapter</artifactId>
+            <artifactId>james-server-spring</artifactId>
         </dependency>
         <dependency>
             <groupId>commons-cli</groupId>

Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java (original)
+++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java Thu
Jul  9 07:43:20 2015
@@ -243,6 +243,13 @@ public class ServerCmd {
                     printUsage();
                     System.exit(1);
                 }
+            } else if (CmdType.DELETEMAILBOX.equals(cmdType)) {
+                if (cmdType.hasCorrectArguments(arguments.length)) {
+                    probe.deleteMailbox(arguments[1], arguments[2], arguments[3]);
+                } else {
+                    printUsage();
+                    System.exit(1);
+                }
             } else {
                 System.err.println("Unrecognized command: " + cmdName + ".");
                 printUsage();
@@ -309,7 +316,8 @@ public class ServerCmd {
                 "copymailbox <srcbean> <dstbean>%n" + //
                 "deleteusermailboxes <user>%n" + //
                 "createmailbox <namespace> <user> <name>%n" + //
-                "listusermailboxes <user>%n"
+                "listusermailboxes <user>%n" + //
+                "deletemailbox <namespace> <user> <name>%n"
         );
         String usage = String.format("java %s --host <arg> <command>%n", ServerCmd.class.getName());
         hf.printHelp(usage, "", options, header);

Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
(original)
+++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
Thu Jul  9 07:43:20 2015
@@ -184,7 +184,7 @@ public interface ServerProbe extends Clo
     void copyMailbox(String srcBean, String dstBean) throws Exception;
 
     /**
-     * Return the name of all mailboxes belonging to #private:${user}
+     * Delete mailboxes Belonging to #private:${user}
      *
      * @param user Username of the user we want to list mailboxes on
      * @return Collection of the mailboxes names
@@ -208,4 +208,13 @@ public interface ServerProbe extends Clo
      * @return List of mailboxes belonging to the private namespace of a user
      */
     Collection<String> listUserMailboxes(String user);
+
+    /**
+     * Delete the given mailbox
+     *
+     * @param namespace Namespace of the mailbox to delete
+     * @param user User the mailbox to delete belongs to
+     * @param name Name of the mailbox to delete
+     */
+    void deleteMailbox(String namespace, String user, String name);
 }

Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
(original)
+++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
Thu Jul  9 07:43:20 2015
@@ -208,4 +208,9 @@ public class JmxServerProbe implements S
     public Collection<String> listUserMailboxes(String user) {
         return mailboxManagerManagement.listMailboxes(user);
     }
+
+    @Override
+    public void deleteMailbox(String namespace, String user, String name) {
+        mailboxManagerManagement.deleteMailbox(namespace, user, name);
+    }
 }

Modified: james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
(original)
+++ james/server/trunk/container/cli/src/main/java/org/apache/james/cli/type/CmdType.java
Thu Jul  9 07:43:20 2015
@@ -39,7 +39,8 @@ public enum CmdType {
 	COPYMAILBOX("copymailbox", 3), //
 	DELETEUSERMAILBOXES("deleteusermailboxes", 2), //
 	CREATEMAILBOX("createmailbox", 4), //
-	LISTUSERMAILBOXES("listusermailboxes",2) //
+	LISTUSERMAILBOXES("listusermailboxes",2), //
+	DELETEMAILBOX("deletemailbox", 4) //
 	;
 	private final String command;
 	private final int arguments;

Modified: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
(original)
+++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
Thu Jul  9 07:43:20 2015
@@ -29,6 +29,7 @@ import javax.management.NotCompliantMBea
 import javax.management.StandardMBean;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 import org.apache.james.lifecycle.api.LogEnabled;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -62,7 +63,7 @@ public class MailboxManagerManagement ex
      */
     @Override
     public boolean deleteMailboxes(String username) {
-        Preconditions.checkArgument(username != null, "Username should not be null");
+        Preconditions.checkArgument(Strings.isNullOrEmpty(username), "Username should not
be null");
         MailboxSession session = null;
         try {
             session = mailboxManager.createSystemSession(username, log);
@@ -95,7 +96,7 @@ public class MailboxManagerManagement ex
      */
     @Override
     public List<String> listMailboxes(String username) {
-        Preconditions.checkArgument(username != null, "Username should not be null");
+        Preconditions.checkArgument(Strings.isNullOrEmpty(username), "Username should not
be null");
         List<String> boxes = new ArrayList<String>();
         MailboxSession session = null;
         try {
@@ -116,7 +117,7 @@ public class MailboxManagerManagement ex
 
     @Override
     public void createMailbox(String namespace, String user, String name) {
-        Preconditions.checkArgument(namespace != null && user != null &&
name != null, "Provided mailbox path components should not be null");
+        checkMailboxArguments(namespace, user, name);
         MailboxSession session = null;
         try {
             session = mailboxManager.createSystemSession(user, log);
@@ -129,6 +130,27 @@ public class MailboxManagerManagement ex
         }
     }
 
+    @Override
+    public void deleteMailbox(String namespace, String user, String name) {
+        checkMailboxArguments(namespace, user, name);
+        MailboxSession session = null;
+        try {
+            session = mailboxManager.createSystemSession(user, log);
+            mailboxManager.startProcessingRequest(session);
+            mailboxManager.deleteMailbox(new MailboxPath(namespace, user, name), session);
+        } catch (Exception e) {
+            log.error("Unable to create mailbox", e);
+        } finally {
+            closeSession(session);
+        }
+    }
+
+    private void checkMailboxArguments(String namespace, String user, String name) {
+        Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "Provided mailbox
path components should not be null or empty");
+        Preconditions.checkArgument(!Strings.isNullOrEmpty(user), "Provided mailbox path
components should not be null or empty");
+        Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Provided mailbox name
components should not be null or empty");
+    }
+
     private void closeSession(MailboxSession session) {
         if (session != null) {
             mailboxManager.endProcessingRequest(session);

Modified: james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
(original)
+++ james/server/trunk/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
Thu Jul  9 07:43:20 2015
@@ -49,4 +49,13 @@ public interface MailboxManagerManagemen
      * @param name Name of the created mailbox
      */
     void createMailbox(String namespace,String user, String name);
+
+    /**
+     * Delete the given mailbox
+     *
+     * @param namespace Namespace of the mailbox to delete
+     * @param user User the mailbox to delete belongs to
+     * @param name Name of the mailbox to delete
+     */
+    void deleteMailbox(String namespace, String user, String name);
 }
\ No newline at end of file

Modified: james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
(original)
+++ james/server/trunk/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
Thu Jul  9 07:43:20 2015
@@ -113,6 +113,11 @@ public class MailboxManagementTest {
         mailboxManagerManagement.deleteMailboxes(null);
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxesShouldThrowOnEmptyUserName() throws Exception {
+        mailboxManagerManagement.deleteMailboxes("");
+    }
+
     @Test
     public void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception {
         inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new
MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "name"), UID_VALIDITY));
@@ -140,17 +145,32 @@ public class MailboxManagementTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void createMailboxShouldThrowOnNullNamespace() {
-        mailboxManagerManagement.createMailbox(null, "", "");
+        mailboxManagerManagement.createMailbox(null, "a", "a");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void createMailboxShouldThrowOnNullUser() {
-        mailboxManagerManagement.createMailbox("", null, "");
+        mailboxManagerManagement.createMailbox("a", null, "a");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void createMailboxShouldThrowOnNullName() {
-        mailboxManagerManagement.createMailbox("", "", null);
+        mailboxManagerManagement.createMailbox("a", "a", null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void createMailboxShouldThrowOnEmptyNamespace() {
+        mailboxManagerManagement.createMailbox("", "a", "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void createMailboxShouldThrowOnEmptyUser() {
+        mailboxManagerManagement.createMailbox("a", "", "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void createMailboxShouldThrowOnEmptyName() {
+        mailboxManagerManagement.createMailbox("a", "a", "");
     }
 
     @Test
@@ -175,4 +195,70 @@ public class MailboxManagementTest {
         mailboxManagerManagement.listMailboxes(null);
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void listMailboxesShouldThrowOnEmptyUserName() {
+        mailboxManagerManagement.listMailboxes("");
+    }
+
+    @Test
+    public void deleteMailboxShouldDeleteGivenMailbox() throws Exception {
+        inMemoryMapperFactory.createMailboxMapper(session).save(new SimpleMailbox<InMemoryId>(new
MailboxPath(MailboxConstants.USER_NAMESPACE, USER, "name"), UID_VALIDITY));
+        mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+        assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).isEmpty();
+    }
+
+    @Test
+    public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception
{
+        Mailbox<InMemoryId> mailbox = new SimpleMailbox<InMemoryId>(new MailboxPath("#top",
USER, "name"), UID_VALIDITY);
+        inMemoryMapperFactory.createMailboxMapper(session).save(mailbox);
+        mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+        assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+    }
+
+    @Test
+    public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception {
+        Mailbox<InMemoryId> mailbox = new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE,
"userbis", "name"), UID_VALIDITY);
+        inMemoryMapperFactory.createMailboxMapper(session).save(mailbox);
+        mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+        assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+    }
+
+    @Test
+    public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception {
+        Mailbox<InMemoryId> mailbox = new SimpleMailbox<InMemoryId>(new MailboxPath(MailboxConstants.USER_NAMESPACE,
USER, "wrong_name"), UID_VALIDITY);
+        inMemoryMapperFactory.createMailboxMapper(session).save(mailbox);
+        mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+        assertThat(inMemoryMapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnNullNamespace() {
+        mailboxManagerManagement.deleteMailbox(null, "a", "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnNullUser() {
+        mailboxManagerManagement.deleteMailbox("a", null, "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnNullName() {
+        mailboxManagerManagement.deleteMailbox("a", "a", null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnEmptyNamespace() {
+        mailboxManagerManagement.deleteMailbox("", "a", "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnEmptyUser() {
+        mailboxManagerManagement.deleteMailbox("a", "", "a");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void deleteMailboxShouldThrowOnEmptyName() {
+        mailboxManagerManagement.deleteMailbox("a", "a", "");
+    }
+
 }

Modified: james/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1690003&r1=1690002&r2=1690003&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Thu Jul  9 07:43:20 2015
@@ -844,6 +844,7 @@
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
                 <version>3.0.0</version>
+                <scope>test</scope>
             </dependency>
 
             <dependency>



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