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 c8202e58b2b362b6cdbe71a460dacdf6294facaf Author: Gautier DI FOLCO <gdifo...@linagora.com> AuthorDate: Wed Sep 4 11:01:15 2019 +0200 JAMES-2813 Extract MailboxMergingTaskDTO --- .../cassandra/mail/task/MailboxMergingTask.java | 82 +++---------------- .../cassandra/mail/task/MailboxMergingTaskDTO.java | 94 ++++++++++++++++++++++ .../mail/task/MailboxMergingTaskTest.java | 2 +- 3 files changed, 107 insertions(+), 71 deletions(-) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java index 87692a0..4a744c1 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java @@ -21,18 +21,12 @@ package org.apache.james.mailbox.cassandra.mail.task; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Function; -import org.apache.james.json.DTOModule; import org.apache.james.mailbox.cassandra.ids.CassandraId; -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 MailboxMergingTask implements Task { public static final TaskType MAILBOX_MERGING = TaskType.of("mailboxMerging"); @@ -105,70 +99,6 @@ public class MailboxMergingTask implements Task { } } - private static class MailboxMergingTaskDTO implements TaskDTO { - private static final CassandraId.Factory CASSANDRA_ID_FACTORY = new CassandraId.Factory(); - - public static MailboxMergingTaskDTO fromDTO(MailboxMergingTask domainObject, String typeName) { - return new MailboxMergingTaskDTO( - typeName, - domainObject.context.totalMessageCount, - domainObject.oldMailboxId.serialize(), - domainObject.newMailboxId.serialize() - ); - } - - private final String type; - - private final long totalMessageCount; - private final String oldMailboxId; - private final String newMailboxId; - - public MailboxMergingTaskDTO(@JsonProperty("type") String type, - @JsonProperty("totalMessageCount") long totalMessageCount, - @JsonProperty("oldMailboxId") String oldMailboxId, - @JsonProperty("newMailboxId") String newMailboxId) { - this.type = type; - this.totalMessageCount = totalMessageCount; - this.oldMailboxId = oldMailboxId; - this.newMailboxId = newMailboxId; - } - - private MailboxMergingTask toDTO(MailboxMergingTaskRunner taskRunner) { - return new MailboxMergingTask( - taskRunner, - totalMessageCount, - CASSANDRA_ID_FACTORY.fromString(oldMailboxId), - CASSANDRA_ID_FACTORY.fromString(newMailboxId) - ); - } - - @Override - public String getType() { - return type; - } - - public long getTotalMessageCount() { - return totalMessageCount; - } - - public String getOldMailboxId() { - return oldMailboxId; - } - - public String getNewMailboxId() { - return newMailboxId; - } - } - - public static final Function<MailboxMergingTaskRunner, TaskDTOModule<MailboxMergingTask, MailboxMergingTaskDTO>> MODULE = (taskRunner) -> - DTOModule - .forDomainObject(MailboxMergingTask.class) - .convertToDTO(MailboxMergingTaskDTO.class) - .toDomainObjectConverter(dto -> dto.toDTO(taskRunner)) - .toDTOConverter(MailboxMergingTaskDTO::fromDTO) - .typeName(MAILBOX_MERGING.asString()) - .withFactory(TaskDTOModule::new); - private final MailboxMergingTaskRunner taskRunner; private final CassandraId oldMailboxId; private final CassandraId newMailboxId; @@ -198,4 +128,16 @@ public class MailboxMergingTask implements Task { context.getMessageMovedCount(), context.getMessageFailedCount())); } + + Context getContext() { + return context; + } + + CassandraId getNewMailboxId() { + return newMailboxId; + } + + CassandraId getOldMailboxId() { + return oldMailboxId; + } } diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskDTO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskDTO.java new file mode 100644 index 0000000..26737f4 --- /dev/null +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskDTO.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.mailbox.cassandra.mail.task; + +import java.util.function.Function; + +import org.apache.james.json.DTOModule; +import org.apache.james.mailbox.cassandra.ids.CassandraId; +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 MailboxMergingTaskDTO implements TaskDTO { + private static final CassandraId.Factory CASSANDRA_ID_FACTORY = new CassandraId.Factory(); + + private static MailboxMergingTaskDTO fromDTO(MailboxMergingTask domainObject, String typeName) { + return new MailboxMergingTaskDTO( + typeName, + domainObject.getContext().getTotalMessageCount(), + domainObject.getOldMailboxId().serialize(), + domainObject.getNewMailboxId().serialize() + ); + } + + public static final Function<MailboxMergingTaskRunner, TaskDTOModule<MailboxMergingTask, MailboxMergingTaskDTO>> MODULE = (taskRunner) -> + DTOModule + .forDomainObject(MailboxMergingTask.class) + .convertToDTO(MailboxMergingTaskDTO.class) + .toDomainObjectConverter(dto -> dto.toDTO(taskRunner)) + .toDTOConverter(MailboxMergingTaskDTO::fromDTO) + .typeName(MailboxMergingTask.MAILBOX_MERGING.asString()) + .withFactory(TaskDTOModule::new); + + private final String type; + + private final long totalMessageCount; + private final String oldMailboxId; + private final String newMailboxId; + + public MailboxMergingTaskDTO(@JsonProperty("type") String type, + @JsonProperty("totalMessageCount") long totalMessageCount, + @JsonProperty("oldMailboxId") String oldMailboxId, + @JsonProperty("newMailboxId") String newMailboxId) { + this.type = type; + this.totalMessageCount = totalMessageCount; + this.oldMailboxId = oldMailboxId; + this.newMailboxId = newMailboxId; + } + + private MailboxMergingTask toDTO(MailboxMergingTaskRunner taskRunner) { + return new MailboxMergingTask( + taskRunner, + totalMessageCount, + CASSANDRA_ID_FACTORY.fromString(oldMailboxId), + CASSANDRA_ID_FACTORY.fromString(newMailboxId) + ); + } + + @Override + public String getType() { + return type; + } + + public long getTotalMessageCount() { + return totalMessageCount; + } + + public String getOldMailboxId() { + return oldMailboxId; + } + + public String getNewMailboxId() { + return newMailboxId; + } +} diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java index c0d9932..32bf837 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java @@ -36,7 +36,7 @@ class MailboxMergingTaskTest { private static final String SERIALIZED = "{\"type\":\"mailboxMerging\",\"totalMessageCount\":0,\"oldMailboxId\":\"3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c\",\"newMailboxId\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\"}"; private static final MailboxMergingTaskRunner TASK_RUNNER = mock(MailboxMergingTaskRunner.class); private static final MailboxMergingTask TASK = new MailboxMergingTask(TASK_RUNNER, 0L, CASSANDRA_ID_FACTORY.fromString("3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c"), CASSANDRA_ID_FACTORY.fromString("2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd")); - private static final JsonTaskSerializer TESTEE = new JsonTaskSerializer(MailboxMergingTask.MODULE.apply(TASK_RUNNER)); + private static final JsonTaskSerializer TESTEE = new JsonTaskSerializer(MailboxMergingTaskDTO.MODULE.apply(TASK_RUNNER)); @Test void taskShouldBeSerializable() throws JsonProcessingException { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org