james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [03/10] james-project git commit: MAILBOX-351 WebAdminReIndexing routes can rely directly on MailboxId
Date Thu, 29 Nov 2018 03:53:17 GMT
MAILBOX-351 WebAdminReIndexing routes can rely directly on MailboxId


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

Branch: refs/heads/master
Commit: 85350b38639e7ae5b15ef785f3c1dc1a80a3789d
Parents: 5e04df0
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Nov 23 15:41:11 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 29 10:52:45 2018 +0700

----------------------------------------------------------------------
 .../james/webadmin/routes/ReindexingRoutes.java | 55 ++++++++------------
 .../webadmin/routes/ReindexingRoutesTest.java   |  6 ++-
 2 files changed, 27 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/85350b38/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
index e042580..e954a0f 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/ReindexingRoutes.java
@@ -25,14 +25,11 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
 import org.apache.james.core.User;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskId;
 import org.apache.james.task.TaskManager;
@@ -42,8 +39,6 @@ import org.apache.james.webadmin.utils.ErrorResponder;
 import org.apache.james.webadmin.utils.JsonTransformer;
 import org.eclipse.jetty.http.HttpStatus;
 
-import com.github.fge.lambdas.supplier.ThrowingSupplier;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -58,6 +53,11 @@ import spark.Service;
 @Path("/mailboxIndex")
 @Produces("application/json")
 public class ReindexingRoutes implements Routes {
+    @FunctionalInterface
+    interface TaskGenerator {
+        Task generate() throws MailboxException;
+    }
+
     static final String BASE_PATH = "/mailboxIndex";
     private static final String USER_PARAM = ":user";
     private static final String MAILBOX_PARAM = ":mailbox";
@@ -67,15 +67,13 @@ public class ReindexingRoutes implements Routes {
     private static final String MESSAGE_PATH = MAILBOX_PATH + "/mails/" + UID_PARAM;
 
     private final TaskManager taskManager;
-    private final MailboxManager mailboxManager;
     private final MailboxId.Factory mailboxIdFactory;
     private final ReIndexer reIndexer;
     private final JsonTransformer jsonTransformer;
 
     @Inject
-    public ReindexingRoutes(TaskManager taskManager, MailboxManager mailboxManager, MailboxId.Factory
mailboxIdFactory, ReIndexer reIndexer, JsonTransformer jsonTransformer) {
+    public ReindexingRoutes(TaskManager taskManager, MailboxId.Factory mailboxIdFactory,
ReIndexer reIndexer, JsonTransformer jsonTransformer) {
         this.taskManager = taskManager;
-        this.mailboxManager = mailboxManager;
         this.mailboxIdFactory = mailboxIdFactory;
         this.reIndexer = reIndexer;
         this.jsonTransformer = jsonTransformer;
@@ -183,7 +181,7 @@ public class ReindexingRoutes implements Routes {
     })
     private TaskIdDto reIndexMailbox(Request request, Response response) {
         return wrap(request, response,
-            () -> reIndexer.reIndex(retrievePath(request)));
+            () -> reIndexer.reIndex(extractMailboxId(request)));
     }
 
     @POST
@@ -223,14 +221,25 @@ public class ReindexingRoutes implements Routes {
     })
     private TaskIdDto reIndexMessage(Request request, Response response) {
         return wrap(request, response,
-            () -> reIndexer.reIndex(retrievePath(request), extractUid(request)));
+            () -> reIndexer.reIndex(extractMailboxId(request), extractUid(request)));
     }
 
-    private TaskIdDto wrap(Request request, Response response, ThrowingSupplier<Task>
taskGenerator) {
+    private TaskIdDto wrap(Request request, Response response, TaskGenerator taskGenerator)
{
         ReIndexingRoutesUtil.enforceTaskParameter(request);
-        Task task = taskGenerator.get();
-        TaskId taskId = taskManager.submit(task);
-        return TaskIdDto.respond(response, taskId);
+        try {
+            Task task = taskGenerator.generate();
+            TaskId taskId = taskManager.submit(task);
+            return TaskIdDto.respond(response, taskId);
+        } catch (MailboxNotFoundException e) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("mailbox not found")
+                .cause(e)
+                .haltError();
+        } catch (MailboxException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     private User extractUser(Request request) {
@@ -246,10 +255,6 @@ public class ReindexingRoutes implements Routes {
         }
     }
 
-    private MailboxPath retrievePath(Request request) throws MailboxException {
-        return toMailboxPath(extractUser(request), extractMailboxId(request));
-    }
-
     private MailboxId extractMailboxId(Request request) {
         try {
             return mailboxIdFactory.fromString(request.params(MAILBOX_PARAM));
@@ -275,18 +280,4 @@ public class ReindexingRoutes implements Routes {
                 .haltError();
         }
     }
-
-    private MailboxPath toMailboxPath(User user, MailboxId mailboxId) throws MailboxException
{
-        try {
-            MailboxSession systemSession = mailboxManager.createSystemSession(user.asString());
-            return mailboxManager.getMailbox(mailboxId, systemSession).getMailboxPath();
-        } catch (MailboxNotFoundException e) {
-            throw ErrorResponder.builder()
-                .statusCode(HttpStatus.BAD_REQUEST_400)
-                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
-                .message("mailbox not found")
-                .cause(e)
-                .haltError();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/85350b38/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
index f0c6459..6ac8cc8 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
@@ -61,6 +61,7 @@ import org.apache.mailbox.tools.indexer.UserReindexingTask;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
@@ -95,7 +96,6 @@ class ReindexingRoutesTest {
             new TasksRoutes(taskManager, jsonTransformer),
             new ReindexingRoutes(
                 taskManager,
-                mailboxManager,
                 mailboxIdFactory,
                 reIndexer,
                 jsonTransformer),
@@ -401,6 +401,7 @@ class ReindexingRoutesTest {
                     .body("message", is("task query parameter is mandatory. The only supported
value is `reIndex`"));
             }
 
+            @Disabled("Using user here makes no sens from an API perspective, and will be
removed")
             @Test
             void mailboxReprocessingShouldFailWithBadUser() throws Exception {
                 MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
@@ -580,6 +581,7 @@ class ReindexingRoutesTest {
                     .body("message", is("task query parameter is mandatory. The only supported
value is `reIndex`"));
             }
 
+            @Disabled("Using user here makes no sens from an API perspective, and will be
removed")
             @Test
             void messageReprocessingShouldFailWithBadUser() throws Exception {
                 MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
@@ -624,7 +626,7 @@ class ReindexingRoutesTest {
                     .statusCode(HttpStatus.BAD_REQUEST_400)
                     .body("statusCode", is(400))
                     .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
-                    .body("message", is("mailbox not found"));
+                    .body("message", is("'uid' needs to be a parsable long"));
             }
         }
 


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