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 57d06560d7c2ec907819e19898df8fb5c687e08f
Author: RĂ©mi Kowalski <rkowal...@linagora.com>
AuthorDate: Fri Aug 30 17:11:22 2019 +0200

    JAMES-2813 add JsonTaskAdditionalInformation serialization
---
 .../JsonTaskAdditionalInformationsSerializer.java  | 77 ++++++++++++++++++++++
 .../task/json/dto/AdditionalInformationDTO.java    | 24 +++++++
 .../json/dto/AdditionalInformationDTOModule.java   | 34 ++++++++++
 3 files changed, 135 insertions(+)

diff --git 
a/server/task-json/src/main/java/org/apache/james/server/task/json/JsonTaskAdditionalInformationsSerializer.java
 
b/server/task-json/src/main/java/org/apache/james/server/task/json/JsonTaskAdditionalInformationsSerializer.java
new file mode 100644
index 0000000..eeb4dd0
--- /dev/null
+++ 
b/server/task-json/src/main/java/org/apache/james/server/task/json/JsonTaskAdditionalInformationsSerializer.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.james.server.task.json;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.james.json.JsonGenericSerializer;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTO;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
+import org.apache.james.task.TaskExecutionDetails;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.collect.ImmutableSet;
+
+public class JsonTaskAdditionalInformationsSerializer {
+
+    public static class InvalidAdditionalInformationsException extends 
RuntimeException {
+        public 
InvalidAdditionalInformationsException(JsonGenericSerializer.InvalidTypeException
 original) {
+            super(original);
+        }
+    }
+
+    public static class UnknownAdditionalInformationException extends 
RuntimeException {
+        public 
UnknownAdditionalInformationException(JsonGenericSerializer.UnknownTypeException
 original) {
+            super(original);
+        }
+    }
+
+    private JsonGenericSerializer<TaskExecutionDetails.AdditionalInformation, 
AdditionalInformationDTO> jsonGenericSerializer;
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Inject
+    public 
JsonTaskAdditionalInformationsSerializer(Set<AdditionalInformationDTOModule> 
modules) {
+        jsonGenericSerializer = new JsonGenericSerializer(modules);
+    }
+
+    public 
JsonTaskAdditionalInformationsSerializer(@SuppressWarnings("rawtypes") 
AdditionalInformationDTOModule... modules) {
+        this(ImmutableSet.copyOf(modules));
+    }
+
+    public String serialize(TaskExecutionDetails.AdditionalInformation 
additionalInformation) throws JsonProcessingException {
+        try {
+            return jsonGenericSerializer.serialize(additionalInformation);
+        } catch (JsonGenericSerializer.UnknownTypeException e) {
+            throw new UnknownAdditionalInformationException(e);
+        }
+    }
+
+    public TaskExecutionDetails.AdditionalInformation deserialize(String type, 
String value) throws IOException {
+        try {
+            return jsonGenericSerializer.deserialize(type, value);
+        } catch (JsonGenericSerializer.UnknownTypeException e) {
+            throw new UnknownAdditionalInformationException(e);
+        } catch (JsonGenericSerializer.InvalidTypeException e) {
+            throw new InvalidAdditionalInformationsException(e);
+        }
+    }
+}
diff --git 
a/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTO.java
 
b/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTO.java
new file mode 100644
index 0000000..4ce0a88
--- /dev/null
+++ 
b/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTO.java
@@ -0,0 +1,24 @@
+/****************************************************************
+ * 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.server.task.json.dto;
+
+import org.apache.james.json.DTO;
+
+public interface AdditionalInformationDTO extends DTO {
+}
diff --git 
a/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTOModule.java
 
b/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTOModule.java
new file mode 100644
index 0000000..59af490
--- /dev/null
+++ 
b/server/task-json/src/main/java/org/apache/james/server/task/json/dto/AdditionalInformationDTOModule.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.server.task.json.dto;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+
+public class AdditionalInformationDTOModule<T extends 
TaskExecutionDetails.AdditionalInformation, U extends AdditionalInformationDTO> 
extends DTOModule<T, U> {
+
+    public static <TaskTypeT extends Task> Builder<TaskTypeT> 
forAdditionalInformation(Class<TaskTypeT> taskType) {
+        return new Builder<>(taskType);
+    }
+
+    public AdditionalInformationDTOModule(DTOConverter<T, U> converter, 
DomainObjectConverter<T, U> toDomainObjectConverter, Class<T> domainObjectType, 
Class<U> dtoType, String typeName) {
+        super(converter, toDomainObjectConverter, domainObjectType, dtoType, 
typeName);
+    }
+}


---------------------------------------------------------------------
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