From e4f0a5c9ecbbdb1cdebcab2706a44d869ce03c9e Mon Sep 17 00:00:00 2001 From: "Benjamin, Max" Date: Tue, 26 May 2020 11:46:44 -0400 Subject: removed net.minidev.json from codebase removed net.minidev.json from codebase Issue-ID: SO-2957 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I03f89a1002b3cf052a304503cd206a979bfee6f8 --- .../tasks/utils/SdncInputParametersProvider.java | 55 ++++++++++------------ 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java index ce0f2c7417..6831a656a8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java @@ -24,7 +24,6 @@ import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.EXT_V import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.FORWARD_SLASH; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.PRELOAD_VNFS_URL; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -32,14 +31,14 @@ import java.util.stream.Collectors; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.ExternalVirtualLink; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.jsonpath.JsonPathUtil; import org.onap.so.client.sdnc.SDNCClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.jayway.jsonpath.JsonPath; -import net.minidev.json.JSONArray; /** * This class retrieve pre-load data from SDNC using
@@ -56,9 +55,12 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider private final SDNCClient sdncClient; + private final ObjectMapper mapper; + @Autowired public SdncInputParametersProvider(final SDNCClient sdncClient) { this.sdncClient = sdncClient; + this.mapper = new ObjectMapper(); } @Override @@ -70,21 +72,23 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider try { LOGGER.debug("Will query sdnc for input parameters using url: {}", url); final String jsonResponse = sdncClient.get(url); - - final JSONArray vnfParametersArray = JsonPath.read(jsonResponse, VNF_PARAMETERS_PATH); - if (vnfParametersArray != null) { - for (int index = 0; index < vnfParametersArray.size(); index++) { - final Object vnfParametersObject = vnfParametersArray.get(index); - if (vnfParametersObject instanceof JSONArray) { - final JSONArray vnfParameters = (JSONArray) vnfParametersObject; - final Map vnfParametersMap = getVnfParameterMap(vnfParameters); - final Map additionalParameters = getAdditionalParameters(vnfParametersMap); - final List extVirtualLinks = getExtVirtualLinks(vnfParametersMap); - final InputParameter inputParameter = new InputParameter(additionalParameters, extVirtualLinks); - LOGGER.info("InputParameter found in sdnc response : {}", inputParameter); - return inputParameter; - } + final String json = JsonPathUtil.getInstance().locateResult(jsonResponse, VNF_PARAMETERS_PATH).orElse(null); + + try { + + if (json != null) { + final List vnfParametersArray = + mapper.readValue(json, new TypeReference>() {}); + final Map vnfParametersMap = getVnfParameterMap(vnfParametersArray); + final Map additionalParameters = getAdditionalParameters(vnfParametersMap); + final List extVirtualLinks = getExtVirtualLinks(vnfParametersMap); + final InputParameter inputParameter = new InputParameter(additionalParameters, extVirtualLinks); + LOGGER.info("InputParameter found in sdnc response : {}", inputParameter); + return inputParameter; } + + } catch (final IOException exception) { + LOGGER.error("Unable to parse vnf parameters : {}", json, exception); } } catch (final Exception exception) { LOGGER.error("Unable to retrieve/parse input parameters using URL: {} ", url, exception); @@ -112,19 +116,12 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider } - private Map getVnfParameterMap(final JSONArray array) { - try { - if (array != null) { - final ObjectMapper mapper = new ObjectMapper(); - final VnfParameter[] readValue = mapper.readValue(array.toJSONString(), VnfParameter[].class); - LOGGER.debug("Vnf parameters: {}", Arrays.asList(readValue)); - return Arrays.asList(readValue).stream() - .filter(vnfParam -> vnfParam.getName() != null && vnfParam.getValue() != null) - .collect(Collectors.toMap(VnfParameter::getName, VnfParameter::getValue)); - } - } catch (final IOException exception) { - LOGGER.error("Unable to parse vnf parameters : {}", array, exception); + private Map getVnfParameterMap(final List array) { + if (array != null) { + return array.stream().filter(vnfParam -> vnfParam.getName() != null && vnfParam.getValue() != null) + .collect(Collectors.toMap(VnfParameter::getName, VnfParameter::getValue)); } + return Collections.emptyMap(); } -- cgit 1.2.3-korg