diff options
author | MichaelMorris <michael.morris@est.tech> | 2022-08-26 11:00:03 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2022-09-07 13:17:19 +0000 |
commit | 0411615fe4f55fe3463da2576de376c7478fcfb2 (patch) | |
tree | 6e9792f607de443c2d04dde2d54412d0e6a85603 /catalog-be/src/main/java/org | |
parent | 00f293346ed73585faea502c6fc6bac1481f7422 (diff) |
Support TOSCA functions in sub properties
Change-Id: Ibfd95c928bbb10089cfc9749ae4e7b05270e3d68
Issue-ID: SDC-4151
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java | 26 |
1 files changed, 25 insertions, 1 deletions
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<String, ResponseFormat> 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<String> 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<List<ComponentInstanceAttribute>, 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); } |