aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java/org
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-05-28 14:20:51 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-05-30 12:12:37 +0200
commit04fdbd0e18a891241ed068044093a257ff506400 (patch)
tree526127ebe596b1d139d39e704a492b53647b5733 /prh-app-server/src/main/java/org
parent7ddaf390698fe5ae9143d91e7011059b3973f8ce (diff)
Fix for Json parser
Change-Id: I322b893356a41ee27dfb14d9ef9dfcdd129e8ced Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java/org')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java18
1 files changed, 12 insertions, 6 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 0ef7e4fe..04956f8d 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
@@ -26,6 +26,8 @@ import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
+import java.util.stream.StreamSupport;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
*/
@@ -42,9 +44,16 @@ public class DmaapConsumerJsonParser {
private DmaapConsumerJsonParser() {
}
+
public static ConsumerDmaapModel getJsonObject(String message) throws DmaapNotFoundException {
JsonElement jsonElement = new JsonParser().parse(message);
- JsonObject jsonObject = jsonElement.getAsJsonObject();
+ JsonObject jsonObject;
+
+ jsonObject = jsonElement.isJsonObject() ? jsonElement.getAsJsonObject() :
+ StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
+ .orElseThrow(() -> new DmaapNotFoundException("Json object not found in json array"))
+ .getAsJsonObject();
+
return create(jsonObject);
}
@@ -64,14 +73,11 @@ public class DmaapConsumerJsonParser {
}
throw new DmaapNotFoundException("IPV4 and IPV6 are empty");
}
- throw new DmaapNotFoundException("Incorrect JsonObject");
+ throw new DmaapNotFoundException("Incorrect JsonObject - missing header");
}
private static String getValueFromJson(JsonObject jsonObject, String jsonKey) {
- if (jsonObject.has(jsonKey)) {
- return jsonObject.get(jsonKey).getAsString();
- }
- return "";
+ return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
private static boolean isVendorAndSerialNotEmpty(String pnfSerialNumber, String pnfVendorName) {