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 8768d7be991f8c3b92b4f705f98b4c32421500dc
Author: Gautier DI FOLCO <[email protected]>
AuthorDate: Tue Sep 3 15:46:22 2019 +0200

    JAMES-2813 Make BlobStoreVaultGarbageCollectionTask serializable
---
 .../blob/BlobStoreVaultGarbageCollectionTask.java  | 10 ++-
 .../BlobStoreVaultGarbageCollectionTaskDTO.java    | 88 ++++++++++++++++++++++
 ...aultGarbageCollectionTaskSerializationTest.java | 69 +++++++++++++++++
 3 files changed, 166 insertions(+), 1 deletion(-)

diff --git 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTask.java
 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTask.java
index 0d3c014..cfddb37 100644
--- 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTask.java
+++ 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTask.java
@@ -58,7 +58,7 @@ public class BlobStoreVaultGarbageCollectionTask implements 
Task {
         }
     }
 
-    private static final TaskType TYPE = 
TaskType.of("deletedMessages/blobStoreBasedGarbageCollection");
+    static final TaskType TYPE = 
TaskType.of("deletedMessages/blobStoreBasedGarbageCollection");
 
     private final Flux<BucketName> retentionOperation;
     private final ZonedDateTime beginningOfRetentionPeriod;
@@ -90,4 +90,12 @@ public class BlobStoreVaultGarbageCollectionTask implements 
Task {
     public Optional<TaskExecutionDetails.AdditionalInformation> details() {
         return Optional.of(new 
AdditionalInformation(beginningOfRetentionPeriod, deletedBuckets));
     }
+
+    ZonedDateTime getBeginningOfRetentionPeriod() {
+        return beginningOfRetentionPeriod;
+    }
+
+    Flux<BucketName> getRetentionOperation() {
+        return retentionOperation;
+    }
 }
diff --git 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskDTO.java
 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskDTO.java
new file mode 100644
index 0000000..bbdb794
--- /dev/null
+++ 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskDTO.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.vault.blob;
+
+import java.time.ZonedDateTime;
+import java.util.Collection;
+
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.json.DTOModule;
+import org.apache.james.server.task.json.dto.TaskDTO;
+import org.apache.james.server.task.json.dto.TaskDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.steveash.guavate.Guavate;
+import reactor.core.publisher.Flux;
+
+public class BlobStoreVaultGarbageCollectionTaskDTO implements TaskDTO {
+    static BlobStoreVaultGarbageCollectionTaskDTO 
fromDomainObject(BlobStoreVaultGarbageCollectionTask task, String type) {
+        return new BlobStoreVaultGarbageCollectionTaskDTO(
+            type,
+            task.getBeginningOfRetentionPeriod().toString(),
+            task.getRetentionOperation()
+                .map(BucketName::asString)
+                .collect(Guavate.toImmutableList())
+                .block()
+        );
+    }
+
+    public static final TaskDTOModule<BlobStoreVaultGarbageCollectionTask, 
BlobStoreVaultGarbageCollectionTaskDTO> MODULE =
+        DTOModule
+            .forDomainObject(BlobStoreVaultGarbageCollectionTask.class)
+            .convertToDTO(BlobStoreVaultGarbageCollectionTaskDTO.class)
+            
.toDomainObjectConverter(BlobStoreVaultGarbageCollectionTaskDTO::toDomainObject)
+            
.toDTOConverter(BlobStoreVaultGarbageCollectionTaskDTO::fromDomainObject)
+            .typeName(BlobStoreVaultGarbageCollectionTask.TYPE.asString())
+            .withFactory(TaskDTOModule::new);
+
+
+    private final String type;
+    private final String beginningOfRetentionPeriod;
+    private final Collection<String> retentionOperation;
+
+    BlobStoreVaultGarbageCollectionTaskDTO(@JsonProperty("type") String type,
+                                           
@JsonProperty("beginningOfRetentionPeriod") String beginningOfRetentionPeriod,
+                                           @JsonProperty("retentionOperation") 
Collection<String> retentionOperation) {
+        this.type = type;
+        this.beginningOfRetentionPeriod = beginningOfRetentionPeriod;
+        this.retentionOperation = retentionOperation;
+    }
+
+    BlobStoreVaultGarbageCollectionTask toDomainObject() {
+        return new BlobStoreVaultGarbageCollectionTask(
+            ZonedDateTime.parse(beginningOfRetentionPeriod),
+            Flux.fromIterable(retentionOperation)
+                .map(BucketName::of));
+    }
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+    public String getBeginningOfRetentionPeriod() {
+        return beginningOfRetentionPeriod;
+    }
+
+    public Collection<String> getRetentionOperation() {
+        return retentionOperation;
+    }
+}
diff --git 
a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskSerializationTest.java
 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskSerializationTest.java
new file mode 100644
index 0000000..82767c2
--- /dev/null
+++ 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskSerializationTest.java
@@ -0,0 +1,69 @@
+/**
+ * *************************************************************
+ * 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.vault.blob;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.time.ZonedDateTime;
+
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.server.task.json.JsonTaskSerializer;
+import org.apache.james.task.Task;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.junit.jupiter.api.Test;
+import reactor.core.publisher.Flux;
+
+class BlobStoreVaultGarbageCollectionTaskSerializationTest {
+
+    private static final JsonTaskSerializer TASK_SERIALIZER = new 
JsonTaskSerializer(BlobStoreVaultGarbageCollectionTaskDTO.MODULE);
+    private static final ZonedDateTime BEGINNING_OF_RETENTION_PERIOD = 
ZonedDateTime.parse("2019-09-03T15:26:13.356+02:00[Europe/Paris]");
+    private static final Flux<BucketName> RETENTION_OPERATION = Flux.just("1", 
"2", "3").map(BucketName::of);
+    private static final BlobStoreVaultGarbageCollectionTask TASK = new 
BlobStoreVaultGarbageCollectionTask(BEGINNING_OF_RETENTION_PERIOD, 
RETENTION_OPERATION);
+
+    private static final String SERIALIZED_TASK = 
"{\"beginningOfRetentionPeriod\":\"2019-09-03T15:26:13.356+02:00[Europe/Paris]\",\"retentionOperation\":[\"1\",
 \"2\", \"3\"],\"type\":\"deletedMessages/blobStoreBasedGarbageCollection\"}";
+
+    @Test
+    void taskShouldBeSerializable() throws JsonProcessingException {
+        assertThatJson(TASK_SERIALIZER.serialize(TASK))
+            .isEqualTo(SERIALIZED_TASK);
+    }
+
+    @Test
+    void taskShouldBeDeserializable() throws IOException {
+        Task deserialized = TASK_SERIALIZER.deserialize(SERIALIZED_TASK);
+
+        
assertThat(deserialized).isInstanceOf(BlobStoreVaultGarbageCollectionTask.class);
+        BlobStoreVaultGarbageCollectionTask 
blobStoreVaultGarbageCollectionTask = (BlobStoreVaultGarbageCollectionTask) 
deserialized;
+        
assertThat(blobStoreVaultGarbageCollectionTask.getBeginningOfRetentionPeriod())
+            .isEqualTo(TASK.getBeginningOfRetentionPeriod());
+        assertThat(blobStoreVaultGarbageCollectionTask
+            .getRetentionOperation()
+            .collectList()
+            .block())
+            .isEqualTo(TASK
+                .getRetentionOperation()
+                .collectList()
+                .block());
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to