This is an automated email from the ASF dual-hosted git repository. rouazana pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d2d2e869fc53273a0f37853033cd7df57f2ca55d Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Mon Jun 1 15:48:08 2020 +0700 JAMES-3194 Rely on DTOConverter in TaskRoute --- .../indexer/ReprocessingContextInformation.java | 6 -- .../indexer/ReprocessingContextInformationDTO.java | 7 +- .../tools/indexer/SingleMailboxReindexingTask.java | 5 +- .../mailbox/tools/indexer/UserReindexingTask.java | 5 +- .../routes/CassandraMappingsRoutesTest.java | 5 +- .../protocols/webadmin/webadmin-cassandra/pom.xml | 11 ++ ...AdminMigrationTaskAdditionalInformationDTO.java | 66 ++++++++++++ .../WebAdminMigrationTaskSerializationTest.java | 40 +++++++ .../routes/CassandraMigrationRoutesTest.java | 6 +- ...lveMessageInconsistenciesRequestToTaskTest.java | 4 +- server/protocols/webadmin/webadmin-core/pom.xml | 4 + .../james/webadmin/dto/ExecutionDetailsDto.java | 24 +++-- .../apache/james/webadmin/routes/TasksRoutes.java | 13 ++- .../james/webadmin/routes/TasksRoutesTest.java | 6 +- ...llFastViewProjectionItemsRequestToTaskTest.java | 4 +- ...erFastViewProjectionItemsRequestToTaskTest.java | 4 +- ...gesVaultDeleteTaskAdditionalInformationDTO.java | 74 +++++++++++++ ...esVaultRestoreTaskAdditionalInformationDTO.java | 101 ++++++++++++++++++ .../routes/DeletedMessagesVaultRoutesTest.java | 9 +- ...edMessagesVaultDeleteTaskSerializationTest.java | 44 ++++++++ ...dMessagesVaultRestoreTaskSerializationTest.java | 41 ++++++++ server/protocols/webadmin/webadmin-mailbox/pom.xml | 1 - .../SerializableReIndexingExecutionFailures.java | 2 +- .../WebAdminReprocessingContextInformationDTO.java | 116 +++++++++++++++++++++ ...lboxReindexingTaskAdditionalInformationDTO.java | 94 +++++++++++++++++ ...UserReindexingTaskAdditionalInformationDTO.java | 93 +++++++++++++++++ ...erializableReIndexingExecutionFailuresTest.java | 2 +- ...AdminReprocessingContextInformationDTOTest.java | 111 ++++++++++++++++++++ .../WebAdminSingleMailboxReprocessingDTOTest.java | 82 +++++++++++++++ .../dto/WebAdminUserReprocessingDTOTest.java | 83 +++++++++++++++ .../routes/EventDeadLettersRoutesTest.java | 9 +- .../routes/MailboxesRoutesNoTasksTest.java | 3 +- .../james/webadmin/routes/MailboxesRoutesTest.java | 17 ++- .../james/webadmin/routes/MessageRoutesTest.java | 6 +- .../UserMailboxesRoutesNoIndexationTest.java | 3 +- .../webadmin/routes/UserMailboxesRoutesTest.java | 17 +-- .../routes/WebAdminQuotaSearchTestSystem.java | 5 +- .../service/MailboxesExportRequestToTaskTest.java | 4 +- ...sFromMailQueueTaskAdditionalInformationDTO.java | 110 +++++++++++++++++++ .../james/webadmin/routes/MailQueueRoutesTest.java | 8 +- ...mMailQueueTaskAdditionalInformationDTOTest.java | 51 +++++++++ ...MailRepositoryTaskAdditionalInformationDTO.java | 88 ++++++++++++++++ .../routes/MailRepositoriesRoutesTest.java | 10 +- .../WebAdminClearMailRepositoryTaskDTOTest.java | 44 ++++++++ src/site/markdown/server/manage-webadmin.md | 51 ++++----- 45 files changed, 1417 insertions(+), 72 deletions(-) diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformation.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformation.java index c2927c9..2517c07 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformation.java +++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformation.java @@ -27,7 +27,6 @@ import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures; import org.apache.james.task.TaskExecutionDetails; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; public class ReprocessingContextInformation implements TaskExecutionDetails.AdditionalInformation, IndexingDetailInformation { @@ -62,11 +61,6 @@ public class ReprocessingContextInformation implements TaskExecutionDetails.Addi return failures; } - @JsonProperty("failures") - public SerializableReIndexingExecutionFailures failuresAsJson() { - return SerializableReIndexingExecutionFailures.from(failures()); - } - @Override public Instant timestamp() { return timestamp; diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java index 714599d..363cc42 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java +++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReprocessingContextInformationDTO.java @@ -36,6 +36,7 @@ import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.steveash.guavate.Guavate; import com.google.common.base.Preconditions; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; @@ -101,7 +102,8 @@ public class ReprocessingContextInformationDTO implements AdditionalInformationD .withFactory(AdditionalInformationDTOModule::new); } - ReprocessingContextInformationForErrorRecoveryIndexationTask(int successfullyReprocessedMailCount, + @VisibleForTesting + public ReprocessingContextInformationForErrorRecoveryIndexationTask(int successfullyReprocessedMailCount, int failedReprocessedMailCount, ReIndexingExecutionFailures failures, Instant timestamp, @@ -150,7 +152,8 @@ public class ReprocessingContextInformationDTO implements AdditionalInformationD .withFactory(AdditionalInformationDTOModule::new); } - ReprocessingContextInformationForFullReindexingTask(int successfullyReprocessedMailCount, + @VisibleForTesting + public ReprocessingContextInformationForFullReindexingTask(int successfullyReprocessedMailCount, int failedReprocessedMailCount, ReIndexingExecutionFailures failures, Instant timestamp, diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java index bc474a3..167889d 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java +++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java @@ -32,6 +32,8 @@ import org.apache.james.task.Task; import org.apache.james.task.TaskExecutionDetails; import org.apache.james.task.TaskType; +import com.google.common.annotations.VisibleForTesting; + public class SingleMailboxReindexingTask implements Task { public static final TaskType MAILBOX_RE_INDEXING = TaskType.of("mailbox-reindexing"); @@ -39,7 +41,8 @@ public class SingleMailboxReindexingTask implements Task { public static class AdditionalInformation extends ReprocessingContextInformation { private final MailboxId mailboxId; - AdditionalInformation(MailboxId mailboxId, int successfullyReprocessedMailCount, + @VisibleForTesting + public AdditionalInformation(MailboxId mailboxId, int successfullyReprocessedMailCount, int failedReprocessedMailCount, ReIndexingExecutionFailures failures, Instant timestamp, RunningOptions runningOptions) { super(successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp, runningOptions); diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTask.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTask.java index 19cde9b..5fe450b 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTask.java +++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTask.java @@ -32,6 +32,8 @@ import org.apache.james.task.Task; import org.apache.james.task.TaskExecutionDetails; import org.apache.james.task.TaskType; +import com.google.common.annotations.VisibleForTesting; + import reactor.core.publisher.Mono; public class UserReindexingTask implements Task { @@ -41,7 +43,8 @@ public class UserReindexingTask implements Task { public static class AdditionalInformation extends ReprocessingContextInformation { private final Username username; - AdditionalInformation(Username username, int successfullyReprocessedMailCount, + @VisibleForTesting + public AdditionalInformation(Username username, int successfullyReprocessedMailCount, int failedReprocessedMailCount, ReIndexingExecutionFailures failures, Instant timestamp, RunningOptions runningOptions) { super(successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp, runningOptions); diff --git a/server/protocols/webadmin/webadmin-cassandra-data/src/test/java/org/apache/james/webadmin/routes/CassandraMappingsRoutesTest.java b/server/protocols/webadmin/webadmin-cassandra-data/src/test/java/org/apache/james/webadmin/routes/CassandraMappingsRoutesTest.java index 5c42462..6812278 100644 --- a/server/protocols/webadmin/webadmin-cassandra-data/src/test/java/org/apache/james/webadmin/routes/CassandraMappingsRoutesTest.java +++ b/server/protocols/webadmin/webadmin-cassandra-data/src/test/java/org/apache/james/webadmin/routes/CassandraMappingsRoutesTest.java @@ -30,10 +30,12 @@ import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.CassandraClusterExtension; import org.apache.james.backends.cassandra.utils.CassandraUtils; import org.apache.james.core.Domain; +import org.apache.james.json.DTOConverter; import org.apache.james.rrt.cassandra.CassandraMappingsSourcesDAO; import org.apache.james.rrt.cassandra.CassandraRRTModule; import org.apache.james.rrt.cassandra.CassandraRecipientRewriteTableDAO; import org.apache.james.rrt.cassandra.migration.MappingsSourcesMigration; +import org.apache.james.rrt.cassandra.migration.MappingsSourcesMigrationTaskAdditionalInformationDTO; import org.apache.james.rrt.lib.Mapping; import org.apache.james.rrt.lib.MappingSource; import org.apache.james.task.Hostname; @@ -80,7 +82,8 @@ class CassandraMappingsRoutesTest { taskManager = new MemoryTaskManager(new Hostname("foo")); webAdminServer = WebAdminUtils.createWebAdminServer( new CassandraMappingsRoutes(cassandraMappingsService, taskManager, jsonTransformer), - new TasksRoutes(taskManager, jsonTransformer)) + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(MappingsSourcesMigrationTaskAdditionalInformationDTO.serializationModule(CassandraMappingsSolveInconsistenciesTask.TYPE)))) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-cassandra/pom.xml b/server/protocols/webadmin/webadmin-cassandra/pom.xml index 002dc6f..0505fab 100644 --- a/server/protocols/webadmin/webadmin-cassandra/pom.xml +++ b/server/protocols/webadmin/webadmin-cassandra/pom.xml @@ -39,6 +39,12 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-json</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-task-memory</artifactId> <scope>test</scope> </dependency> @@ -72,6 +78,11 @@ <artifactId>javax.inject</artifactId> </dependency> <dependency> + <groupId>net.javacrumbs.json-unit</groupId> + <artifactId>json-unit-assertj</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <scope>test</scope> diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..dc6be00 --- /dev/null +++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskAdditionalInformationDTO.java @@ -0,0 +1,66 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import java.time.Instant; + +import org.apache.james.backends.cassandra.migration.MigrationTask; +import org.apache.james.backends.cassandra.versions.SchemaVersion; +import org.apache.james.json.DTOModule; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminMigrationTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static AdditionalInformationDTOModule<MigrationTask.AdditionalInformation, WebAdminMigrationTaskAdditionalInformationDTO> serializationModule() { + return DTOModule.forDomainObject(MigrationTask.AdditionalInformation.class) + .convertToDTO(WebAdminMigrationTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(dto -> new MigrationTask.AdditionalInformation(new SchemaVersion(dto.getToVersion()), dto.timestamp)) + .toDTOConverter((details, type) -> new WebAdminMigrationTaskAdditionalInformationDTO(type, details.getToVersion(), details.timestamp())) + .typeName(MigrationTask.CASSANDRA_MIGRATION.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + private final String type; + private final int toVersion; + private final Instant timestamp; + + public WebAdminMigrationTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("toVersion") int toVersion, + @JsonProperty("timestamp") Instant timestamp) { + this.type = type; + this.toVersion = toVersion; + this.timestamp = timestamp; + } + + @Override + public String getType() { + return type; + } + + public Instant getTimestamp() { + return timestamp; + } + + public int getToVersion() { + return toVersion; + } +} diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskSerializationTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskSerializationTest.java new file mode 100644 index 0000000..3d9abc6 --- /dev/null +++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/WebAdminMigrationTaskSerializationTest.java @@ -0,0 +1,40 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import java.time.Instant; + +import org.apache.james.JsonSerializationVerifier; +import org.apache.james.backends.cassandra.migration.MigrationTask; +import org.apache.james.backends.cassandra.migration.MigrationTaskAdditionalInformationDTO; +import org.apache.james.backends.cassandra.versions.SchemaVersion; +import org.junit.jupiter.api.Test; + +class WebAdminMigrationTaskSerializationTest { + private static final String SERIALIZED_ADDITIONAL_INFORMATION = "{\"type\": \"cassandra-migration\", \"toVersion\": 12, \"timestamp\": \"2018-11-13T12:00:55Z\"}"; + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + @Test + void additionalInformationShouldBeSerializable() throws Exception { + JsonSerializationVerifier.dtoModule(WebAdminMigrationTaskAdditionalInformationDTO.serializationModule()) + .bean(new MigrationTask.AdditionalInformation(new SchemaVersion(12), TIMESTAMP)) + .json(SERIALIZED_ADDITIONAL_INFORMATION) + .verify(); + } +} \ No newline at end of file diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java index 5d5d4e5..ddf52e4 100644 --- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java +++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java @@ -41,13 +41,16 @@ import org.apache.james.backends.cassandra.migration.CassandraMigrationService; import org.apache.james.backends.cassandra.migration.CassandraSchemaTransitions; import org.apache.james.backends.cassandra.migration.Migration; import org.apache.james.backends.cassandra.migration.MigrationTask; +import org.apache.james.backends.cassandra.migration.MigrationTaskAdditionalInformationDTO; import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO; import org.apache.james.backends.cassandra.versions.SchemaTransition; import org.apache.james.backends.cassandra.versions.SchemaVersion; +import org.apache.james.json.DTOConverter; import org.apache.james.task.Hostname; import org.apache.james.task.MemoryTaskManager; import org.apache.james.webadmin.WebAdminServer; import org.apache.james.webadmin.WebAdminUtils; +import org.apache.james.webadmin.dto.WebAdminMigrationTaskAdditionalInformationDTO; import org.apache.james.webadmin.utils.JsonTransformer; import org.eclipse.jetty.http.HttpStatus; import org.junit.After; @@ -87,7 +90,8 @@ public class CassandraMigrationRoutesTest { webAdminServer = WebAdminUtils.createWebAdminServer( new CassandraMigrationRoutes(new CassandraMigrationService(schemaVersionDAO, transitions, version -> new MigrationTask(schemaVersionDAO, transitions, version), LATEST_VERSION), taskManager, jsonTransformer), - new TasksRoutes(taskManager, jsonTransformer)) + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(WebAdminMigrationTaskAdditionalInformationDTO.serializationModule()))) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMessageInconsistenciesRequestToTaskTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMessageInconsistenciesRequestToTaskTest.java index 01cb39d..00ccadd 100644 --- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMessageInconsistenciesRequestToTaskTest.java +++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMessageInconsistenciesRequestToTaskTest.java @@ -27,7 +27,9 @@ import static org.hamcrest.Matchers.notNullValue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.cassandra.mail.task.SolveMessageInconsistenciesService; +import org.apache.james.mailbox.cassandra.mail.task.SolveMessageInconsistenciesTaskAdditionalInformationDTO; import org.apache.james.task.Hostname; import org.apache.james.task.MemoryTaskManager; import org.apache.james.task.Task; @@ -89,7 +91,7 @@ public class SolveMessageInconsistenciesRequestToTaskTest { Mockito.when(service.fixMessageInconsistencies(any(), any())).thenReturn(Mono.just(Task.Result.COMPLETED)); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, DTOConverter.of(SolveMessageInconsistenciesTaskAdditionalInformationDTO.MODULE)), new JMAPRoutes( service, taskManager)) diff --git a/server/protocols/webadmin/webadmin-core/pom.xml b/server/protocols/webadmin/webadmin-core/pom.xml index 2d80ae4..1f28dee 100644 --- a/server/protocols/webadmin/webadmin-core/pom.xml +++ b/server/protocols/webadmin/webadmin-core/pom.xml @@ -70,6 +70,10 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-server-task-json</artifactId> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-task-memory</artifactId> <scope>test</scope> </dependency> diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/dto/ExecutionDetailsDto.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/dto/ExecutionDetailsDto.java index 413a525..8e25de7 100644 --- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/dto/ExecutionDetailsDto.java +++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/dto/ExecutionDetailsDto.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import org.apache.james.json.DTOConverter; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; import org.apache.james.task.Hostname; import org.apache.james.task.TaskExecutionDetails; @@ -32,20 +34,28 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.github.steveash.guavate.Guavate; public class ExecutionDetailsDto { - public static List<ExecutionDetailsDto> from(List<TaskExecutionDetails> tasksDetails) { + public static List<ExecutionDetailsDto> from(DTOConverter<TaskExecutionDetails.AdditionalInformation, AdditionalInformationDTO> additionalInformationConverter, + List<TaskExecutionDetails> tasksDetails) { return tasksDetails.stream() - .map(ExecutionDetailsDto::new) + .map(details -> ExecutionDetailsDto.from(additionalInformationConverter, details)) .collect(Guavate.toImmutableList()); } - public static ExecutionDetailsDto from(TaskExecutionDetails taskDetails) { - return new ExecutionDetailsDto(taskDetails); + public static ExecutionDetailsDto from(DTOConverter<TaskExecutionDetails.AdditionalInformation, AdditionalInformationDTO> additionalInformationConverter, + TaskExecutionDetails taskDetails) { + + return new ExecutionDetailsDto(taskDetails, + taskDetails.getAdditionalInformation() + .flatMap(additionalInformationConverter::toDTO)); } private final TaskExecutionDetails executionDetails; + private final Optional<AdditionalInformationDTO> additionalInformation; - private ExecutionDetailsDto(TaskExecutionDetails executionDetails) { + private ExecutionDetailsDto(TaskExecutionDetails executionDetails, + Optional<AdditionalInformationDTO> additionalInformation) { this.executionDetails = executionDetails; + this.additionalInformation = additionalInformation; } public UUID getTaskId() { @@ -74,8 +84,8 @@ public class ExecutionDetailsDto { .map(Hostname::asString); } - public Optional<TaskExecutionDetails.AdditionalInformation> getAdditionalInformation() { - return executionDetails.getAdditionalInformation(); + public Optional<AdditionalInformationDTO> getAdditionalInformation() { + return additionalInformation; } @JsonInclude(JsonInclude.Include.NON_ABSENT) diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/TasksRoutes.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/TasksRoutes.java index 231388a..9316ad7 100644 --- a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/TasksRoutes.java +++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/TasksRoutes.java @@ -31,6 +31,8 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import org.apache.james.json.DTOConverter; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; import org.apache.james.task.TaskExecutionDetails; import org.apache.james.task.TaskId; import org.apache.james.task.TaskManager; @@ -60,14 +62,17 @@ import spark.Service; @Produces("application/json") public class TasksRoutes implements Routes { private static final Duration MAXIMUM_AWAIT_TIMEOUT = Duration.ofDays(365); + public static final String BASE = "/tasks"; + private final TaskManager taskManager; private final JsonTransformer jsonTransformer; - public static final String BASE = "/tasks"; + private final DTOConverter<TaskExecutionDetails.AdditionalInformation, AdditionalInformationDTO> additionalInformationDTOConverter; @Inject - public TasksRoutes(TaskManager taskManager, JsonTransformer jsonTransformer) { + public TasksRoutes(TaskManager taskManager, JsonTransformer jsonTransformer, DTOConverter<TaskExecutionDetails.AdditionalInformation, AdditionalInformationDTO> additionalInformationDTOConverter) { this.taskManager = taskManager; this.jsonTransformer = jsonTransformer; + this.additionalInformationDTOConverter = additionalInformationDTOConverter; } @Override @@ -105,7 +110,7 @@ public class TasksRoutes implements Routes { }) public Object list(Request req, Response response) { try { - return ExecutionDetailsDto.from( + return ExecutionDetailsDto.from(additionalInformationDTOConverter, Optional.ofNullable(req.queryParams("status")) .map(TaskManager.Status::fromString) .map(taskManager::list) @@ -153,7 +158,7 @@ public class TasksRoutes implements Routes { private Object respondStatus(TaskId taskId, Supplier<TaskExecutionDetails> executionDetailsSupplier) { try { TaskExecutionDetails executionDetails = executionDetailsSupplier.get(); - return ExecutionDetailsDto.from(executionDetails); + return ExecutionDetailsDto.from(additionalInformationDTOConverter, executionDetails); } catch (TaskNotFoundException e) { throw ErrorResponder.builder() .message("%s can not be found", taskId.getValue()) diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java index c34baa4..acf53f7 100644 --- a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java +++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/TasksRoutesTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.Matchers.nullValue; import java.util.UUID; import java.util.concurrent.CountDownLatch; +import org.apache.james.json.DTOConverter; import org.apache.james.task.Hostname; import org.apache.james.task.MemoryReferenceTask; import org.apache.james.task.MemoryTaskManager; @@ -50,8 +51,8 @@ import org.junit.jupiter.api.Test; import io.restassured.RestAssured; class TasksRoutesTest { + private static final String HOSTNAME = "foo"; - public static final String HOSTNAME = "foo"; private MemoryTaskManager taskManager; private WebAdminServer webAdminServer; private CountDownLatch waitingForResultLatch; @@ -60,7 +61,8 @@ class TasksRoutesTest { void setUp() { taskManager = new MemoryTaskManager(new Hostname(HOSTNAME)); - webAdminServer = WebAdminUtils.createWebAdminServer(new TasksRoutes(taskManager, new JsonTransformer())) + webAdminServer = WebAdminUtils.createWebAdminServer(new TasksRoutes(taskManager, new JsonTransformer(), + DTOConverter.of())) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeAllFastViewProjectionItemsRequestToTaskTest.java b/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeAllFastViewProjectionItemsRequestToTaskTest.java index 0a8a2e6..35e402e 100644 --- a/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeAllFastViewProjectionItemsRequestToTaskTest.java +++ b/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeAllFastViewProjectionItemsRequestToTaskTest.java @@ -34,6 +34,7 @@ import org.apache.james.jmap.api.model.Preview; import org.apache.james.jmap.api.projections.MessageFastViewPrecomputedProperties; import org.apache.james.jmap.draft.utils.JsoupHtmlTextExtractor; import org.apache.james.jmap.memory.projections.MemoryMessageFastViewProjection; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; @@ -119,7 +120,8 @@ class RecomputeAllFastViewProjectionItemsRequestToTaskTest { Preview.Factory previewFactory = new Preview.Factory(messageContentExtractor, htmlTextExtractor); MessageFastViewPrecomputedProperties.Factory projectionItemFactory = new MessageFastViewPrecomputedProperties.Factory(previewFactory); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(RecomputeAllFastViewTaskAdditionalInformationDTO.SERIALIZATION_MODULE)), new JMAPRoutes( new MessageFastViewProjectionCorrector(usersRepository, mailboxManager, messageFastViewProjection, projectionItemFactory), taskManager)) diff --git a/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeUserFastViewProjectionItemsRequestToTaskTest.java b/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeUserFastViewProjectionItemsRequestToTaskTest.java index 5a4d74a..91eabc8 100644 --- a/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeUserFastViewProjectionItemsRequestToTaskTest.java +++ b/server/protocols/webadmin/webadmin-jmap/src/test/java/org/apache/james/webadmin/data/jmap/RecomputeUserFastViewProjectionItemsRequestToTaskTest.java @@ -35,6 +35,7 @@ import org.apache.james.jmap.api.model.Preview; import org.apache.james.jmap.api.projections.MessageFastViewPrecomputedProperties; import org.apache.james.jmap.draft.utils.JsoupHtmlTextExtractor; import org.apache.james.jmap.memory.projections.MemoryMessageFastViewProjection; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; @@ -133,7 +134,8 @@ class RecomputeUserFastViewProjectionItemsRequestToTaskTest { Preview.Factory previewFactory = new Preview.Factory(messageContentExtractor, htmlTextExtractor); MessageFastViewPrecomputedProperties.Factory projectionItemFactory = new MessageFastViewPrecomputedProperties.Factory(previewFactory); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(RecomputeUserFastViewTaskAdditionalInformationDTO.SERIALIZATION_MODULE)), new JMAPRoutes( new MessageFastViewProjectionCorrector(usersRepository, mailboxManager, messageFastViewProjection, projectionItemFactory), taskManager, usersRepository)) diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..f387ecc --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.java @@ -0,0 +1,74 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.vault.routes; + +import java.time.Instant; + +import org.apache.james.core.Username; +import org.apache.james.json.DTOModule; +import org.apache.james.mailbox.model.MessageId; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static AdditionalInformationDTOModule<DeletedMessagesVaultDeleteTask.AdditionalInformation, WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO> serializationModule(MessageId.Factory factory) { + return DTOModule.forDomainObject(DeletedMessagesVaultDeleteTask.AdditionalInformation.class) + .convertToDTO(WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(dto -> new DeletedMessagesVaultDeleteTask.AdditionalInformation(Username.of(dto.username), factory.fromString(dto.getDeleteMessageId()), dto.getTimestamp())) + .toDTOConverter((details, type) -> new WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO(type, details.getUsername(), details.getDeleteMessageId(), details.timestamp())) + .typeName(DeletedMessagesVaultDeleteTask.TYPE.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + private final String type; + private final String username; + private final String deleteMessageId; + private final Instant timestamp; + + public WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("username") String username, + @JsonProperty("deleteMessageId") String messageId, + @JsonProperty("timestamp") Instant timestamp) { + this.type = type; + this.username = username; + this.deleteMessageId = messageId; + this.timestamp = timestamp; + } + + public String getDeleteMessageId() { + return deleteMessageId; + } + + public String getUsername() { + return username; + } + + @Override + public Instant getTimestamp() { + return timestamp; + } + + @Override + public String getType() { + return type; + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..7e498ae --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/main/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.java @@ -0,0 +1,101 @@ +/** + * ************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ***************************************************************/ + +package org.apache.james.webadmin.vault.routes; + +import java.time.Instant; + +import org.apache.james.core.Username; +import org.apache.james.json.DTOModule; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + private static WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO fromDomainObject(DeletedMessagesVaultRestoreTask.AdditionalInformation additionalInformation, String type) { + return new WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO( + type, + additionalInformation.getUsername(), + additionalInformation.getSuccessfulRestoreCount(), + additionalInformation.getErrorRestoreCount(), + additionalInformation.timestamp() + ); + } + + public static final AdditionalInformationDTOModule<DeletedMessagesVaultRestoreTask.AdditionalInformation, WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO> MODULE = + DTOModule + .forDomainObject(DeletedMessagesVaultRestoreTask.AdditionalInformation.class) + .convertToDTO(WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO::toDomainObject) + .toDTOConverter(WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO::fromDomainObject) + .typeName(DeletedMessagesVaultRestoreTask.TYPE.asString()) + .withFactory(AdditionalInformationDTOModule::new); + + private final String type; + private final String username; + private final Long successfulRestoreCount; + private final Long errorRestoreCount; + private final Instant timestamp; + + public WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("username") String username, + @JsonProperty("successfulRestoreCount") Long successfulRestoreCount, + @JsonProperty("errorRestoreCount") Long errorRestoreCount, + @JsonProperty("timestamp") Instant timestamp) { + this.type = type; + this.username = username; + this.successfulRestoreCount = successfulRestoreCount; + this.errorRestoreCount = errorRestoreCount; + this.timestamp = timestamp; + } + + public String getUsername() { + return username; + } + + public Long getSuccessfulRestoreCount() { + return successfulRestoreCount; + } + + public Long getErrorRestoreCount() { + return errorRestoreCount; + } + + DeletedMessagesVaultRestoreTask.AdditionalInformation toDomainObject() { + return new DeletedMessagesVaultRestoreTask.AdditionalInformation( + Username.of(username), + successfulRestoreCount, + errorRestoreCount, + timestamp + ); + } + + @Override + public Instant getTimestamp() { + return timestamp; + } + + @Override + public String getType() { + return type; + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java index 4a4fc5a..c66f372 100644 --- a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java @@ -84,6 +84,7 @@ import org.apache.james.core.Username; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.domainlist.lib.DomainListConfiguration; import org.apache.james.domainlist.memory.MemoryDomainList; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.DefaultMailboxes; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; @@ -110,6 +111,7 @@ import org.apache.james.vault.DeletedMessageVault; import org.apache.james.vault.DeletedMessageZipper; import org.apache.james.vault.RetentionConfiguration; import org.apache.james.vault.blob.BlobStoreDeletedMessageVault; +import org.apache.james.vault.blob.BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO; import org.apache.james.vault.blob.BucketNameGenerator; import org.apache.james.vault.dto.query.QueryTranslator; import org.apache.james.vault.memory.metadata.MemoryDeletedMessageMetadataVault; @@ -193,7 +195,12 @@ class DeletedMessagesVaultRoutesTest { usersRepository = createUsersRepository(); MessageId.Factory messageIdFactory = new InMemoryMessageId.Factory(); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of( + WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.serializationModule(messageIdFactory), + DeletedMessagesVaultExportTaskAdditionalInformationDTO.MODULE, + WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.MODULE, + BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.MODULE)), new DeletedMessagesVaultRoutes(vault, vaultRestore, exportService, jsonTransformer, taskManager, queryTranslator, usersRepository, messageIdFactory)) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskSerializationTest.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskSerializationTest.java new file mode 100644 index 0000000..d02c2ce --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultDeleteTaskSerializationTest.java @@ -0,0 +1,44 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.vault.routes; + +import java.time.Instant; + +import org.apache.james.JsonSerializationVerifier; +import org.apache.james.core.Username; +import org.apache.james.mailbox.model.MessageId; +import org.apache.james.mailbox.model.TestMessageId; +import org.junit.jupiter.api.Test; + +class WebAdminDeletedMessagesVaultDeleteTaskSerializationTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private final Username username = Username.of("james"); + private final TestMessageId.Factory messageIdFactory = new TestMessageId.Factory(); + private final MessageId messageId = messageIdFactory.generate(); + private final String serializedAdditionalInformation = "{\"type\": \"deleted-messages-delete\", \"username\":\"james\", \"deleteMessageId\": \"" + messageId.serialize() + "\", \"timestamp\":\"2018-11-13T12:00:55Z\"}"; + + @Test + void additionalInformationShouldBeSerializable() throws Exception { + JsonSerializationVerifier.dtoModule(WebAdminDeletedMessagesVaultDeleteTaskAdditionalInformationDTO.serializationModule(messageIdFactory)) + .bean(new DeletedMessagesVaultDeleteTask.AdditionalInformation(username, messageId, TIMESTAMP)) + .json(serializedAdditionalInformation) + .verify(); + } +} \ No newline at end of file diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskSerializationTest.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskSerializationTest.java new file mode 100644 index 0000000..71e73d1 --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/WebAdminDeletedMessagesVaultRestoreTaskSerializationTest.java @@ -0,0 +1,41 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.vault.routes; + +import java.time.Instant; + +import org.apache.james.JsonSerializationVerifier; +import org.apache.james.core.Username; +import org.junit.jupiter.api.Test; + +class WebAdminDeletedMessagesVaultRestoreTaskSerializationTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + private static final String USERNAME = "james"; + private static final Username USERNAME_TO_RESTORE = Username.of(USERNAME); + private static final DeletedMessagesVaultRestoreTask.AdditionalInformation DETAILS = new DeletedMessagesVaultRestoreTask.AdditionalInformation(USERNAME_TO_RESTORE,42, 10, TIMESTAMP); + private static final String SERIALIZED_ADDITIONAL_INFORMATION_TASK = "{\"type\":\"deleted-messages-restore\", \"username\":\"james\",\"successfulRestoreCount\":42,\"errorRestoreCount\":10, \"timestamp\":\"2018-11-13T12:00:55Z\"}"; + + @Test + void additionalInformationShouldBeSerializable() throws Exception { + JsonSerializationVerifier.dtoModule(WebAdminDeletedMessagesVaultRestoreTaskAdditionalInformationDTO.MODULE) + .bean(DETAILS) + .json(SERIALIZED_ADDITIONAL_INFORMATION_TASK) + .verify(); + } +} \ No newline at end of file diff --git a/server/protocols/webadmin/webadmin-mailbox/pom.xml b/server/protocols/webadmin/webadmin-mailbox/pom.xml index 44fd413..c4868ce 100644 --- a/server/protocols/webadmin/webadmin-mailbox/pom.xml +++ b/server/protocols/webadmin/webadmin-mailbox/pom.xml @@ -71,7 +71,6 @@ <dependency> <groupId>${james.groupId}</groupId> <artifactId>apache-james-mailbox-tools-indexer</artifactId> - <scope>test</scope> </dependency> <dependency> <groupId>${james.groupId}</groupId> diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailures.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailures.java similarity index 98% rename from mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailures.java rename to server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailures.java index 5c7c489..cd8fe9f 100644 --- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailures.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailures.java @@ -17,7 +17,7 @@ * under the License. * ****************************************************************/ -package org.apache.mailbox.tools.indexer; +package org.apache.james.webadmin.dto; import java.util.List; diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTO.java new file mode 100644 index 0000000..0c67a50 --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTO.java @@ -0,0 +1,116 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import java.time.Instant; + +import org.apache.commons.lang3.NotImplementedException; +import org.apache.james.json.DTOModule; +import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; +import org.apache.mailbox.tools.indexer.ErrorRecoveryIndexationTask; +import org.apache.mailbox.tools.indexer.FullReindexingTask; +import org.apache.mailbox.tools.indexer.ReprocessingContextInformationDTO; + +public class WebAdminReprocessingContextInformationDTO implements AdditionalInformationDTO { + public static class WebAdminErrorRecoveryIndexationDTO extends WebAdminReprocessingContextInformationDTO { + public static AdditionalInformationDTOModule<ReprocessingContextInformationDTO.ReprocessingContextInformationForErrorRecoveryIndexationTask, WebAdminErrorRecoveryIndexationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) { + return DTOModule.forDomainObject(ReprocessingContextInformationDTO.ReprocessingContextInformationForErrorRecoveryIndexationTask.class) + .convertToDTO(WebAdminErrorRecoveryIndexationDTO.class) + .toDomainObjectConverter(dto -> { + throw new NotImplementedException("Deserialization not implemented for this DTO"); + }) + .toDTOConverter((details, type) -> new WebAdminErrorRecoveryIndexationDTO( + type, + details.getSuccessfullyReprocessedMailCount(), + details.getFailedReprocessedMailCount(), + SerializableReIndexingExecutionFailures.from(details.failures()), + details.timestamp())) + .typeName(ErrorRecoveryIndexationTask.PREVIOUS_FAILURES_INDEXING.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + WebAdminErrorRecoveryIndexationDTO(String type, int successfullyReprocessedMailCount, int failedReprocessedMailCount, + SerializableReIndexingExecutionFailures failures, Instant timestamp) { + super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp); + } + } + + public static class WebAdminFullIndexationDTO extends WebAdminReprocessingContextInformationDTO { + public static AdditionalInformationDTOModule<ReprocessingContextInformationDTO.ReprocessingContextInformationForFullReindexingTask, WebAdminFullIndexationDTO> serializationModule(MailboxId.Factory mailboxIdFactory) { + return DTOModule.forDomainObject(ReprocessingContextInformationDTO.ReprocessingContextInformationForFullReindexingTask.class) + .convertToDTO(WebAdminFullIndexationDTO.class) + .toDomainObjectConverter(dto -> { + throw new NotImplementedException("Deserialization not implemented for this DTO"); + }) + .toDTOConverter((details, type) -> new WebAdminFullIndexationDTO( + type, + details.getSuccessfullyReprocessedMailCount(), + details.getFailedReprocessedMailCount(), + SerializableReIndexingExecutionFailures.from(details.failures()), + details.timestamp())) + .typeName(FullReindexingTask.FULL_RE_INDEXING.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + WebAdminFullIndexationDTO(String type, int successfullyReprocessedMailCount, int failedReprocessedMailCount, + SerializableReIndexingExecutionFailures failures, Instant timestamp) { + super(type, successfullyReprocessedMailCount, failedReprocessedMailCount, failures, timestamp); + } + + } + + protected final String type; + protected final int successfullyReprocessedMailCount; + protected final int failedReprocessedMailCount; + protected final SerializableReIndexingExecutionFailures failures; + protected final Instant timestamp; + + + WebAdminReprocessingContextInformationDTO(String type, int successfullyReprocessedMailCount, int failedReprocessedMailCount, + SerializableReIndexingExecutionFailures failures, Instant timestamp) { + this.type = type; + this.successfullyReprocessedMailCount = successfullyReprocessedMailCount; + this.failedReprocessedMailCount = failedReprocessedMailCount; + this.failures = failures; + this.timestamp = timestamp; + } + + public int getSuccessfullyReprocessedMailCount() { + return successfullyReprocessedMailCount; + } + + public int getFailedReprocessedMailCount() { + return failedReprocessedMailCount; + } + + public SerializableReIndexingExecutionFailures getFailures() { + return failures; + } + + public Instant getTimestamp() { + return timestamp; + } + + @Override + public String getType() { + return type; + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..6574e7a --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.java @@ -0,0 +1,94 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import java.time.Instant; + +import org.apache.commons.lang3.NotImplementedException; +import org.apache.james.json.DTOModule; +import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; +import org.apache.mailbox.tools.indexer.SingleMailboxReindexingTask; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static AdditionalInformationDTOModule<SingleMailboxReindexingTask.AdditionalInformation, WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO> serializationModule(MailboxId.Factory factory) { + return DTOModule.forDomainObject(SingleMailboxReindexingTask.AdditionalInformation.class) + .convertToDTO(WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(dto -> { + throw new NotImplementedException("Deserialization not implemented for this DTO"); + }) + .toDTOConverter((details, type) -> new WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO( + type, + details.getMailboxId(), + details.getSuccessfullyReprocessedMailCount(), + details.getFailedReprocessedMailCount(), + SerializableReIndexingExecutionFailures.from(details.failures()), + details.timestamp())) + .typeName(SingleMailboxReindexingTask.MAILBOX_RE_INDEXING.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + private final WebAdminReprocessingContextInformationDTO reprocessingContextInformationDTO; + private final String mailboxId; + + @JsonCreator + private WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("mailboxId") String mailboxId, + @JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount, + @JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount, + @JsonProperty("failures") SerializableReIndexingExecutionFailures failures, + @JsonProperty("timestamp") Instant timestamp) { + this.mailboxId = mailboxId; + this.reprocessingContextInformationDTO = new WebAdminReprocessingContextInformationDTO( + type, + successfullyReprocessedMailCount, + failedReprocessedMailCount, failures, + timestamp); + } + + @Override + public String getType() { + return reprocessingContextInformationDTO.getType(); + } + + public Instant getTimestamp() { + return reprocessingContextInformationDTO.getTimestamp(); + } + + public String getMailboxId() { + return mailboxId; + } + + public int getSuccessfullyReprocessedMailCount() { + return reprocessingContextInformationDTO.getSuccessfullyReprocessedMailCount(); + } + + public int getFailedReprocessedMailCount() { + return reprocessingContextInformationDTO.getFailedReprocessedMailCount(); + } + + public SerializableReIndexingExecutionFailures getFailures() { + return reprocessingContextInformationDTO.getFailures(); + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminUserReindexingTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminUserReindexingTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..9d5c17a --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/WebAdminUserReindexingTaskAdditionalInformationDTO.java @@ -0,0 +1,93 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import java.time.Instant; + +import org.apache.commons.lang3.NotImplementedException; +import org.apache.james.json.DTOModule; +import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; +import org.apache.mailbox.tools.indexer.UserReindexingTask; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminUserReindexingTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static AdditionalInformationDTOModule<UserReindexingTask.AdditionalInformation, WebAdminUserReindexingTaskAdditionalInformationDTO> serializationModule(MailboxId.Factory factory) { + return DTOModule.forDomainObject(UserReindexingTask.AdditionalInformation.class) + .convertToDTO(WebAdminUserReindexingTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(dto -> { + throw new NotImplementedException("Deserialization not implemented for this DTO"); + }) + .toDTOConverter((details, type) -> new WebAdminUserReindexingTaskAdditionalInformationDTO( + type, + details.getUsername(), + details.getSuccessfullyReprocessedMailCount(), + details.getFailedReprocessedMailCount(), + SerializableReIndexingExecutionFailures.from(details.failures()), + details.timestamp())) + .typeName(UserReindexingTask.USER_RE_INDEXING.asString()) + .withFactory(AdditionalInformationDTOModule::new); + } + + private final WebAdminReprocessingContextInformationDTO reprocessingContextInformationDTO; + private final String username; + + @JsonCreator + private WebAdminUserReindexingTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("username") String username, + @JsonProperty("successfullyReprocessedMailCount") int successfullyReprocessedMailCount, + @JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount, + @JsonProperty("failures") SerializableReIndexingExecutionFailures failures, + @JsonProperty("timestamp") Instant timestamp) { + this.username = username; + this.reprocessingContextInformationDTO = new WebAdminReprocessingContextInformationDTO( + type, + successfullyReprocessedMailCount, + failedReprocessedMailCount, failures, timestamp); + } + + @Override + public String getType() { + return reprocessingContextInformationDTO.getType(); + } + + public Instant getTimestamp() { + return reprocessingContextInformationDTO.getTimestamp(); + } + + public String getUsername() { + return username; + } + + public int getSuccessfullyReprocessedMailCount() { + return reprocessingContextInformationDTO.getSuccessfullyReprocessedMailCount(); + } + + public int getFailedReprocessedMailCount() { + return reprocessingContextInformationDTO.getFailedReprocessedMailCount(); + } + + public SerializableReIndexingExecutionFailures getFailures() { + return reprocessingContextInformationDTO.getFailures(); + } +} diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailuresTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailuresTest.java similarity index 98% rename from mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailuresTest.java rename to server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailuresTest.java index 5ef546a..e9ad633 100644 --- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SerializableReIndexingExecutionFailuresTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/SerializableReIndexingExecutionFailuresTest.java @@ -17,7 +17,7 @@ * under the License. * ****************************************************************/ -package org.apache.mailbox.tools.indexer; +package org.apache.james.webadmin.dto; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTOTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTOTest.java new file mode 100644 index 0000000..c8d25af --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminReprocessingContextInformationDTOTest.java @@ -0,0 +1,111 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Instant; +import java.util.List; + +import org.apache.james.json.JsonGenericSerializer; +import org.apache.james.mailbox.MessageUid; +import org.apache.james.mailbox.indexer.ReIndexer; +import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures; +import org.apache.james.mailbox.model.TestId; +import org.apache.mailbox.tools.indexer.ReprocessingContextInformationDTO; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; +import com.google.common.collect.ImmutableList; + +class WebAdminReprocessingContextInformationDTOTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private final String serializedErrorRecoveryAdditionalInformation = "{\"type\":\"error-recovery-indexation\",\"successfullyReprocessedMailCount\":42,\"failedReprocessedMailCount\":2,\"failures\":{\"1\":[{\"uid\":10}],\"2\":[{\"uid\":20}]},\"timestamp\":\"2018-11-13T12:00:55Z\"}"; + private final String serializedFullAdditionalInformation = "{\"type\":\"full-reindexing\",\"successfullyReprocessedMailCount\":42,\"failedReprocessedMailCount\":2,\"failures\":{\"1\":[{\"uid\":10}],\"2\":[{\"uid\":20}]},\"timestamp\":\"2018-11-13T12:00:55Z\"}"; + + private final TestId mailboxId = TestId.of(1L); + private final MessageUid messageUid = MessageUid.of(10L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId, messageUid); + private final TestId mailboxId2 = TestId.of(2L); + private final MessageUid messageUid2 = MessageUid.of(20L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure2 = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId2, messageUid2); + private final List<ReIndexingExecutionFailures.ReIndexingFailure> failures = ImmutableList.of(indexingFailure, indexingFailure2); + private final ReIndexingExecutionFailures executionFailures = new ReIndexingExecutionFailures(failures); + + @Test + void shouldSerializeErrorRecoveryAdditionalInformation() throws Exception { + ReprocessingContextInformationDTO.ReprocessingContextInformationForErrorRecoveryIndexationTask domainObject = + new ReprocessingContextInformationDTO.ReprocessingContextInformationForErrorRecoveryIndexationTask( + 42, + 2, + executionFailures, + TIMESTAMP, + ReIndexer.RunningOptions.DEFAULT); + + String json = + JsonGenericSerializer.forModules(WebAdminReprocessingContextInformationDTO.WebAdminErrorRecoveryIndexationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .serialize(domainObject); + + assertThatJson(json) + .isEqualTo(serializedErrorRecoveryAdditionalInformation); + } + + @Test + void deserializeErrorRecoveryShouldNotBeSupported() { + assertThatThrownBy(() -> JsonGenericSerializer.forModules(WebAdminReprocessingContextInformationDTO.WebAdminErrorRecoveryIndexationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .deserialize(serializedErrorRecoveryAdditionalInformation)) + .isInstanceOf(InvalidDefinitionException.class); + } + + @Test + void shouldSerializeFullAdditionalInformation() throws Exception { + ReprocessingContextInformationDTO.ReprocessingContextInformationForFullReindexingTask domainObject = + new ReprocessingContextInformationDTO.ReprocessingContextInformationForFullReindexingTask( + 42, + 2, + executionFailures, + TIMESTAMP, + ReIndexer.RunningOptions.DEFAULT); + + String json = + JsonGenericSerializer.forModules(WebAdminReprocessingContextInformationDTO.WebAdminFullIndexationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .serialize(domainObject); + + assertThatJson(json) + .isEqualTo(serializedFullAdditionalInformation); + } + + @Test + void deserializeFullShouldNotBeSupported() { + assertThatThrownBy(() -> JsonGenericSerializer.forModules(WebAdminReprocessingContextInformationDTO.WebAdminFullIndexationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .deserialize(serializedFullAdditionalInformation)) + .isInstanceOf(InvalidDefinitionException.class); + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReprocessingDTOTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReprocessingDTOTest.java new file mode 100644 index 0000000..30bd411 --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminSingleMailboxReprocessingDTOTest.java @@ -0,0 +1,82 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Instant; +import java.util.List; + +import org.apache.james.json.JsonGenericSerializer; +import org.apache.james.mailbox.MessageUid; +import org.apache.james.mailbox.indexer.ReIndexer; +import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures; +import org.apache.james.mailbox.model.TestId; +import org.apache.mailbox.tools.indexer.ReprocessingContextInformationDTO; +import org.apache.mailbox.tools.indexer.SingleMailboxReindexingTask; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; +import com.google.common.collect.ImmutableList; + +class WebAdminSingleMailboxReprocessingDTOTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private final String serializedAdditionalInformation = "{\"type\":\"mailbox-reindexing\",\"mailboxId\":\"1\",\"successfullyReprocessedMailCount\":42,\"failedReprocessedMailCount\":2,\"failures\":{\"1\":[{\"uid\":10}],\"2\":[{\"uid\":20}]},\"timestamp\":\"2018-11-13T12:00:55Z\"}"; + + private final TestId mailboxId = TestId.of(1L); + private final MessageUid messageUid = MessageUid.of(10L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId, messageUid); + private final TestId mailboxId2 = TestId.of(2L); + private final MessageUid messageUid2 = MessageUid.of(20L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure2 = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId2, messageUid2); + private final List<ReIndexingExecutionFailures.ReIndexingFailure> failures = ImmutableList.of(indexingFailure, indexingFailure2); + private final ReIndexingExecutionFailures executionFailures = new ReIndexingExecutionFailures(failures); + + @Test + void shouldSerializeAdditionalInformation() throws Exception { + SingleMailboxReindexingTask.AdditionalInformation domainObject = + new SingleMailboxReindexingTask.AdditionalInformation( + mailboxId, + 42, + 2, + executionFailures, + TIMESTAMP, + ReIndexer.RunningOptions.DEFAULT); + + String json = + JsonGenericSerializer.forModules(WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .serialize(domainObject); + + assertThatJson(json) + .isEqualTo(serializedAdditionalInformation); + } + + @Test + void deserializeShouldNotBeSupported() { + assertThatThrownBy(() -> JsonGenericSerializer.forModules(WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .deserialize(serializedAdditionalInformation)) + .isInstanceOf(InvalidDefinitionException.class); + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminUserReprocessingDTOTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminUserReprocessingDTOTest.java new file mode 100644 index 0000000..9ea55a7 --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/dto/WebAdminUserReprocessingDTOTest.java @@ -0,0 +1,83 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.dto; + +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Instant; +import java.util.List; + +import org.apache.james.core.Username; +import org.apache.james.json.JsonGenericSerializer; +import org.apache.james.mailbox.MessageUid; +import org.apache.james.mailbox.indexer.ReIndexer; +import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures; +import org.apache.james.mailbox.model.TestId; +import org.apache.mailbox.tools.indexer.SingleMailboxReindexingTask; +import org.apache.mailbox.tools.indexer.UserReindexingTask; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; +import com.google.common.collect.ImmutableList; + +class WebAdminUserReprocessingDTOTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private final String serializedAdditionalInformation = "{\"type\":\"user-reindexing\",\"username\":\"bob\",\"successfullyReprocessedMailCount\":42,\"failedReprocessedMailCount\":2,\"failures\":{\"1\":[{\"uid\":10}],\"2\":[{\"uid\":20}]},\"timestamp\":\"2018-11-13T12:00:55Z\"}"; + + private final TestId mailboxId = TestId.of(1L); + private final MessageUid messageUid = MessageUid.of(10L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId, messageUid); + private final TestId mailboxId2 = TestId.of(2L); + private final MessageUid messageUid2 = MessageUid.of(20L); + private final ReIndexingExecutionFailures.ReIndexingFailure indexingFailure2 = new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId2, messageUid2); + private final List<ReIndexingExecutionFailures.ReIndexingFailure> failures = ImmutableList.of(indexingFailure, indexingFailure2); + private final ReIndexingExecutionFailures executionFailures = new ReIndexingExecutionFailures(failures); + + @Test + void shouldSerializeAdditionalInformation() throws Exception { + UserReindexingTask.AdditionalInformation domainObject = + new UserReindexingTask.AdditionalInformation( + Username.of("bob"), + 42, + 2, + executionFailures, + TIMESTAMP, + ReIndexer.RunningOptions.DEFAULT); + + String json = + JsonGenericSerializer.forModules(WebAdminUserReindexingTaskAdditionalInformationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .serialize(domainObject); + + assertThatJson(json) + .isEqualTo(serializedAdditionalInformation); + } + + @Test + void deserializeShouldNotBeSupported() { + assertThatThrownBy(() -> JsonGenericSerializer.forModules(WebAdminUserReindexingTaskAdditionalInformationDTO + .serializationModule(new TestId.Factory())) + .withoutNestedType() + .deserialize(serializedAdditionalInformation)) + .isInstanceOf(InvalidDefinitionException.class); + } +} diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java index f5b0c4f..eb08117 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.Matchers.nullValue; import org.apache.james.core.Username; import org.apache.james.event.json.EventSerializer; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.events.Event; import org.apache.james.mailbox.events.EventBus; @@ -59,6 +60,9 @@ import org.apache.james.webadmin.service.EventDeadLettersRedeliverAllTask; import org.apache.james.webadmin.service.EventDeadLettersRedeliverGroupTask; import org.apache.james.webadmin.service.EventDeadLettersRedeliverOneTask; import org.apache.james.webadmin.service.EventDeadLettersRedeliverService; +import org.apache.james.webadmin.service.EventDeadLettersRedeliveryTaskAdditionalInformationDTO.EventDeadLettersRedeliveryTaskAdditionalInformationForAll; +import org.apache.james.webadmin.service.EventDeadLettersRedeliveryTaskAdditionalInformationDTO.EventDeadLettersRedeliveryTaskAdditionalInformationForGroup; +import org.apache.james.webadmin.service.EventDeadLettersRedeliveryTaskAdditionalInformationDTO.EventDeadLettersRedeliveryTaskAdditionalInformationForOne; import org.apache.james.webadmin.service.EventDeadLettersService; import org.apache.james.webadmin.utils.ErrorResponder; import org.apache.james.webadmin.utils.JsonTransformer; @@ -123,7 +127,10 @@ class EventDeadLettersRoutesTest { taskManager = new MemoryTaskManager(new Hostname("foo")); webAdminServer = WebAdminUtils.createWebAdminServer( new EventDeadLettersRoutes(service, eventSerializer, taskManager, jsonTransformer), - new TasksRoutes(taskManager, jsonTransformer)) + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(EventDeadLettersRedeliveryTaskAdditionalInformationForOne.MODULE, + EventDeadLettersRedeliveryTaskAdditionalInformationForGroup.MODULE, + EventDeadLettersRedeliveryTaskAdditionalInformationForAll.MODULE))) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer).build(); diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesNoTasksTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesNoTasksTest.java index 2a3b1d1..915454f 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesNoTasksTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesNoTasksTest.java @@ -21,6 +21,7 @@ package org.apache.james.webadmin.routes; import static io.restassured.RestAssured.when; +import org.apache.james.json.DTOConverter; import org.apache.james.task.Hostname; import org.apache.james.task.MemoryTaskManager; import org.apache.james.webadmin.WebAdminServer; @@ -49,7 +50,7 @@ class MailboxesRoutesNoTasksTest { JsonTransformer jsonTransformer = new JsonTransformer(); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, DTOConverter.of()), new MailboxesRoutes(taskManager, jsonTransformer, NO_ADDITIONAL_REGISTRATION, diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesTest.java index c8c29cc..56a2290 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MailboxesRoutesTest.java @@ -33,6 +33,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import org.apache.james.core.Username; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.indexer.ReIndexer; @@ -49,15 +50,24 @@ import org.apache.james.task.Hostname; import org.apache.james.task.MemoryTaskManager; import org.apache.james.webadmin.WebAdminServer; import org.apache.james.webadmin.WebAdminUtils; +import org.apache.james.webadmin.dto.WebAdminReprocessingContextInformationDTO; +import org.apache.james.webadmin.dto.WebAdminReprocessingContextInformationDTO.WebAdminErrorRecoveryIndexationDTO; +import org.apache.james.webadmin.dto.WebAdminReprocessingContextInformationDTO.WebAdminFullIndexationDTO; +import org.apache.james.webadmin.dto.WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.PreviousReIndexingService; import org.apache.james.webadmin.utils.ErrorResponder; import org.apache.james.webadmin.utils.JsonTransformer; import org.apache.mailbox.tools.indexer.FullReindexingTask; import org.apache.mailbox.tools.indexer.ReIndexerImpl; import org.apache.mailbox.tools.indexer.ReIndexerPerformer; +import org.apache.mailbox.tools.indexer.ReprocessingContextInformationDTO.ReprocessingContextInformationForErrorRecoveryIndexationTask; +import org.apache.mailbox.tools.indexer.ReprocessingContextInformationDTO.ReprocessingContextInformationForFullReindexingTask; import org.apache.mailbox.tools.indexer.SingleMailboxReindexingTask; +import org.apache.mailbox.tools.indexer.SingleMailboxReindexingTaskAdditionalInformationDTO; import org.apache.mailbox.tools.indexer.SingleMessageReindexingTask; +import org.apache.mailbox.tools.indexer.SingleMessageReindexingTaskAdditionalInformationDTO; import org.eclipse.jetty.http.HttpStatus; +import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -97,7 +107,12 @@ class MailboxesRoutesTest { JsonTransformer jsonTransformer = new JsonTransformer(); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of( + WebAdminErrorRecoveryIndexationDTO.serializationModule(mailboxIdFactory), + WebAdminFullIndexationDTO.serializationModule(mailboxIdFactory), + WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.serializationModule(mailboxIdFactory), + SingleMessageReindexingTaskAdditionalInformationDTO.serializationModule(mailboxIdFactory))), new MailboxesRoutes(taskManager, jsonTransformer, ImmutableSet.of( diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MessageRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MessageRoutesTest.java index 45c4d98..bd24736 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MessageRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/MessageRoutesTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import org.apache.james.core.Username; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; @@ -48,6 +49,7 @@ import org.apache.james.webadmin.utils.ErrorResponder; import org.apache.james.webadmin.utils.JsonTransformer; import org.apache.mailbox.tools.indexer.MessageIdReIndexerImpl; import org.apache.mailbox.tools.indexer.MessageIdReIndexingTask; +import org.apache.mailbox.tools.indexer.MessageIdReindexingTaskAdditionalInformationDTO; import org.apache.mailbox.tools.indexer.ReIndexerPerformer; import org.eclipse.jetty.http.HttpStatus; import org.junit.jupiter.api.AfterEach; @@ -85,7 +87,9 @@ class MessageRoutesTest { JsonTransformer jsonTransformer = new JsonTransformer(); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of( + MessageIdReindexingTaskAdditionalInformationDTO.serializationModule(mailboxManager.getMessageIdFactory()))), new MessagesRoutes(taskManager, new InMemoryMessageId.Factory(), new MessageIdReIndexerImpl(reIndexerPerformer), diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesNoIndexationTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesNoIndexationTest.java index bd8b402..71cf564 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesNoIndexationTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesNoIndexationTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.apache.james.core.Username; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.task.Hostname; @@ -65,7 +66,7 @@ class UserMailboxesRoutesNoIndexationTest { new UserMailboxesRoutes(new UserMailboxesService(mailboxManager, usersRepository), new JsonTransformer(), taskManager, ImmutableSet.of()), - new TasksRoutes(taskManager, new JsonTransformer())) + new TasksRoutes(taskManager, new JsonTransformer(), DTOConverter.of())) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java index 5dd021b..2818968 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import org.apache.james.core.Username; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSessionUtil; @@ -71,6 +72,7 @@ import org.apache.james.task.MemoryTaskManager; import org.apache.james.user.api.UsersRepository; import org.apache.james.webadmin.WebAdminServer; import org.apache.james.webadmin.WebAdminUtils; +import org.apache.james.webadmin.dto.WebAdminUserReindexingTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.UserMailboxesService; import org.apache.james.webadmin.utils.JsonTransformer; import org.apache.mailbox.tools.indexer.ReIndexerImpl; @@ -103,7 +105,7 @@ class UserMailboxesRoutesTest { private ListeningMessageSearchIndex searchIndex; private MemoryTaskManager taskManager; - private void createServer(MailboxManager mailboxManager, MailboxSessionMapperFactory mapperFactory) throws Exception { + private void createServer(MailboxManager mailboxManager, MailboxSessionMapperFactory mapperFactory, MailboxId.Factory mailboxIdFactory) throws Exception { usersRepository = mock(UsersRepository.class); when(usersRepository.contains(USERNAME)).thenReturn(true); @@ -125,7 +127,8 @@ class UserMailboxesRoutesTest { new UserMailboxesRoutes(new UserMailboxesService(mailboxManager, usersRepository), new JsonTransformer(), taskManager, ImmutableSet.of(new UserMailboxesRoutes.UserReIndexingTaskRegistration(reIndexer))), - new TasksRoutes(taskManager, new JsonTransformer())) + new TasksRoutes(taskManager, new JsonTransformer(), + DTOConverter.of(WebAdminUserReindexingTaskAdditionalInformationDTO.serializationModule(mailboxIdFactory)))) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) @@ -145,7 +148,7 @@ class UserMailboxesRoutesTest { @BeforeEach void setUp() throws Exception { InMemoryMailboxManager mailboxManager = InMemoryIntegrationResources.defaultResources().getMailboxManager(); - createServer(mailboxManager, mailboxManager.getMapperFactory()); + createServer(mailboxManager, mailboxManager.getMapperFactory(), new InMemoryId.Factory()); } @Test @@ -854,7 +857,7 @@ class UserMailboxesRoutesTest { mailboxManager = mock(MailboxManager.class); when(mailboxManager.createSystemSession(any())).thenReturn(MailboxSessionUtil.create(USERNAME)); - createServer(mailboxManager, mock(MailboxSessionMapperFactory.class)); + createServer(mailboxManager, mock(MailboxSessionMapperFactory.class), new InMemoryId.Factory()); } @Test @@ -1112,7 +1115,7 @@ class UserMailboxesRoutesTest { @BeforeEach void setUp() throws Exception { mailboxManager = InMemoryIntegrationResources.defaultResources().getMailboxManager(); - createServer(mailboxManager, mailboxManager.getMapperFactory()); + createServer(mailboxManager, mailboxManager.getMapperFactory(), new InMemoryId.Factory()); } @Nested @@ -1176,9 +1179,9 @@ class UserMailboxesRoutesTest { given() .basePath(TasksRoutes.BASE) - .when() + .when() .get(taskId + "/await") - .then() + .then() .body("status", Matchers.is("completed")) .body("taskId", Matchers.is(notNullValue())) .body("type", Matchers.is(UserReindexingTask.USER_RE_INDEXING.asString())) diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/WebAdminQuotaSearchTestSystem.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/WebAdminQuotaSearchTestSystem.java index b315dbc..a84d9f7 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/WebAdminQuotaSearchTestSystem.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/WebAdminQuotaSearchTestSystem.java @@ -23,7 +23,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.quota.task.RecomputeCurrentQuotasService; +import org.apache.james.mailbox.quota.task.RecomputeCurrentQuotasTaskAdditionalInformationDTO; import org.apache.james.quota.search.QuotaSearchTestSystem; import org.apache.james.task.Hostname; import org.apache.james.task.MemoryTaskManager; @@ -60,7 +62,8 @@ public class WebAdminQuotaSearchTestSystem { TaskManager taskManager = new MemoryTaskManager(new Hostname("foo")); RecomputeCurrentQuotasService mock = mock(RecomputeCurrentQuotasService.class); when(mock.recomputeCurrentQuotas(any(), any())).thenReturn(Mono.just(Task.Result.COMPLETED)); - TasksRoutes tasksRoutes = new TasksRoutes(taskManager, new JsonTransformer()); + TasksRoutes tasksRoutes = new TasksRoutes(taskManager, new JsonTransformer(), + DTOConverter.of(RecomputeCurrentQuotasTaskAdditionalInformationDTO.MODULE)); UserQuotaRoutes userQuotaRoutes = new UserQuotaRoutes(quotaSearchTestSystem.getUsersRepository(), userQuotaService, jsonTransformer, diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/service/MailboxesExportRequestToTaskTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/service/MailboxesExportRequestToTaskTest.java index 0e856dc..e518170 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/service/MailboxesExportRequestToTaskTest.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/service/MailboxesExportRequestToTaskTest.java @@ -37,6 +37,7 @@ import java.util.Optional; import org.apache.james.blob.export.file.FileSystemExtension; import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.json.DTOConverter; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.backup.ZipAssert; @@ -111,7 +112,8 @@ class MailboxesExportRequestToTaskTest { JsonTransformer jsonTransformer = new JsonTransformer(); webAdminServer = WebAdminUtils.createWebAdminServer( - new TasksRoutes(taskManager, jsonTransformer), + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(MailboxesExportTaskAdditionalInformationDTO.SERIALIZATION_MODULE)), new ExportRoutes( new ExportService(testSystem.backup, testSystem.blobStore, testSystem.blobExport, testSystem.usersRepository), taskManager, testSystem.usersRepository)) diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..dd62fdb --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.java @@ -0,0 +1,110 @@ +package org.apache.james.webadmin.service; + +import java.time.Instant; +import java.util.Optional; + +import org.apache.james.core.MailAddress; +import org.apache.james.json.DTOModule; +import org.apache.james.queue.api.MailQueueName; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.fge.lambdas.Throwing; + +public class WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static final AdditionalInformationDTOModule<DeleteMailsFromMailQueueTask.AdditionalInformation, WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO> MODULE = + DTOModule + .forDomainObject(DeleteMailsFromMailQueueTask.AdditionalInformation.class) + .convertToDTO(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO::fromDTO) + .toDTOConverter(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO::toDTO) + .typeName(DeleteMailsFromMailQueueTask.TYPE.asString()) + .withFactory(AdditionalInformationDTOModule::new); + + private static WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO toDTO(DeleteMailsFromMailQueueTask.AdditionalInformation domainObject, String typeName) { + return new WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO( + typeName, + domainObject.getMailQueueName(), + domainObject.getSender(), + domainObject.getName(), + domainObject.getRecipient(), + domainObject.getInitialCount(), + domainObject.getRemainingCount(), + domainObject.timestamp()); + } + + private static DeleteMailsFromMailQueueTask.AdditionalInformation fromDTO(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO dto) { + return new DeleteMailsFromMailQueueTask.AdditionalInformation( + MailQueueName.of(dto.getMailQueueName()), + dto.getInitialCount(), + dto.getRemainingCount(), + dto.sender.map(Throwing.<String, MailAddress>function(MailAddress::new).sneakyThrow()), + dto.name, + dto.recipient.map(Throwing.<String, MailAddress>function(MailAddress::new).sneakyThrow()), + dto.timestamp); + } + + private final String mailQueueName; + private final String type; + private final Optional<String> sender; + private final Optional<String> name; + private final Optional<String> recipient; + private final long initialCount; + private final long remainingCount; + private final Instant timestamp; + + public WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("mailQueueName") String mailQueueName, + @JsonProperty("sender") Optional<String> sender, + @JsonProperty("name") Optional<String> name, + @JsonProperty("recipient") Optional<String> recipient, + @JsonProperty("initialCount") long initialCount, + @JsonProperty("remainingCount") long remainingCount, + @JsonProperty("timestamp") Instant timestamp) { + this.type = type; + this.mailQueueName = mailQueueName; + this.sender = sender; + this.name = name; + this.recipient = recipient; + this.initialCount = initialCount; + this.remainingCount = remainingCount; + this.timestamp = timestamp; + } + + + public String getMailQueueName() { + return mailQueueName; + } + + public Optional<String> getSender() { + return sender; + } + + public Optional<String> getName() { + return name; + } + + public Optional<String> getRecipient() { + return recipient; + } + + public long getInitialCount() { + return initialCount; + } + + public long getRemainingCount() { + return remainingCount; + } + + @Override + public Instant getTimestamp() { + return timestamp; + } + + @Override + public String getType() { + return type; + } +} \ No newline at end of file diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java index 6ba4b07..d16dd01 100644 --- a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.james.core.MailAddress; +import org.apache.james.json.DTOConverter; import org.apache.james.queue.api.MailQueueName; import org.apache.james.queue.api.Mails; import org.apache.james.queue.api.ManageableMailQueue; @@ -49,7 +50,10 @@ import org.apache.james.task.TaskManager; import org.apache.james.webadmin.WebAdminServer; import org.apache.james.webadmin.WebAdminUtils; import org.apache.james.webadmin.service.ClearMailQueueTask; +import org.apache.james.webadmin.service.ClearMailQueueTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.DeleteMailsFromMailQueueTask; +import org.apache.james.webadmin.service.DeleteMailsFromMailQueueTaskAdditionalInformationDTO; +import org.apache.james.webadmin.service.WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO; import org.apache.james.webadmin.utils.JsonTransformer; import org.apache.mailet.Mail; import org.apache.mailet.base.test.FakeMail; @@ -91,7 +95,9 @@ class MailQueueRoutesTest { return WebAdminUtils.createWebAdminServer( new MailQueueRoutes(mailQueueFactory, jsonTransformer, taskManager), - new TasksRoutes(taskManager, jsonTransformer)) + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.MODULE, + ClearMailQueueTaskAdditionalInformationDTO.SERIALIZATION_MODULE))) .start(); } diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTOTest.java b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTOTest.java new file mode 100644 index 0000000..9d6986a --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/service/WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTOTest.java @@ -0,0 +1,51 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + * ***************************************************************/ + +package org.apache.james.webadmin.service; + +import java.time.Instant; +import java.util.Optional; + +import org.apache.james.JsonSerializationVerifier; +import org.apache.james.core.MailAddress; +import org.apache.james.queue.api.MailQueueName; +import org.junit.jupiter.api.Test; + +class WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTOTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private final static MailQueueName queueName = MailQueueName.of("anyQueue"); + + @Test + void additionalInformationShouldBeSerializable() throws Exception { + DeleteMailsFromMailQueueTask.AdditionalInformation detailsSender = new DeleteMailsFromMailQueueTask.AdditionalInformation(queueName, 10L, 5L, + Optional.of(new MailAddress("a@b.c")), Optional.empty(), Optional.empty(), TIMESTAMP); + DeleteMailsFromMailQueueTask.AdditionalInformation detailsName = new DeleteMailsFromMailQueueTask.AdditionalInformation(queueName, 1L, 0L, + Optional.empty(), Optional.of("name"), Optional.empty(), TIMESTAMP); + DeleteMailsFromMailQueueTask.AdditionalInformation detailsRecipient = new DeleteMailsFromMailQueueTask.AdditionalInformation(queueName, 6L, 6L, + Optional.empty(), Optional.empty(), Optional.of(new MailAddress("d@e.f")), TIMESTAMP); + + JsonSerializationVerifier.dtoModule(WebAdminDeleteMailsFromMailQueueTaskAdditionalInformationDTO.MODULE) + .testCase(detailsSender, + "{\"type\": \"delete-mails-from-mail-queue\", \"mailQueueName\": \"anyQueue\", \"sender\": \"a@b.c\", \"initialCount\" : 10, \"remainingCount\":5, \"timestamp\": \"2018-11-13T12:00:55Z\"}") + .testCase(detailsName, + "{\"type\": \"delete-mails-from-mail-queue\", \"mailQueueName\": \"anyQueue\", \"name\": \"name\", \"initialCount\" : 1, \"remainingCount\":0, \"timestamp\": \"2018-11-13T12:00:55Z\"}") + .testCase(detailsRecipient, + "{\"type\": \"delete-mails-from-mail-queue\", \"mailQueueName\": \"anyQueue\", \"recipient\": \"d@e.f\", \"initialCount\" : 6, \"remainingCount\":6, \"timestamp\": \"2018-11-13T12:00:55Z\"}") + .verify(); + } +} \ No newline at end of file diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskAdditionalInformationDTO.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskAdditionalInformationDTO.java new file mode 100644 index 0000000..25acd2e --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskAdditionalInformationDTO.java @@ -0,0 +1,88 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.webadmin.service; + +import java.time.Instant; + +import org.apache.james.json.DTOModule; +import org.apache.james.mailrepository.api.MailRepositoryPath; +import org.apache.james.server.task.json.dto.AdditionalInformationDTO; +import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WebAdminClearMailRepositoryTaskAdditionalInformationDTO implements AdditionalInformationDTO { + + public static final AdditionalInformationDTOModule<ClearMailRepositoryTask.AdditionalInformation, WebAdminClearMailRepositoryTaskAdditionalInformationDTO> SERIALIZATION_MODULE = + DTOModule.forDomainObject(ClearMailRepositoryTask.AdditionalInformation.class) + .convertToDTO(WebAdminClearMailRepositoryTaskAdditionalInformationDTO.class) + .toDomainObjectConverter(dto -> new ClearMailRepositoryTask.AdditionalInformation( + MailRepositoryPath.from(dto.repositoryPath), + dto.initialCount, + dto.remainingCount, + dto.timestamp + )) + .toDTOConverter((details, type) -> new WebAdminClearMailRepositoryTaskAdditionalInformationDTO( + type, + details.getRepositoryPath(), + details.getInitialCount(), + details.getRemainingCount(), + details.timestamp())) + .typeName(ClearMailRepositoryTask.TYPE.asString()) + .withFactory(AdditionalInformationDTOModule::new); + + private final String repositoryPath; + private final String type; + private final long initialCount; + private final long remainingCount; + private final Instant timestamp; + + public WebAdminClearMailRepositoryTaskAdditionalInformationDTO(@JsonProperty("type") String type, + @JsonProperty("repositoryPath") String repositoryPath, + @JsonProperty("initialCount") long initialCount, + @JsonProperty("remainingCount") long remainingCount, + @JsonProperty("timestamp") Instant timestamp) { + this.type = type; + this.repositoryPath = repositoryPath; + this.initialCount = initialCount; + this.remainingCount = remainingCount; + this.timestamp = timestamp; + } + + public String getRepositoryPath() { + return repositoryPath; + } + + public long getInitialCount() { + return initialCount; + } + + public long getRemainingCount() { + return remainingCount; + } + + public Instant getTimestamp() { + return timestamp; + } + + @Override + public String getType() { + return type; + } +} diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java index b69d674..6444bee 100644 --- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java +++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java @@ -49,6 +49,7 @@ import org.apache.commons.configuration2.BaseHierarchicalConfiguration; import org.apache.james.core.MailAddress; import org.apache.james.core.builder.MimeMessageBuilder; import org.apache.james.core.builder.MimeMessageBuilder.BodyPartBuilder; +import org.apache.james.json.DTOConverter; import org.apache.james.mailrepository.api.MailKey; import org.apache.james.mailrepository.api.MailRepository; import org.apache.james.mailrepository.api.MailRepositoryPath; @@ -71,10 +72,14 @@ import org.apache.james.webadmin.Constants; import org.apache.james.webadmin.WebAdminServer; import org.apache.james.webadmin.WebAdminUtils; import org.apache.james.webadmin.service.ClearMailRepositoryTask; +import org.apache.james.webadmin.service.ClearMailRepositoryTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.MailRepositoryStoreService; import org.apache.james.webadmin.service.ReprocessingAllMailsTask; +import org.apache.james.webadmin.service.ReprocessingAllMailsTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.ReprocessingOneMailTask; +import org.apache.james.webadmin.service.ReprocessingOneMailTaskAdditionalInformationDTO; import org.apache.james.webadmin.service.ReprocessingService; +import org.apache.james.webadmin.service.WebAdminClearMailRepositoryTaskAdditionalInformationDTO; import org.apache.james.webadmin.utils.ErrorResponder; import org.apache.james.webadmin.utils.JsonTransformer; import org.apache.mailet.Attribute; @@ -125,7 +130,10 @@ public class MailRepositoriesRoutesTest { webAdminServer = WebAdminUtils.createWebAdminServer( new MailRepositoriesRoutes(repositoryStoreService, jsonTransformer, reprocessingService, taskManager), - new TasksRoutes(taskManager, jsonTransformer)) + new TasksRoutes(taskManager, jsonTransformer, + DTOConverter.of(ReprocessingOneMailTaskAdditionalInformationDTO.SERIALIZATION_MODULE, + ReprocessingAllMailsTaskAdditionalInformationDTO.SERIALIZATION_MODULE, + WebAdminClearMailRepositoryTaskAdditionalInformationDTO.SERIALIZATION_MODULE))) .start(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskDTOTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskDTOTest.java new file mode 100644 index 0000000..4496652 --- /dev/null +++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/WebAdminClearMailRepositoryTaskDTOTest.java @@ -0,0 +1,44 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.webadmin.service; + +import java.time.Instant; + +import org.apache.james.JsonSerializationVerifier; +import org.apache.james.mailrepository.api.MailRepositoryPath; +import org.junit.jupiter.api.Test; + +class WebAdminClearMailRepositoryTaskDTOTest { + private static final Instant TIMESTAMP = Instant.parse("2018-11-13T12:00:55Z"); + + private static final String SERIALIZED_TASK_ADDITIONAL_INFORMATION = "{\"type\":\"clear-mail-repository\", \"repositoryPath\":\"a\", \"initialCount\": 0, \"remainingCount\": 10, \"timestamp\":\"2018-11-13T12:00:55Z\"}"; + private static final MailRepositoryPath MAIL_REPOSITORY_PATH = MailRepositoryPath.from("a"); + private static final long INITIAL_COUNT = 0L; + private static final long REMAINING_COUNT = 10L; + + + @Test + void additionalInformationShouldBeSerializable() throws Exception { + JsonSerializationVerifier.dtoModule(WebAdminClearMailRepositoryTaskAdditionalInformationDTO.SERIALIZATION_MODULE) + .bean(new ClearMailRepositoryTask.AdditionalInformation(MAIL_REPOSITORY_PATH, INITIAL_COUNT, REMAINING_COUNT, TIMESTAMP)) + .json(SERIALIZED_TASK_ADDITIONAL_INFORMATION) + .verify(); + } +} \ No newline at end of file diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md index 8f2f797..806c67f 100644 --- a/src/site/markdown/server/manage-webadmin.md +++ b/src/site/markdown/server/manage-webadmin.md @@ -601,10 +601,11 @@ The scheduled task will have the following type `full-reindexing` and the follow }, "successfullyReprocessedMailCount":18, "failedReprocessedMailCount": 3, - "failures": { - "mbx1": [{"uid": 35}, {"uid": 45}], - "mbx2": [{"uid": 38}] - } + "failures": [ + { + "mailboxId": "1", + "uids": [1, 36] + }] } ``` @@ -642,10 +643,10 @@ The scheduled task will have the following type `error-recovery-indexation` and }, "successfullyReprocessedMailCount":18, "failedReprocessedMailCount": 3, - "failures": { - "mbx1": [{"uid": 35}, {"uid": 45}], - "mbx2": [{"uid": 38}] - } + "failures": [{ + "mailboxId": "1", + "uids": [1, 36] + }] } ``` @@ -694,10 +695,11 @@ The scheduled task will have the following type `mailbox-reindexing` and the fol "mailboxId":"{mailboxId}", "successfullyReprocessedMailCount":18, "failedReprocessedMailCount": 3, - "failures": { - "mbx1": [{"uid": 35}, {"uid": 45}], - "mbx2": [{"uid": 38}] - } + "failures": [ + { + "mailboxId": "1", + "uids": [1, 36] + }] } ``` @@ -1019,10 +1021,11 @@ The scheduled task will have the following type `user-reindexing` and the follow "user":"u...@domain.com", "successfullyReprocessedMailCount":18, "failedReprocessedMailCount": 3, - "failures": { - "mbx1": [{"uid": 35}, {"uid": 45}], - "mbx2": [{"uid": 38}] - } + "failures": [ + { + "mailboxId": "1", + "uids": [1, 36] + }] } ``` @@ -1825,7 +1828,7 @@ If the server restarts during the migration, the migration is silently aborted. The scheduled task will have the following type `cassandra-migration` and the following `additionalInformation`: ``` -{"toVersion":3} +{"targetVersion":3} ``` ### Upgrading to the latest version @@ -2711,7 +2714,7 @@ The scheduled task will have the following type `clear-mail-repository` and the ``` { - "repositoryPath":"var/mail/error/", + "mailRepositoryPath":"var/mail/error/", "initialCount": 243, "remainingCount": 17 } @@ -2760,7 +2763,7 @@ The scheduled task will have the following type `reprocessing-all` and the follo ``` { - "repositoryPath":"var/mail/error/", + "mailRepositoryPath":"var/mail/error/", "targetQueue":"spool", "targetProcessor":"transport", "initialCount": 243, @@ -2811,7 +2814,7 @@ The scheduled task will have the following type `reprocessing-one` and the follo ``` { - "repositoryPath":"var/mail/error/", + "mailRepositoryPath":"var/mail/error/", "targetQueue":"spool", "targetProcessor":"transport", "mailKey":"name1" @@ -2918,7 +2921,7 @@ The scheduled task will have the following type `delete-mails-from-mail-queue` a ``` { - "mailQueueName":"outgoing", + "queue":"outgoing", "initialCount":10, "remainingCount": 5, "sender": "sen...@james.org", @@ -2947,7 +2950,7 @@ The scheduled task will have the following type `clear-mail-queue` and the follo ``` { - "mailQueueName":"outgoing", + "queue":"outgoing", "initialCount":10, "remainingCount": 0 } @@ -3601,8 +3604,8 @@ The scheduled task will have the following type `deleted-messages-delete` and th ``` { - "user": "u...@domain.ext", - "deleteMessageId": "3294a976-ce63-491e-bd52-1b6f465ed7a2" + "userName": "u...@domain.ext", + "messageId": "3294a976-ce63-491e-bd52-1b6f465ed7a2" } ``` --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org