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:09 UTC
[james-project] 19/38: JAMES-2813 extract ClearMailRepositoryTaskDTO
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 54abe1ec644004fdcdd86a7c30f9431a2ab32e74
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Tue Sep 3 17:17:54 2019 +0200
JAMES-2813 extract ClearMailRepositoryTaskDTO
---
.../webadmin/service/ClearMailRepositoryTask.java | 53 ++-------------
.../service/ClearMailRepositoryTaskDTO.java | 75 ++++++++++++++++++++++
.../service/ClearMailRepositoryTaskTest.java | 14 ++--
3 files changed, 88 insertions(+), 54 deletions(-)
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTask.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTask.java
index bb5d530..84b1985 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTask.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTask.java
@@ -29,13 +29,11 @@ import javax.mail.MessagingException;
import org.apache.james.json.DTOModule;
import org.apache.james.mailrepository.api.MailRepository;
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 org.apache.james.task.Task;
import org.apache.james.task.TaskExecutionDetails;
import org.apache.james.task.TaskType;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.fge.lambdas.Throwing;
public class ClearMailRepositoryTask implements Task {
@@ -80,56 +78,13 @@ public class ClearMailRepositoryTask implements Task {
}
}
- private static class ClearMailRepositoryTaskDTO implements TaskDTO {
-
- public static ClearMailRepositoryTaskDTO toDTO(ClearMailRepositoryTask domainObject, String typeName) {
- try {
- return new ClearMailRepositoryTaskDTO(typeName, domainObject.additionalInformation.repositoryPath.urlEncoded());
- } catch (Exception e) {
- throw new UrlEncodingFailureSerializationException(domainObject.additionalInformation.repositoryPath);
- }
- }
-
- private final String type;
- private final String mailRepositoryPath;
-
- public ClearMailRepositoryTaskDTO(@JsonProperty("type") String type, @JsonProperty("mailRepositoryPath") String mailRepositoryPath) {
- this.type = type;
- this.mailRepositoryPath = mailRepositoryPath;
- }
-
- public ClearMailRepositoryTask fromDTO(List<MailRepository> mailRepositories) {
- try {
- return new ClearMailRepositoryTask(mailRepositories, MailRepositoryPath.fromEncoded(mailRepositoryPath));
- } catch (Exception e) {
- throw new InvalidMailRepositoryPathDeserializationException(mailRepositoryPath);
- }
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- public String getMailRepositoryPath() {
- return mailRepositoryPath;
- }
- }
-
- public static final Function<List<MailRepository>, TaskDTOModule<ClearMailRepositoryTask, ClearMailRepositoryTaskDTO>> MODULE = (mailRepositories) ->
- DTOModule
- .forDomainObject(ClearMailRepositoryTask.class)
- .convertToDTO(ClearMailRepositoryTaskDTO.class)
- .toDomainObjectConverter(dto -> dto.fromDTO(mailRepositories))
- .toDTOConverter(ClearMailRepositoryTaskDTO::toDTO)
- .typeName(TYPE.asString())
- .withFactory(TaskDTOModule::new);
-
private final List<MailRepository> mailRepositories;
+ private final MailRepositoryPath mailRepositoryPath;
private final AdditionalInformation additionalInformation;
public ClearMailRepositoryTask(List<MailRepository> mailRepositories, MailRepositoryPath path) {
this.mailRepositories = mailRepositories;
+ this.mailRepositoryPath = path;
this.additionalInformation = new AdditionalInformation(path, this::getRemainingSize);
}
@@ -153,6 +108,10 @@ public class ClearMailRepositoryTask implements Task {
return TYPE;
}
+ MailRepositoryPath getMailRepositoryPath() {
+ return mailRepositoryPath;
+ }
+
@Override
public Optional<TaskExecutionDetails.AdditionalInformation> details() {
return Optional.of(additionalInformation);
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskDTO.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskDTO.java
new file mode 100644
index 0000000..719c73f
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskDTO.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.List;
+import java.util.function.Function;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailrepository.api.MailRepository;
+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;
+
+public class ClearMailRepositoryTaskDTO implements TaskDTO {
+
+ public static final Function<List<MailRepository>, TaskDTOModule<ClearMailRepositoryTask, ClearMailRepositoryTaskDTO>> MODULE = (mailRepositories) ->
+ DTOModule
+ .forDomainObject(ClearMailRepositoryTask.class)
+ .convertToDTO(ClearMailRepositoryTaskDTO.class)
+ .toDomainObjectConverter(dto -> dto.fromDTO(mailRepositories))
+ .toDTOConverter(ClearMailRepositoryTaskDTO::toDTO)
+ .typeName(ClearMailRepositoryTask.TYPE.asString())
+ .withFactory(TaskDTOModule::new);
+
+ public static ClearMailRepositoryTaskDTO toDTO(ClearMailRepositoryTask domainObject, String typeName) {
+ try {
+ return new ClearMailRepositoryTaskDTO(typeName, domainObject.getMailRepositoryPath().urlEncoded());
+ } catch (Exception e) {
+ throw new ClearMailRepositoryTask.UrlEncodingFailureSerializationException(domainObject.getMailRepositoryPath());
+ }
+ }
+
+ private final String type;
+ private final String mailRepositoryPath;
+
+ public ClearMailRepositoryTaskDTO(@JsonProperty("type") String type, @JsonProperty("mailRepositoryPath") String mailRepositoryPath) {
+ this.type = type;
+ this.mailRepositoryPath = mailRepositoryPath;
+ }
+
+ public ClearMailRepositoryTask fromDTO(List<MailRepository> mailRepositories) {
+ try {
+ return new ClearMailRepositoryTask(mailRepositories, MailRepositoryPath.fromEncoded(mailRepositoryPath));
+ } catch (Exception e) {
+ throw new ClearMailRepositoryTask.InvalidMailRepositoryPathDeserializationException(mailRepositoryPath);
+ }
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public String getMailRepositoryPath() {
+ return mailRepositoryPath;
+ }
+}
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskTest.java
index fe02c84..0a127b1 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/ClearMailRepositoryTaskTest.java
@@ -22,16 +22,16 @@ package org.apache.james.webadmin.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.IOException;
+
import org.apache.james.mailrepository.api.MailRepository;
import org.apache.james.mailrepository.api.MailRepositoryPath;
import org.apache.james.server.task.json.JsonTaskSerializer;
+import org.junit.jupiter.api.Test;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.ImmutableList;
import net.javacrumbs.jsonunit.assertj.JsonAssertions;
-import org.junit.jupiter.api.Test;
-
-import java.io.IOException;
class ClearMailRepositoryTaskTest {
private static final String SERIALIZED = "{\"type\":\"clearMailRepository\",\"mailRepositoryPath\":\"a\"}";
@@ -40,14 +40,14 @@ class ClearMailRepositoryTaskTest {
@Test
void taskShouldBeSerializable() throws JsonProcessingException {
- JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTask.MODULE.apply(MAIL_REPOSITORIES));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTaskDTO.MODULE.apply(MAIL_REPOSITORIES));
JsonAssertions.assertThatJson(testee.serialize(TASK))
.isEqualTo(SERIALIZED);
}
@Test
void taskShouldBeDeserializable() throws IOException {
- JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTask.MODULE.apply(MAIL_REPOSITORIES));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTaskDTO.MODULE.apply(MAIL_REPOSITORIES));
assertThat(testee.deserialize(SERIALIZED))
.isEqualToComparingFieldByFieldRecursively(TASK);
@@ -55,7 +55,7 @@ class ClearMailRepositoryTaskTest {
@Test
void taskShouldThrowOnDeserializationUrlDecodingError() {
- JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTask.MODULE.apply(MAIL_REPOSITORIES));
+ JsonTaskSerializer testee = new JsonTaskSerializer(ClearMailRepositoryTaskDTO.MODULE.apply(MAIL_REPOSITORIES));
assertThatThrownBy(() -> testee.deserialize("{\"type\":\"clearMailRepository\",\"mailRepositoryPath\":\"%\"}"))
.isInstanceOf(ClearMailRepositoryTask.InvalidMailRepositoryPathDeserializationException.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org