Remove IP requirement

Remove the requirement of at least one IP present in VES event.
Update IP information in AAI only if it is present and is not empty.

Change-Id: I83ae8990d45d71de4c839e43b5065db89b6c6a3a
Issue-ID: DCAEGEN2-1312
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
index a69b7c5..b628d96 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
@@ -120,7 +120,7 @@
         this.pnfSwVersionOptionalField = getValueFromJson(pnfRegistrationFields, SW_VERSION);
         this.pnfAdditionalFields = pnfRegistrationFields.getAsJsonObject(ADDITIONAL_FIELDS);
 
-        return (StringUtils.isEmpty(pnfSourceName) || !ipPropertiesNotEmpty(pnfOamIpv4Address, pnfOamIpv6Address))
+        return (StringUtils.isEmpty(pnfSourceName))
                 ? logErrorAndReturnMonoEmpty("Incorrect json, consumerDmaapModel can not be created: "
                 + printMessage()) :
                 Mono.just(ImmutableConsumerDmaapModel.builder()
@@ -140,10 +140,6 @@
         return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
     }
 
-    private boolean ipPropertiesNotEmpty(String ipv4, String ipv6) {
-        return (!StringUtils.isEmpty(ipv4)) || !(StringUtils.isEmpty(ipv6));
-    }
-
     private boolean containsHeader(JsonObject jsonObject) {
         return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(PNF_REGISTRATION_FIELDS);
     }
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java
index 8e95a75..2be95ee 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java
@@ -22,9 +22,11 @@
 
 import com.google.gson.GsonBuilder;
 import com.google.gson.TypeAdapterFactory;
+import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder;
 import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
 
 import java.util.ServiceLoader;
+import org.springframework.util.StringUtils;
 
 
 public class AaiJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> {
@@ -39,9 +41,7 @@
         GsonBuilder gsonBuilder = new GsonBuilder();
         ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
 
-        return gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder()
-            .ipv4(consumerDmaapModel.getIpv4())
-            .ipv6(consumerDmaapModel.getIpv6())
+        Builder builder = ImmutableConsumerDmaapModel.builder()
             .correlationId(consumerDmaapModel.getCorrelationId())
             .serialNumber(consumerDmaapModel.getSerialNumber())
             .equipVendor(consumerDmaapModel.getEquipVendor())
@@ -49,7 +49,17 @@
             .equipType(consumerDmaapModel.getEquipType())
             .nfRole(consumerDmaapModel.getNfRole())
             .swVersion(consumerDmaapModel.getSwVersion())
-            .additionalFields(consumerDmaapModel.getAdditionalFields())
-            .build());
+            .additionalFields(consumerDmaapModel.getAdditionalFields());
+
+        String ipv4 = consumerDmaapModel.getIpv4();
+        if (!StringUtils.isEmpty(ipv4)) {
+            builder.ipv4(ipv4);
+        }
+        String ipv6 = consumerDmaapModel.getIpv6();
+        if (!StringUtils.isEmpty(ipv6)) {
+            builder.ipv6(ipv6);
+        }
+
+        return gsonBuilder.create().toJson(builder.build());
     }
 }
\ No newline at end of file
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java
index d1995f3..60ce520 100644
--- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java
+++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java
@@ -57,4 +57,58 @@
 
         assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model));
     }
+
+    @Test
+    void createJsonBodyWithoutIPs_shouldReturnJsonInString() {
+
+        ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
+            .correlationId("NOKnhfsadhff")
+            .serialNumber("1234")
+            .equipVendor("NOKIA")
+            .equipModel("3310")
+            .equipType("cell")
+            .nfRole("role")
+            .swVersion("1.2.3")
+            .build();
+
+        String expectedResult = "{"
+            + "\"correlationId\":\"NOKnhfsadhff\","
+            + "\"serial-number\":\"1234\","
+            + "\"equip-vendor\":\"NOKIA\","
+            + "\"equip-model\":\"3310\","
+            + "\"equip-type\":\"cell\","
+            + "\"nf-role\":\"role\","
+            + "\"sw-version\":\"1.2.3\""
+            + "}";
+
+        assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model));
+    }
+
+    @Test
+    void createJsonBodyWithEmptyIPs_shouldReturnJsonInString() {
+
+        ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
+            .correlationId("NOKnhfsadhff")
+            .ipv4("")
+            .ipv6("")
+            .serialNumber("1234")
+            .equipVendor("NOKIA")
+            .equipModel("3310")
+            .equipType("cell")
+            .nfRole("role")
+            .swVersion("1.2.3")
+            .build();
+
+        String expectedResult = "{"
+            + "\"correlationId\":\"NOKnhfsadhff\","
+            + "\"serial-number\":\"1234\","
+            + "\"equip-vendor\":\"NOKIA\","
+            + "\"equip-model\":\"3310\","
+            + "\"equip-type\":\"cell\","
+            + "\"nf-role\":\"role\","
+            + "\"sw-version\":\"1.2.3\""
+            + "}";
+
+        assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model));
+    }
 }