summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-05-27 10:59:04 +0000
committerGerrit Code Review <gerrit@onap.org>2020-05-27 10:59:04 +0000
commit7223180206b466248afa5330640365b13d760a3d (patch)
tree1d1c99342bd48d561a6fe4184614f2739e49c3a0 /bpmn
parente386b185fd13548a43bfd258dabda4093a9254bd (diff)
parente4f0a5c9ecbbdb1cdebcab2706a44d869ce03c9e (diff)
Merge "removed net.minidev.json from codebase"
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java55
1 files 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 <br/>
@@ -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<String, String> vnfParametersMap = getVnfParameterMap(vnfParameters);
- final Map<String, String> additionalParameters = getAdditionalParameters(vnfParametersMap);
- final List<ExternalVirtualLink> 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<VnfParameter> vnfParametersArray =
+ mapper.readValue(json, new TypeReference<List<VnfParameter>>() {});
+ final Map<String, String> vnfParametersMap = getVnfParameterMap(vnfParametersArray);
+ final Map<String, String> additionalParameters = getAdditionalParameters(vnfParametersMap);
+ final List<ExternalVirtualLink> 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<String, String> 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<String, String> getVnfParameterMap(final List<VnfParameter> 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();
}