diff options
Diffstat (limited to 'prh-commons/src/main')
-rw-r--r-- | prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java | 10 | ||||
-rw-r--r-- | prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java | 18 |
2 files changed, 18 insertions, 10 deletions
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java index 9abbc3b4..d8eefec1 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java @@ -20,6 +20,7 @@ package org.onap.dcaegen2.services.prh.model; +import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; import org.immutables.gson.Gson; import org.immutables.value.Value; @@ -37,12 +38,6 @@ public interface ConsumerDmaapModel extends AaiModel, DmaapModel { @SerializedName(value = "correlationId", alternate = "correlationId") String getCorrelationId(); - @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam") - String getIpv4(); - - @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam") - String getIpv6(); - @SerializedName(value = "serial-number", alternate = "serial-number") String getSerialNumber(); @@ -60,4 +55,7 @@ public interface ConsumerDmaapModel extends AaiModel, DmaapModel { @SerializedName(value = "sw-version", alternate = "sw-version") String getSwVersion(); + + @SerializedName(value = "additionalFields", alternate = "additionalFields") + JsonObject getAdditionalFields(); } diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java index fd628834..f04168c2 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java @@ -21,6 +21,8 @@ package org.onap.dcaegen2.services.prh.model; import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.TypeAdapterFactory; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; @@ -29,6 +31,7 @@ import java.util.ServiceLoader; public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> { + public static final String ADDITIONAL_FIELDS = "additionalFields"; /** * Method for serialization object by GSON. @@ -39,9 +42,7 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { GsonBuilder gsonBuilder = new GsonBuilder(); ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); - return gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder() - .ipv4(consumerDmaapModel.getIpv4()) - .ipv6(consumerDmaapModel.getIpv6()) + return filterOutAdditionalFieldsIfEmpty(gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder() .correlationId(consumerDmaapModel.getCorrelationId()) .serialNumber(consumerDmaapModel.getSerialNumber()) .equipVendor(consumerDmaapModel.getEquipVendor()) @@ -49,6 +50,15 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> .equipType(consumerDmaapModel.getEquipType()) .nfRole(consumerDmaapModel.getNfRole()) .swVersion(consumerDmaapModel.getSwVersion()) - .build()); + .additionalFields(consumerDmaapModel.getAdditionalFields()) + .build())); + } + + private String filterOutAdditionalFieldsIfEmpty(String json) { + JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); + if(jsonObject.get(ADDITIONAL_FIELDS).equals(new JsonObject())) { + jsonObject.remove(ADDITIONAL_FIELDS); + } + return jsonObject.toString(); } }
\ No newline at end of file |