2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2018 Nokia.
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.bpmn.infrastructure.pnf.kafka;
26 import com.google.gson.JsonArray;
27 import com.google.gson.JsonElement;
28 import com.google.gson.JsonObject;
29 import com.google.gson.JsonParser;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33 import java.util.Optional;
34 import java.util.Spliterator;
36 public final class JsonUtilForPnfCorrelationId {
38 private static final String JSON_PNF_CORRELATION_ID_FIELD_NAME = "correlationId";
40 private JsonUtilForPnfCorrelationId() {
41 throw new IllegalStateException("Utility class");
44 static List<String> parseJsonToGelAllPnfCorrelationId(List<String> list) {
45 if (list == null || list.isEmpty()) {
46 return Collections.emptyList();
49 List<String> newList = new ArrayList<>();
50 list.forEach(je -> handleEscapedCharacters(new JsonParser().parse(je))
51 .ifPresent(jsonObject -> getPnfCorrelationId(jsonObject)
52 .ifPresent(pnfCorrelationId -> newList.add(pnfCorrelationId))));
56 private static Optional<JsonObject> handleEscapedCharacters(JsonElement jsonElement) {
57 if (jsonElement.isJsonObject()) {
58 return Optional.ofNullable(jsonElement.getAsJsonObject());
60 return Optional.ofNullable(new JsonParser().parse(jsonElement.getAsString()).getAsJsonObject());
63 private static Optional<String> getPnfCorrelationId(JsonObject jsonObject) {
64 if (jsonObject.has(JSON_PNF_CORRELATION_ID_FIELD_NAME)) {
65 return Optional.ofNullable(jsonObject.get(JSON_PNF_CORRELATION_ID_FIELD_NAME).getAsString());
67 return Optional.empty();