From e6f9402455d0931c6d2e078a7780ed3969fe0121 Mon Sep 17 00:00:00 2001 From: Agata Stanislawska Date: Wed, 22 Jul 2020 12:55:50 +0200 Subject: Sonar fixes Issue-ID: SO-1841 Signed-off-by: astanislawska Change-Id: Ibd594e83b022d3b9a363a69f47da7bec616913ae Signed-off-by: astanislawska --- .../tasks/utils/SdncInputParametersProvider.java | 69 ++++++++++++---------- .../utils/UserParamInputParametersProvider.java | 4 +- .../adapter/vnfm/tasks/utils/VnfParameter.java | 21 +------ 3 files changed, 43 insertions(+), 51 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src') 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 6831a656a8..92ed61df67 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 @@ -50,11 +50,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class SdncInputParametersProvider extends AbstractInputParametersProvider { private static final Logger LOGGER = LoggerFactory.getLogger(SdncInputParametersProvider.class); - private static final String VNF_PARAMETERS_PATH = "$..vnf-parameters"; - private final SDNCClient sdncClient; - private final ObjectMapper mapper; @Autowired @@ -68,34 +65,12 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider final String vnfName = genericVnf.getVnfName(); final String vnfType = getVnfType(genericVnf); final String url = getPreloadVnfsUrl(vnfName, vnfType); + final InputParameter inputParameter = parseInputParametersUsingUrl(url); - try { - LOGGER.debug("Will query sdnc for input parameters using url: {}", url); - final String jsonResponse = sdncClient.get(url); - 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); - } + if (inputParameter != null) + return inputParameter; LOGGER.warn("No input parameters found ..."); return NullInputParameter.NULL_INSTANCE; - } private List getExtVirtualLinks(final Map vnfParametersMap) { @@ -109,19 +84,18 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider private Map getAdditionalParameters(final Map vnfParametersMap) { final String additionalParamsString = vnfParametersMap.get(ADDITIONAL_PARAMS); + if (additionalParamsString != null && !additionalParamsString.isEmpty()) { return parseAdditionalParameters(additionalParamsString); } return Collections.emptyMap(); } - 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(); } @@ -131,10 +105,43 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider private String getVnfType(final GenericVnf genericVnf) { final ModelInfoGenericVnf modelInfoGenericVnf = genericVnf.getModelInfoGenericVnf(); - if (modelInfoGenericVnf != null && modelInfoGenericVnf.getModelName() != null) { + if (modelInfoGenericVnf != null) { return modelInfoGenericVnf.getModelName(); } return genericVnf.getVnfType(); } + private InputParameter parseInputParametersUsingUrl(String url) { + try { + LOGGER.debug("Will query sdnc for input parameters using url: {}", url); + final String jsonResponse = sdncClient.get(url); + final String json = JsonPathUtil.getInstance().locateResult(jsonResponse, VNF_PARAMETERS_PATH).orElse(null); + final InputParameter inputParameter = parseVnfParameters(json); + + if (inputParameter != null) + return inputParameter; + } catch (final Exception exception) { + LOGGER.error("Unable to retrieve/parse input parameters using URL: {} ", url, exception); + } + return null; + } + + private InputParameter parseVnfParameters(String json) { + 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); + } + return null; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java index ac939d04ec..bdd738b031 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java @@ -40,12 +40,12 @@ public class UserParamInputParametersProvider extends AbstractInputParametersPro final InputParameter inputParameter = new InputParameter(); final Object additionalParams = userParams.get(ADDITIONAL_PARAMS); - if (additionalParams != null && additionalParams instanceof String) { + if (additionalParams instanceof String) { inputParameter.setAdditionalParams(parseAdditionalParameters(additionalParams.toString())); } final Object extVirtualLinks = userParams.get(EXT_VIRTUAL_LINKS); - if (extVirtualLinks != null && extVirtualLinks instanceof String) { + if (extVirtualLinks instanceof String) { inputParameter.setExtVirtualLinks(parseExternalVirtualLinks(extVirtualLinks.toString())); } LOGGER.info("InputParameter found in userParams : {}", inputParameter); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java index 0d45dad6fe..2491c99bc4 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java @@ -35,30 +35,18 @@ public class VnfParameter { @JsonProperty("vnf-parameter-value") private String value; - /** - * @return the name - */ public String getName() { return name; } - /** - * @param name the name to set - */ public void setName(final String name) { this.name = name; } - /** - * @return the value - */ public String getValue() { return value; } - /** - * @param value the value to set - */ public void setValue(final String value) { this.value = value; } @@ -66,10 +54,9 @@ public class VnfParameter { @Override public int hashCode() { final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return Objects.hash(name, value); + int nameResult = prime + ((name == null) ? 0 : name.hashCode()); + int valueResult = prime + ((value == null) ? 0 : value.hashCode()); + return Objects.hash(nameResult, valueResult); } @Override @@ -78,7 +65,6 @@ public class VnfParameter { VnfParameter other = (VnfParameter) obj; return Objects.equals(name, other.name) && Objects.equals(value, other.value); } - return false; } @@ -86,5 +72,4 @@ public class VnfParameter { public String toString() { return "VnfParameter [name=" + name + ", value=" + value + "]"; } - } -- cgit 1.2.3-korg