From 0411615fe4f55fe3463da2576de376c7478fcfb2 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 26 Aug 2022 11:00:03 +0100 Subject: Support TOSCA functions in sub properties Change-Id: Ibfd95c928bbb10089cfc9749ae4e7b05270e3d68 Issue-ID: SDC-4151 Signed-off-by: MichaelMorris --- .../impl/ComponentInstanceBusinessLogic.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 5b15138ad4..684645a7b2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -43,6 +43,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.json.JSONObject; import org.onap.sdc.tosca.datatypes.model.PropertyType; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; @@ -1967,6 +1968,13 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { toscaFunctionValidator.validate(property, containerComponent); property.setValue(property.getToscaFunction().getValue()); } + if (CollectionUtils.isNotEmpty(property.getSubPropertyToscaFunctions())){ + final JSONObject jObject = property.getValue() == null ? new JSONObject() : new JSONObject(property.getValue()); + property.getSubPropertyToscaFunctions().stream().forEach(subToscaFunction -> { + setJsonObjectForSubProperty(jObject, subToscaFunction.getSubPropertyPath(), subToscaFunction.getToscaFunction().getValue()); + }); + property.setValue(jObject.toString()); + } Either updatedPropertyValue = updatePropertyObjectValue(property, containerComponent.getModel()); if (updatedPropertyValue.isRight()) { log.error("Failed to update property object value of property: {}", @@ -2011,6 +2019,22 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType()); } } + + private void setJsonObjectForSubProperty(final JSONObject jObject, final List path, String value) { + if (path.size() == 1) { + if (!value.startsWith("{")) { + value = new StringBuilder("{").append(value).append("}").toString(); + } + final JSONObject jObjectSub = new JSONObject(value); + jObject.put(path.get(0), jObjectSub); + } else { + if (!jObject.has(path.get(0))) { + jObject.put(path.get(0), new JSONObject()); + } + final JSONObject jsonObject = jObject.getJSONObject(path.get(0)); + setJsonObjectForSubProperty(jsonObject, path.subList(1, path.size()), value); + } + } public Either, ResponseFormat> createOrUpdateAttributeValues(final ComponentTypeEnum componentTypeEnum, final String componentId, @@ -2300,7 +2324,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { // Specific Update Logic String newValue = property.getValue(); - if (property.hasToscaFunction()) { + if (property.hasToscaFunction() || CollectionUtils.isNotEmpty(property.getSubPropertyToscaFunctions())) { return Either.left(newValue); } -- cgit 1.2.3-korg