private Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, PROPERTYOWNER propertiesOwner,
List<ComponentInstancePropInput> propsToDeclare) {
- PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(),
+ PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propertiesOwner,
propsToDeclare);
return updatePropertiesValues(component, propertiesOwner.getUniqueId(), policyProperties.getPropertiesToUpdate()).left()
.map(updatePropsRes -> policyProperties.getPoliciesToCreate());
.map(updatePropsRes -> inputsProperties.getInputsToCreate());
}
- private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, List<ComponentInstancePropInput> propsToDeclare) {
+ private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner,
+ List<ComponentInstancePropInput> propsToDeclare) {
List<PROPERTYTYPE> declaredProperties = new ArrayList<>();
List<PolicyDefinition> policies = new ArrayList<>();
propsToDeclare.forEach(property -> policies.add(declarePropertyPolicy(componentId, declaredProperties, property)));
if (propertyCapability.isPresent()) {
String capName = propertyCapability.get().getName();
if (capName.contains(".")) {
- capName = capName.replace(".", UNDERSCORE);
+ capName = capName.replaceAll("\\.", UNDERSCORE);
}
generatedInputPrefix =
generatedInputPrefix == null || generatedInputPrefix.isEmpty() ? capName : generatedInputPrefix + UNDERSCORE + capName;
input.setInputPath(propertiesName);
input.setInstanceUniqueId(propertiesOwner.getUniqueId());
input.setPropertyId(propInput.getUniqueId());
- if (Objects.isNull(input.getSubPropertyInputPath()) || (StringUtils.isNotEmpty(propertiesName) && input.getSubPropertyInputPath()
+ if (Objects.isNull(input.getSubPropertyInputPath()) || (Objects.nonNull(propertiesName) && input.getSubPropertyInputPath()
.substring(input.getSubPropertyInputPath().lastIndexOf('#')).equals(propertiesName.substring(propertiesName.lastIndexOf('#'))))) {
input.setParentPropertyType(propInput.getType());
input.setSubPropertyInputPath(propertiesName);
}
- changePropertyValueToGetInputValue(parsedPropNames, input, prop, complexProperty);
+ changePropertyValueToGetInputValue(inputName, parsedPropNames, input, prop, complexProperty);
if (prop instanceof IComponentInstanceConnectedElement) {
((IComponentInstanceConnectedElement) prop).setComponentInstanceId(propertiesOwner.getUniqueId());
((IComponentInstanceConnectedElement) prop).setComponentInstanceName(propertiesOwner.getName());
return input;
}
- private void changePropertyValueToGetInputValue(String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
+ private void changePropertyValueToGetInputValue(String inputName, String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
boolean complexProperty) {
JSONObject jsonObject = new JSONObject();
- final String value = prop.getValue();
- final String inputName = input.getName();
+ String value = prop.getValue();
if (value == null || value.isEmpty()) {
if (complexProperty) {
jsonObject = createJSONValueForProperty(parsedPropNames.length - 1, parsedPropNames, jsonObject, inputName);
prop.setValue(jsonObject.toJSONString());
} else {
- jsonObject.put(GET_INPUT, inputName);
+ jsonObject.put(GET_INPUT, input.getName());
prop.setValue(jsonObject.toJSONString());
}
} else {
- final Object objValue = new Yaml().load(value);
+ Object objValue = new Yaml().load(value);
if (objValue instanceof Map || objValue instanceof List) {
if (!complexProperty) {
- jsonObject.put(GET_INPUT, inputName);
+ jsonObject.put(GET_INPUT, input.getName());
prop.setValue(jsonObject.toJSONString());
} else {
- final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName);
- final String json = gson.toJson(mappedToscaTemplate);
+ String json = gson.toJson(mappedToscaTemplate);
prop.setValue(json);
}
} else {
- jsonObject.put(GET_INPUT, inputName);
+ jsonObject.put(GET_INPUT, input.getName());
prop.setValue(jsonObject.toJSONString());
}
}
if (CollectionUtils.isEmpty(prop.getGetInputValues())) {
prop.setGetInputValues(new ArrayList<>());
}
- final List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
- final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+ List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
+ GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
getInputValueDataDefinition.setInputId(input.getUniqueId());
- getInputValueDataDefinition.setInputName(inputName);
+ getInputValueDataDefinition.setInputName(input.getName());
getInputValues.add(getInputValueDataDefinition);
}
if (result.isLeft()) {
modifiedMappedToscaTemplate = (Map) result.left().value();
} else {
- log.warn("Map cleanup failed -> {}", result.right().value()); //continue, don't break operation
+ log.warn("Map cleanup failed -> " + result.right().value()
+ .toString()); //continue, don't break operation
}
value = gson.toJson(modifiedMappedToscaTemplate);
}
boolean isEmpty = true;
if (element != null) {
if (element instanceof Map) {
- final Map map = (Map) element;
- if (MapUtils.isNotEmpty(map)) {
- for (final Object key : map.keySet()) {
- final Object value = map.get(key);
+ if (MapUtils.isEmpty((Map) element)) {
+ isEmpty = true;
+ } else {
+ for (Object key : ((Map) (element)).keySet()) {
+ Object value = ((Map) (element)).get(key);
isEmpty &= isEmptyNestedMap(value);
}
}
}
return isEmpty;
}
- //@returns true if map nested maps are all empty
+ //@returns true iff map nested maps are all empty
private class PropertiesDeclarationData {