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 f5be8554913d85c1a1cc15a90453ba0ef6ab405f
Author: Gautier DI FOLCO <[email protected]>
AuthorDate: Tue Sep 3 16:34:13 2019 +0200

    JAMES-2813 Make BlobStoreVaultGarbageCollectionTask.AdditionalInformation 
serializable
---
 ...bageCollectionTaskAdditionalInformationDTO.java | 76 ++++++++++++++++++++++
 ...aultGarbageCollectionTaskSerializationTest.java | 20 +++++-
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git 
a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.java
 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.java
new file mode 100644
index 0000000..cc68f1a
--- /dev/null
+++ 
b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.java
@@ -0,0 +1,76 @@
+/**
+ * *************************************************************
+ * 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.AdditionalInformationDTO;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.steveash.guavate.Guavate;
+
+public class BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO 
implements AdditionalInformationDTO {
+    static BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO 
fromDomainObject(BlobStoreVaultGarbageCollectionTask.AdditionalInformation 
additionalInformation, String type) {
+        return new BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO(
+            additionalInformation.getBeginningOfRetentionPeriod().toString(),
+            additionalInformation.getDeletedBuckets()
+        );
+    }
+
+    public static final 
AdditionalInformationDTOModule<BlobStoreVaultGarbageCollectionTask.AdditionalInformation,
 BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO> MODULE =
+        DTOModule
+            
.forDomainObject(BlobStoreVaultGarbageCollectionTask.AdditionalInformation.class)
+            
.convertToDTO(BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.class)
+            
.toDomainObjectConverter(BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO::toDomainObject)
+            
.toDTOConverter(BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO::fromDomainObject)
+            .typeName(BlobStoreVaultGarbageCollectionTask.TYPE.asString())
+            .withFactory(AdditionalInformationDTOModule::new);
+
+    private final String beginningOfRetentionPeriod;
+    private final Collection<String> deletedBuckets;
+
+    
BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO(@JsonProperty("beginningOfRetentionPeriod")
 String beginningOfRetentionPeriod,
+                                                                
@JsonProperty("deletedBuckets") Collection<String> deletedBuckets) {
+        this.beginningOfRetentionPeriod = beginningOfRetentionPeriod;
+        this.deletedBuckets = deletedBuckets;
+    }
+
+    BlobStoreVaultGarbageCollectionTask.AdditionalInformation toDomainObject() 
{
+        return new BlobStoreVaultGarbageCollectionTask.AdditionalInformation(
+            ZonedDateTime.parse(beginningOfRetentionPeriod),
+            deletedBuckets
+                .stream()
+                .map(BucketName::of)
+                .collect(Guavate.toImmutableList()));
+    }
+
+    public String getBeginningOfRetentionPeriod() {
+        return beginningOfRetentionPeriod;
+    }
+
+    public Collection<String> getDeletedBuckets() {
+        return deletedBuckets;
+    }
+}
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
index 82767c2..97a93af 100644
--- 
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
@@ -27,10 +27,12 @@ import java.io.IOException;
 import java.time.ZonedDateTime;
 
 import org.apache.james.blob.api.BucketName;
+import 
org.apache.james.server.task.json.JsonTaskAdditionalInformationsSerializer;
 import org.apache.james.server.task.json.JsonTaskSerializer;
 import org.apache.james.task.Task;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.collect.ImmutableList;
 import org.junit.jupiter.api.Test;
 import reactor.core.publisher.Flux;
 
@@ -38,10 +40,15 @@ 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 ImmutableList<BucketName> BUCKET_IDS = 
ImmutableList.of(BucketName.of("1"), BucketName.of("2"), BucketName.of("3"));
+    private static final Flux<BucketName> RETENTION_OPERATION = 
Flux.fromIterable(BUCKET_IDS);
+    private static final 
BlobStoreVaultGarbageCollectionTask.AdditionalInformation DETAILS = new 
BlobStoreVaultGarbageCollectionTask.AdditionalInformation(BEGINNING_OF_RETENTION_PERIOD,
 BUCKET_IDS);
     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\"}";
+    private static final String SERIALIZED_ADDITIONAL_INFORMATION_TASK = 
"{\"beginningOfRetentionPeriod\":\"2019-09-03T15:26:13.356+02:00[Europe/Paris]\",\"deletedBuckets\":[\"1\",
 \"2\", \"3\"]}";
+
+    private static final JsonTaskAdditionalInformationsSerializer 
JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER = new 
JsonTaskAdditionalInformationsSerializer(BlobStoreVaultGarbageCollectionTaskAdditionalInformationDTO.MODULE);
 
     @Test
     void taskShouldBeSerializable() throws JsonProcessingException {
@@ -66,4 +73,15 @@ class BlobStoreVaultGarbageCollectionTaskSerializationTest {
                 .collectList()
                 .block());
     }
+
+    @Test
+    void additionalInformationShouldBeSerializable() throws 
JsonProcessingException {
+        
assertThatJson(JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER.serialize(DETAILS)).isEqualTo(SERIALIZED_ADDITIONAL_INFORMATION_TASK);
+    }
+
+    @Test
+    void additonalInformationShouldBeDeserializable() throws IOException {
+        
assertThat(JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER.deserialize("deletedMessages/blobStoreBasedGarbageCollection",
 SERIALIZED_ADDITIONAL_INFORMATION_TASK))
+            .isEqualToComparingFieldByField(DETAILS);
+    }
 }
\ No newline at end of file


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

Reply via email to