diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java index 0412516390..07d5ba0f24 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java @@ -126,7 +126,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties private Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, PROPERTYOWNER propertiesOwner, List<ComponentInstancePropInput> propsToDeclare) { - PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propertiesOwner, + PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propsToDeclare); return updatePropertiesValues(component, propertiesOwner.getUniqueId(), policyProperties.getPropertiesToUpdate()).left() .map(updatePropsRes -> policyProperties.getPoliciesToCreate()); @@ -144,8 +144,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties .map(updatePropsRes -> inputsProperties.getInputsToCreate()); } - private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner, - List<ComponentInstancePropInput> propsToDeclare) { + private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, List<ComponentInstancePropInput> propsToDeclare) { List<PROPERTYTYPE> declaredProperties = new ArrayList<>(); List<PolicyDefinition> policies = new ArrayList<>(); propsToDeclare.forEach(property -> policies.add(declarePropertyPolicy(componentId, declaredProperties, property))); @@ -250,7 +249,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties if (propertyCapability.isPresent()) { String capName = propertyCapability.get().getName(); if (capName.contains(".")) { - capName = capName.replaceAll("\\.", UNDERSCORE); + capName = capName.replace(".", UNDERSCORE); } generatedInputPrefix = generatedInputPrefix == null || generatedInputPrefix.isEmpty() ? capName : generatedInputPrefix + UNDERSCORE + capName; @@ -315,12 +314,12 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties input.setInputPath(propertiesName); input.setInstanceUniqueId(propertiesOwner.getUniqueId()); input.setPropertyId(propInput.getUniqueId()); - if (Objects.isNull(input.getSubPropertyInputPath()) || (Objects.nonNull(propertiesName) && input.getSubPropertyInputPath() + if (Objects.isNull(input.getSubPropertyInputPath()) || (StringUtils.isNotEmpty(propertiesName) && input.getSubPropertyInputPath() .substring(input.getSubPropertyInputPath().lastIndexOf('#')).equals(propertiesName.substring(propertiesName.lastIndexOf('#'))))) { input.setParentPropertyType(propInput.getType()); input.setSubPropertyInputPath(propertiesName); } - changePropertyValueToGetInputValue(inputName, parsedPropNames, input, prop, complexProperty); + changePropertyValueToGetInputValue(parsedPropNames, input, prop, complexProperty); if (prop instanceof IComponentInstanceConnectedElement) { ((IComponentInstanceConnectedElement) prop).setComponentInstanceId(propertiesOwner.getUniqueId()); ((IComponentInstanceConnectedElement) prop).setComponentInstanceName(propertiesOwner.getName()); @@ -328,42 +327,43 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties return input; } - private void changePropertyValueToGetInputValue(String inputName, String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop, + private void changePropertyValueToGetInputValue(String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop, boolean complexProperty) { JSONObject jsonObject = new JSONObject(); - String value = prop.getValue(); + final String value = prop.getValue(); + final String inputName = input.getName(); if (value == null || value.isEmpty()) { if (complexProperty) { jsonObject = createJSONValueForProperty(parsedPropNames.length - 1, parsedPropNames, jsonObject, inputName); prop.setValue(jsonObject.toJSONString()); } else { - jsonObject.put(GET_INPUT, input.getName()); + jsonObject.put(GET_INPUT, inputName); prop.setValue(jsonObject.toJSONString()); } } else { - Object objValue = new Yaml().load(value); + final Object objValue = new Yaml().load(value); if (objValue instanceof Map || objValue instanceof List) { if (!complexProperty) { - jsonObject.put(GET_INPUT, input.getName()); + jsonObject.put(GET_INPUT, inputName); prop.setValue(jsonObject.toJSONString()); } else { - Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue; + final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue; createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName); - String json = gson.toJson(mappedToscaTemplate); + final String json = gson.toJson(mappedToscaTemplate); prop.setValue(json); } } else { - jsonObject.put(GET_INPUT, input.getName()); + jsonObject.put(GET_INPUT, inputName); prop.setValue(jsonObject.toJSONString()); } } if (CollectionUtils.isEmpty(prop.getGetInputValues())) { prop.setGetInputValues(new ArrayList<>()); } - List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues(); - GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); + final List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues(); + final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); getInputValueDataDefinition.setInputId(input.getUniqueId()); - getInputValueDataDefinition.setInputName(input.getName()); + getInputValueDataDefinition.setInputName(inputName); getInputValues.add(getInputValueDataDefinition); } @@ -460,8 +460,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties if (result.isLeft()) { modifiedMappedToscaTemplate = (Map) result.left().value(); } else { - log.warn("Map cleanup failed -> " + result.right().value() - .toString()); //continue, don't break operation + log.warn("Map cleanup failed -> {}", result.right().value()); //continue, don't break operation } value = gson.toJson(modifiedMappedToscaTemplate); } @@ -546,11 +545,10 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties boolean isEmpty = true; if (element != null) { if (element instanceof Map) { - if (MapUtils.isEmpty((Map) element)) { - isEmpty = true; - } else { - for (Object key : ((Map) (element)).keySet()) { - Object value = ((Map) (element)).get(key); + final Map map = (Map) element; + if (MapUtils.isNotEmpty(map)) { + for (final Object key : map.keySet()) { + final Object value = map.get(key); isEmpty &= isEmptyNestedMap(value); } } @@ -560,7 +558,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties } return isEmpty; } - //@returns true iff map nested maps are all empty + //@returns true if map nested maps are all empty private class PropertiesDeclarationData { |