[SO] Remove DMaap Dependency in SO-bpmn-infra
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / dmaap / JsonUtilForPnfCorrelationId.java
index fb5d043..9cb566f 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2018 Nokia.
+ * Modifications Copyright (c) 2019 Samsung
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,6 +28,7 @@ import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.Spliterator;
@@ -35,17 +37,20 @@ public final class JsonUtilForPnfCorrelationId {
 
     private static final String JSON_PNF_CORRELATION_ID_FIELD_NAME = "correlationId";
 
-    static List<String> parseJsonToGelAllPnfCorrelationId(String json) {
-        JsonElement je = new JsonParser().parse(json);
-        JsonArray array = je.getAsJsonArray();
-        List<String> list = new ArrayList<>();
-        Spliterator<JsonElement> spliterator = array.spliterator();
-        spliterator.forEachRemaining(jsonElement -> {
-            handleEscapedCharacters(jsonElement)
-                    .ifPresent(jsonObject -> getPnfCorrelationId(jsonObject)
-                            .ifPresent(pnfCorrelationId -> list.add(pnfCorrelationId)));
-        });
-        return list;
+    private JsonUtilForPnfCorrelationId() {
+        throw new IllegalStateException("Utility class");
+    }
+
+    static List<String> parseJsonToGelAllPnfCorrelationId(List<String> list) {
+        if (list == null || list.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        List<String> newList = new ArrayList<>();
+        list.forEach(je -> handleEscapedCharacters(new JsonParser().parse(je))
+                .ifPresent(jsonObject -> getPnfCorrelationId(jsonObject)
+                        .ifPresent(pnfCorrelationId -> newList.add(pnfCorrelationId))));
+        return newList;
     }
 
     private static Optional<JsonObject> handleEscapedCharacters(JsonElement jsonElement) {