diff options
Diffstat (limited to 'prh-app-server/src/main/java')
2 files changed, 9 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 3bac7c36..ab4ec633 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,14 +40,15 @@ public class DmaapConsumerJsonParser { private static final String PNF_VENDOR_NAME = "pnfVendorName"; private static final String PNF_SERIAL_NUMBER = "pnfSerialNumber"; - public ConsumerDmaapModel getJsonObject(String message) throws DmaapNotFoundException { + public Optional<ConsumerDmaapModel> getJsonObject(String message) throws DmaapNotFoundException { JsonElement jsonElement = new JsonParser().parse(message); if (jsonElement.isJsonObject()) { - return create(jsonElement.getAsJsonObject()); + return Optional.of(create(jsonElement.getAsJsonObject())); } else { - return create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst() - .flatMap(this::getJsonObjectFromAnArray) - .orElseThrow(() -> new DmaapNotFoundException("Json object not found in json array"))); + return Optional + .of(create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst() + .flatMap(this::getJsonObjectFromAnArray) + .orElse(null))); } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index 01b85a9d..9d818366 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -60,7 +60,9 @@ public class DmaapConsumerTaskImpl extends @Override ConsumerDmaapModel consume(String message) throws DmaapNotFoundException { logger.trace("Method called with arg {}", message); - return dmaapConsumerJsonParser.getJsonObject(message); + return dmaapConsumerJsonParser.getJsonObject(message) + .orElseThrow(() -> new DmaapNotFoundException(String.format("Nothing to consume from DmaaP %s topic.", + resolveConfiguration().dmaapTopicName()))); } @Override |