From 4bd281390ed24b278846775c1157f82db81fddbe Mon Sep 17 00:00:00 2001 From: maximesson Date: Thu, 21 Mar 2019 15:58:55 +0000 Subject: Add check to DataRouter if file has been published For each file in the FileReady message that DFC does not know if it has been published yet, it should ask DataRouter if it has been published already to avoid downloading and publishing a file more than once. Change-Id: I18117a6e968ec929aa255052a4c44f890a8ed39d Issue-ID: DCAEGEN2-1256 Signed-off-by: maximesson --- .../datafile/exceptions/DatafileTaskException.java | 2 +- .../collectors/datafile/model/CommonFunctions.java | 35 ++++++++++++++++++++-- .../datafile/model/ConsumerDmaapModel.java | 5 +++- 3 files changed, 37 insertions(+), 5 deletions(-) (limited to 'datafile-commons/src/main/java') diff --git a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java index 0eaa7a17..5e08efc7 100644 --- a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java +++ b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/DatafileTaskException.java @@ -30,6 +30,6 @@ public class DatafileTaskException extends Exception { } public DatafileTaskException(String message, Exception e) { - super(message + e); + super(message, e); } } diff --git a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctions.java b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctions.java index 9f3a3188..f115dba7 100644 --- a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctions.java +++ b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/CommonFunctions.java @@ -20,15 +20,44 @@ package org.onap.dcaegen2.collectors.datafile.model; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.nio.file.Path; +/** + * Helper class to serialize object. + */ public class CommonFunctions { - private static Gson gson = new GsonBuilder().serializeNulls().create(); + private static Gson gson = + new GsonBuilder().registerTypeHierarchyAdapter(Path.class, new PathConverter()).serializeNulls().create(); - private CommonFunctions() {} + private CommonFunctions() { + } + /** + * Serializes a ConsumerDmaapModel. + * + * @param consumerDmaapModel model to serialize. + * + * @return a string with the serialized model. + */ public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { return gson.toJson(consumerDmaapModel); } -} \ No newline at end of file + + /** + * Json serializer that handles Path serializations, since Path does not implement the + * Serializable interface. + */ + public static class PathConverter implements JsonSerializer { + @Override + public JsonElement serialize(Path path, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(path.toString()); + } + } +} diff --git a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModel.java b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModel.java index 972316bf..2337485a 100644 --- a/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModel.java +++ b/datafile-commons/src/main/java/org/onap/dcaegen2/collectors/datafile/model/ConsumerDmaapModel.java @@ -17,6 +17,9 @@ package org.onap.dcaegen2.collectors.datafile.model; import com.google.gson.annotations.SerializedName; + +import java.nio.file.Path; + import org.immutables.gson.Gson; import org.immutables.value.Value; import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; @@ -55,7 +58,7 @@ public interface ConsumerDmaapModel extends DmaapModel { String getLocation(); @SerializedName("internalLocation") - String getInternalLocation(); + Path getInternalLocation(); @SerializedName("compression") String getCompression(); -- cgit 1.2.3-korg