You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/09/11 10:01:15 UTC
[james-project] 25/38: JAMES-2813 extract
ReprocessingAllMailsTaskDTO
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 7a584bf1386115f8b48a4e0027716ccc7ee942fe
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Wed Sep 4 13:44:53 2019 +0200
JAMES-2813 extract ReprocessingAllMailsTaskDTO
---
.../webadmin/service/ReprocessingAllMailsTask.java | 101 +++----------------
.../service/ReprocessingAllMailsTaskDTO.java | 108 +++++++++++++++++++++
.../service/ReprocessingAllMailsTaskTest.java | 12 +--
3 files changed, 130 insertions(+), 91 deletions(-)
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTask.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTask.java
index 02fd99a..f524027 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTask.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTask.java
@@ -21,22 +21,16 @@ package org.apache.james.webadmin.service;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.function.Function;
import javax.mail.MessagingException;
-import org.apache.james.json.DTOModule;
import org.apache.james.mailrepository.api.MailKey;
import org.apache.james.mailrepository.api.MailRepositoryPath;
import org.apache.james.mailrepository.api.MailRepositoryStore;
-import org.apache.james.server.task.json.dto.TaskDTO;
-import org.apache.james.server.task.json.dto.TaskDTOModule;
import org.apache.james.task.Task;
import org.apache.james.task.TaskExecutionDetails;
import org.apache.james.task.TaskType;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
public class ReprocessingAllMailsTask implements Task {
public static final TaskType TYPE = TaskType.of("reprocessingAllTask");
@@ -92,85 +86,6 @@ public class ReprocessingAllMailsTask implements Task {
}
}
- private static class ReprocessingAllMailsTaskDTO implements TaskDTO {
-
- public static ReprocessingAllMailsTaskDTO toDTO(ReprocessingAllMailsTask domainObject, String typeName) {
- try {
- return new ReprocessingAllMailsTaskDTO(
- typeName,
- domainObject.repositorySize,
- domainObject.repositoryPath.urlEncoded(),
- domainObject.targetQueue,
- domainObject.targetProcessor
- );
- } catch (Exception e) {
- throw new UrlEncodingFailureSerializationException(domainObject.repositoryPath);
- }
- }
-
- private final String type;
- private final long repositorySize;
- private final String repositoryPath;
- private final String targetQueue;
- private final Optional<String> targetProcessor;
-
- public ReprocessingAllMailsTaskDTO(@JsonProperty("type") String type,
- @JsonProperty("repositorySize") long repositorySize,
- @JsonProperty("repositoryPath") String repositoryPath,
- @JsonProperty("targetQueue") String targetQueue,
- @JsonProperty("targetProcessor") Optional<String> targetProcessor) {
- this.type = type;
- this.repositorySize = repositorySize;
- this.repositoryPath = repositoryPath;
- this.targetQueue = targetQueue;
- this.targetProcessor = targetProcessor;
- }
-
- public ReprocessingAllMailsTask fromDTO(ReprocessingService reprocessingService) {
- try {
- return new ReprocessingAllMailsTask(
- reprocessingService,
- repositorySize,
- MailRepositoryPath.fromEncoded(repositoryPath),
- targetQueue,
- targetProcessor
- );
- } catch (Exception e) {
- throw new InvalidMailRepositoryPathDeserializationException(repositoryPath);
- }
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- public long getRepositorySize() {
- return repositorySize;
- }
-
- public String getRepositoryPath() {
- return repositoryPath;
- }
-
- public String getTargetQueue() {
- return targetQueue;
- }
-
- public Optional<String> getTargetProcessor() {
- return targetProcessor;
- }
- }
-
- public static final Function<ReprocessingService, TaskDTOModule<ReprocessingAllMailsTask, ReprocessingAllMailsTaskDTO>> MODULE = (reprocessingService) ->
- DTOModule
- .forDomainObject(ReprocessingAllMailsTask.class)
- .convertToDTO(ReprocessingAllMailsTaskDTO.class)
- .toDomainObjectConverter(dto -> dto.fromDTO(reprocessingService))
- .toDTOConverter(ReprocessingAllMailsTaskDTO::toDTO)
- .typeName(TYPE.asString())
- .withFactory(TaskDTOModule::new);
-
private final ReprocessingService reprocessingService;
private final MailRepositoryPath repositoryPath;
private final String targetQueue;
@@ -203,6 +118,22 @@ public class ReprocessingAllMailsTask implements Task {
}
}
+ MailRepositoryPath getRepositoryPath() {
+ return repositoryPath;
+ }
+
+ long getRepositorySize() {
+ return repositorySize;
+ }
+
+ Optional<String> getTargetProcessor() {
+ return targetProcessor;
+ }
+
+ String getTargetQueue() {
+ return targetQueue;
+ }
+
@Override
public TaskType type() {
return TYPE;
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskDTO.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskDTO.java
new file mode 100644
index 0000000..a27afc3
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskDTO.java
@@ -0,0 +1,108 @@
+/****************************************************************
+ * 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.util.Optional;
+import java.util.function.Function;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailrepository.api.MailRepositoryPath;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+class ReprocessingAllMailsTaskDTO implements TaskDTO {
+
+ public static final Function<ReprocessingService, TaskDTOModule<ReprocessingAllMailsTask, ReprocessingAllMailsTaskDTO>> MODULE = (reprocessingService) ->
+ DTOModule
+ .forDomainObject(ReprocessingAllMailsTask.class)
+ .convertToDTO(ReprocessingAllMailsTaskDTO.class)
+ .toDomainObjectConverter(dto -> dto.fromDTO(reprocessingService))
+ .toDTOConverter(ReprocessingAllMailsTaskDTO::toDTO)
+ .typeName(ReprocessingAllMailsTask.TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+
+ private static ReprocessingAllMailsTaskDTO toDTO(ReprocessingAllMailsTask domainObject, String typeName) {
+ try {
+ return new ReprocessingAllMailsTaskDTO(
+ typeName,
+ domainObject.getRepositorySize(),
+ domainObject.getRepositoryPath().urlEncoded(),
+ domainObject.getTargetQueue(),
+ domainObject.getTargetProcessor()
+ );
+ } catch (Exception e) {
+ throw new ReprocessingAllMailsTask.UrlEncodingFailureSerializationException(domainObject.getRepositoryPath());
+ }
+ }
+
+ private final String type;
+ private final long repositorySize;
+ private final String repositoryPath;
+ private final String targetQueue;
+ private final Optional<String> targetProcessor;
+
+ public ReprocessingAllMailsTaskDTO(@JsonProperty("type") String type,
+ @JsonProperty("repositorySize") long repositorySize,
+ @JsonProperty("repositoryPath") String repositoryPath,
+ @JsonProperty("targetQueue") String targetQueue,
+ @JsonProperty("targetProcessor") Optional<String> targetProcessor) {
+ this.type = type;
+ this.repositorySize = repositorySize;
+ this.repositoryPath = repositoryPath;
+ this.targetQueue = targetQueue;
+ this.targetProcessor = targetProcessor;
+ }
+
+ private ReprocessingAllMailsTask fromDTO(ReprocessingService reprocessingService) {
+ try {
+ return new ReprocessingAllMailsTask(
+ reprocessingService,
+ repositorySize,
+ MailRepositoryPath.fromEncoded(repositoryPath),
+ targetQueue,
+ targetProcessor
+ );
+ } catch (Exception e) {
+ throw new ReprocessingAllMailsTask.InvalidMailRepositoryPathDeserializationException(repositoryPath);
+ }
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public long getRepositorySize() {
+ return repositorySize;
+ }
+
+ public String getRepositoryPath() {
+ return repositoryPath;
+ }
+
+ public String getTargetQueue() {
+ return targetQueue;
+ }
+
+ public Optional<String> getTargetProcessor() {
+ return targetProcessor;
+ }
+}
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskTest.java
index 1c401d4..4f41a74 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ReprocessingAllMailsTaskTest.java
@@ -23,20 +23,20 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
-import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.james.mailrepository.api.MailRepositoryPath;
import org.apache.james.server.task.json.JsonTaskSerializer;
-
-import net.javacrumbs.jsonunit.assertj.JsonAssertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import net.javacrumbs.jsonunit.assertj.JsonAssertions;
+
class ReprocessingAllMailsTaskTest {
private static final ReprocessingService REPROCESSING_SERVICE = mock(ReprocessingService.class);
@@ -47,7 +47,7 @@ class ReprocessingAllMailsTaskTest {
String targetQueue,
Optional<String> targetProcessor,
String serialized) throws JsonProcessingException {
- JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTask.MODULE.apply(REPROCESSING_SERVICE));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTaskDTO.MODULE.apply(REPROCESSING_SERVICE));
ReprocessingAllMailsTask task = new ReprocessingAllMailsTask(REPROCESSING_SERVICE, repositorySize, repositoryPath, targetQueue, targetProcessor);
JsonAssertions.assertThatJson(testee.serialize(task))
.isEqualTo(serialized);
@@ -64,7 +64,7 @@ class ReprocessingAllMailsTaskTest {
String targetQueue,
Optional<String> targetProcessor,
String serialized) throws IOException {
- JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTask.MODULE.apply(REPROCESSING_SERVICE));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTaskDTO.MODULE.apply(REPROCESSING_SERVICE));
ReprocessingAllMailsTask task = new ReprocessingAllMailsTask(REPROCESSING_SERVICE, repositorySize, repositoryPath, targetQueue, targetProcessor);
assertThat(testee.deserialize(serialized))
@@ -85,7 +85,7 @@ class ReprocessingAllMailsTaskTest {
@ParameterizedTest
@ValueSource(strings = {"{\"type\":\"reprocessingAllTask\",\"repositorySize\":5,\"repositoryPath\":\"%\",\"targetQueue\":\"queue\",\"targetProcessor\":\"targetProcessor\"}", "{\"type\":\"reprocessingAllTask\",\"repositorySize\":5,\"repositoryPath\":\"%\",\"targetQueue\":\"queue\"}"})
void taskShouldThrowOnDeserializationUrlDecodingError(String serialized) {
- JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTask.MODULE.apply(REPROCESSING_SERVICE));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ReprocessingAllMailsTaskDTO.MODULE.apply(REPROCESSING_SERVICE));
assertThatThrownBy(() -> testee.deserialize(serialized))
.isInstanceOf(ReprocessingAllMailsTask.InvalidMailRepositoryPathDeserializationException.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org