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 76c2fd98203304efb08d952e4e62b321e5ea3f44
Author: Rémi Kowalski <rkowal...@linagora.com>
AuthorDate: Fri Sep 20 17:49:57 2019 +0200

    JAMES-2813 serialize additional informations for UserReindexingTask
---
 ...UserReindexingTaskAdditionalInformationDTO.java | 77 ++++++++++++++++++++++
 .../UserReindexingTaskSerializationTest.java       | 46 +++++++++++++
 2 files changed, 123 insertions(+)

diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTaskAdditionalInformationDTO.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTaskAdditionalInformationDTO.java
new file mode 100644
index 0000000..3b82156
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/UserReindexingTaskAdditionalInformationDTO.java
@@ -0,0 +1,77 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer;
+
+import java.util.List;
+import java.util.function.Function;
+
+import org.apache.james.core.User;
+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 com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class UserReindexingTaskAdditionalInformationDTO implements 
AdditionalInformationDTO {
+
+    public static final Function<MailboxId.Factory, 
AdditionalInformationDTOModule<UserReindexingTask.AdditionalInformation, 
UserReindexingTaskAdditionalInformationDTO>> SERIALIZATION_MODULE =
+        factory ->
+            
DTOModule.forDomainObject(UserReindexingTask.AdditionalInformation.class)
+                .convertToDTO(UserReindexingTaskAdditionalInformationDTO.class)
+                .toDomainObjectConverter(dto -> new 
UserReindexingTask.AdditionalInformation(User.fromUsername(dto.getUser()),
+                    dto.getSuccessfullyReprocessedMailCount(),
+                    dto.getFailedReprocessedMailCount(),
+                    
ReprocessingContextInformationDTO.deserializeFailures(factory, 
dto.getFailures())))
+                .toDTOConverter((details, type) -> new 
UserReindexingTaskAdditionalInformationDTO(details.getUser(), 
details.getSuccessfullyReprocessedMailCount(), 
details.getFailedReprocessedMailCount(),
+                    
ReprocessingContextInformationDTO.serializeFailures(details.failures())))
+                .typeName(UserReindexingTask.USER_RE_INDEXING.asString())
+                .withFactory(AdditionalInformationDTOModule::new);
+
+    private final ReprocessingContextInformationDTO 
reprocessingContextInformationDTO;
+    private final String user;
+
+    @JsonCreator
+    private UserReindexingTaskAdditionalInformationDTO(@JsonProperty("user") 
String user,
+                                                       
@JsonProperty("successfullyReprocessedMailCount") int 
successfullyReprocessedMailCount,
+                                                       
@JsonProperty("failedReprocessedMailCount") int failedReprocessedMailCount,
+                                                       
@JsonProperty("failures") 
List<ReprocessingContextInformationDTO.ReindexingFailureDTO> failures) {
+        this.user = user;
+        this.reprocessingContextInformationDTO = new 
ReprocessingContextInformationDTO(
+            successfullyReprocessedMailCount,
+            failedReprocessedMailCount, failures);
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public int getSuccessfullyReprocessedMailCount() {
+        return 
reprocessingContextInformationDTO.getSuccessfullyReprocessedMailCount();
+    }
+
+    public int getFailedReprocessedMailCount() {
+        return 
reprocessingContextInformationDTO.getFailedReprocessedMailCount();
+    }
+
+    public List<ReprocessingContextInformationDTO.ReindexingFailureDTO> 
getFailures() {
+        return reprocessingContextInformationDTO.getFailures();
+    }
+}
diff --git 
a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/UserReindexingTaskSerializationTest.java
 
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/UserReindexingTaskSerializationTest.java
index c586e65..737f17a 100644
--- 
a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/UserReindexingTaskSerializationTest.java
+++ 
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/UserReindexingTaskSerializationTest.java
@@ -23,25 +23,57 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures;
+import org.apache.james.mailbox.model.TestId;
+import 
org.apache.james.server.task.json.JsonTaskAdditionalInformationsSerializer;
 import org.apache.james.server.task.json.JsonTaskSerializer;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.collect.ImmutableList;
 
 class UserReindexingTaskSerializationTest {
 
     private ReIndexerPerformer reIndexerPerformer;
     private JsonTaskSerializer taskSerializer;
+    private JsonTaskAdditionalInformationsSerializer 
jsonAdditionalInformationSerializer;
+
+    private final User user = User.fromUsername("f...@apache.org");
+    private final int successfullyReprocessedMailCount = 42;
+    private final int failedReprocessedMailCount = 2;
+    private ReIndexingExecutionFailures reIndexingExecutionFailures;
     private final String serializedUserReindexingTask = "{\"type\": 
\"userReIndexing\", \"username\": \"f...@apache.org\"}";
 
+    private final String SERIALIZED_ADDITIONAL_INFORMATION = "{ \"user\": 
\"f...@apache.org\", 
\"successfullyReprocessedMailCount\":42,\"failedReprocessedMailCount\":2,\"failures\":[{\"mailboxId\":\"1\",\"uids\":[10]},{\"mailboxId\":\"2\",\"uids\":[20]}]}";
+
+    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);
+
     @BeforeEach
     void setUp() {
         reIndexerPerformer = mock(ReIndexerPerformer.class);
         UserReindexingTask.Factory factory = new 
UserReindexingTask.Factory(reIndexerPerformer);
         taskSerializer = new 
JsonTaskSerializer(UserReindexingTaskDTO.MODULE.apply(factory));
+        jsonAdditionalInformationSerializer = new 
JsonTaskAdditionalInformationsSerializer(
+            UserReindexingTaskAdditionalInformationDTO
+                .SERIALIZATION_MODULE
+                .apply(new TestId.Factory()));
+
+        reIndexingExecutionFailures = new 
ReIndexingExecutionFailures(ImmutableList.of(
+            new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId, 
messageUid),
+            new ReIndexingExecutionFailures.ReIndexingFailure(mailboxId2, 
messageUid2)));
     }
 
     @Test
@@ -61,5 +93,19 @@ class UserReindexingTaskSerializationTest {
         assertThat(taskSerializer.deserialize(serializedUserReindexingTask))
             .isEqualToComparingOnlyGivenFields(task, "reIndexerPerformer");
     }
+
+
+    @Test
+    void additionalInformationShouldBeSerializable() throws 
JsonProcessingException {
+        UserReindexingTask.AdditionalInformation details = new 
UserReindexingTask.AdditionalInformation(user, 
successfullyReprocessedMailCount, failedReprocessedMailCount, 
reIndexingExecutionFailures);
+        
assertThatJson(jsonAdditionalInformationSerializer.serialize(details)).isEqualTo(SERIALIZED_ADDITIONAL_INFORMATION);
+    }
+
+    @Test
+    void additionalInformationShouldBeDeserializable() throws IOException {
+        UserReindexingTask.AdditionalInformation details = new 
UserReindexingTask.AdditionalInformation(user, 
successfullyReprocessedMailCount, failedReprocessedMailCount, 
reIndexingExecutionFailures);
+        
assertThat(jsonAdditionalInformationSerializer.deserialize("userReIndexing", 
SERIALIZED_ADDITIONAL_INFORMATION))
+            .isEqualToComparingFieldByField(details);
+    }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to