summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main
diff options
context:
space:
mode:
authorPrzemyslaw Wasala <przemyslaw.wasala@nokia.com>2018-08-30 10:54:42 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-30 10:54:42 +0000
commit82a6fc31d1905f380fbbae1d0b4a34b67d8258e3 (patch)
tree0b43eab94e92ecad870b2a72325d6e650299e532 /prh-app-server/src/main
parentdbf0ce580ccf9dd68c57e2008c2e0f23c35cb2f2 (diff)
parented4d45332691282e7e0dc4bb413d20f46e1a0a66 (diff)
Merge "Introduction of a new parameter "sourceName""
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java46
1 files changed, 22 insertions, 24 deletions
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 17b1ef67..8742d872 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
@@ -40,11 +40,11 @@ import reactor.core.publisher.Mono;
public class DmaapConsumerJsonParser {
private static final String EVENT = "event";
+ private static final String COMMON_EVENT_HEADER = "commonEventHeader";
private static final String PNF_REGISTRATION_FIELDS = "pnfRegistrationFields";
private static final String OAM_IPV_4_ADDRESS = "oamV4IpAddress";
private static final String OAM_IPV_6_ADDRESS = "oamV6IpAddress";
- private static final String VENDOR_NAME = "vendorName";
- private static final String SERIAL_NUMBER = "serialNumber";
+ private static final String SOURCE_NAME = "sourceName";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -89,20 +89,23 @@ public class DmaapConsumerJsonParser {
: transform(monoJsonP));
}
- private Mono<ConsumerDmaapModel> transform(JsonObject monoJsonP) {
- monoJsonP = monoJsonP.getAsJsonObject(EVENT).getAsJsonObject(PNF_REGISTRATION_FIELDS);
- String pnfVendorName = getValueFromJson(monoJsonP, VENDOR_NAME);
- String pnfSerialNumber = getValueFromJson(monoJsonP, SERIAL_NUMBER);
- String pnfOamIpv4Address = getValueFromJson(monoJsonP, OAM_IPV_4_ADDRESS);
- String pnfOamIpv6Address = getValueFromJson(monoJsonP, OAM_IPV_6_ADDRESS);
- return
- (!vendorAndSerialNotEmpty(pnfSerialNumber, pnfVendorName) || !ipPropertiesNotEmpty(pnfOamIpv4Address,
- pnfOamIpv6Address))
+ private Mono<ConsumerDmaapModel> transform(JsonObject responseFromDmaap) {
+
+ JsonObject commonEventHeader = responseFromDmaap.getAsJsonObject(EVENT)
+ .getAsJsonObject(COMMON_EVENT_HEADER);
+ JsonObject pnfRegistrationFields = responseFromDmaap.getAsJsonObject(EVENT)
+ .getAsJsonObject(PNF_REGISTRATION_FIELDS);
+
+ String pnfSourceName = getValueFromJson(commonEventHeader, SOURCE_NAME);
+ String pnfOamIpv4Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_4_ADDRESS);
+ String pnfOamIpv6Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_6_ADDRESS);
+
+ return ( StringUtils.isEmpty(pnfSourceName) || !ipPropertiesNotEmpty(pnfOamIpv4Address, pnfOamIpv6Address) )
? Mono.error(new DmaapNotFoundException("Incorrect json, consumerDmaapModel can not be created: "
- + printMessage(pnfVendorName, pnfSerialNumber, pnfOamIpv4Address, pnfOamIpv6Address))) :
+ + printMessage(pnfSourceName, pnfOamIpv4Address, pnfOamIpv6Address))) :
Mono.just(ImmutableConsumerDmaapModel.builder()
- .pnfName(pnfVendorName.substring(0, Math.min(pnfVendorName.length(), 3)).toUpperCase()
- .concat(pnfSerialNumber)).ipv4(pnfOamIpv4Address)
+ .sourceName(pnfSourceName)
+ .ipv4(pnfOamIpv4Address)
.ipv6(pnfOamIpv6Address).build());
}
@@ -110,10 +113,6 @@ public class DmaapConsumerJsonParser {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
- private boolean vendorAndSerialNotEmpty(String pnfSerialNumber, String pnfVendorName) {
- return (!StringUtils.isEmpty(pnfSerialNumber) && !StringUtils.isEmpty(pnfVendorName));
- }
-
private boolean ipPropertiesNotEmpty(String ipv4, String ipv6) {
return (!StringUtils.isEmpty(ipv4)) || !(StringUtils.isEmpty(ipv6));
}
@@ -122,12 +121,11 @@ public class DmaapConsumerJsonParser {
return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(PNF_REGISTRATION_FIELDS);
}
- private String printMessage(String vendorName, String serialNumber, String oamIpv4Address, String oamIpv6Address) {
+ private String printMessage(String sourceName, String oamIpv4Address, String oamIpv6Address) {
return String.format("%n{"
- + "\"" + VENDOR_NAME + " : \"%s\","
- + "\"" + SERIAL_NUMBER + "\": \"%s\","
- + "\"" + OAM_IPV_4_ADDRESS + "\": \"%s\","
- + "\"" + OAM_IPV_6_ADDRESS + "\": \"%s\""
- + "%n}", vendorName, serialNumber, oamIpv4Address, oamIpv6Address);
+ + "\"" + SOURCE_NAME + "\": \"%s\","
+ + "\"" + OAM_IPV_4_ADDRESS + "\": \"%s\","
+ + "\"" + OAM_IPV_6_ADDRESS + "\": \"%s\""
+ + "%n}", sourceName, oamIpv4Address, oamIpv6Address);
}
}