From 6d65fde29c1859a7099d91ed0e8911bcb1823a38 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Tue, 12 Jan 2021 13:41:59 +0000 Subject: Allow property to take its value from defined input list Issue-ID: SDC-3547 Change-Id: Ic438e8f8943d0f1c656e386611b88b25f879e83b Signed-off-by: KrupaNagabhushan Signed-off-by: andre.schmid --- .../impl/ComponentInstanceBusinessLogic.java | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'catalog-be/src/main/java') 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 8515c5c468..d0c72e566c 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 @@ -73,6 +73,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ForwardingPathUtils; import org.openecomp.sdc.be.impl.ServiceFilterUtils; @@ -1972,6 +1973,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { resultOp = Either.left(updatedProperties); return resultOp; + } catch (final ComponentException e) { + return Either.right(e.getResponseFormat()); } finally { if (resultOp == null || resultOp.isRight()) { janusGraphDao.rollback(); @@ -2169,10 +2172,17 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } innerType = propDef.getType(); } + // Specific Update Logic + String newValue = property.getValue(); + + if (property.getToscaGetFunctionType() != null) { + validateToscaGetFunction(property); + return Either.left(newValue); + } + Either isValid = propertyOperation .validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, allDataTypes); - String newValue = property.getValue(); if (isValid.isRight()) { Boolean res = isValid.right().value(); if (!res) { @@ -2198,6 +2208,31 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { return Either.left(newValue); } + private void validateToscaGetFunction(T property) { + if (property.getToscaGetFunctionType() == ToscaGetFunctionType.GET_INPUT) { + final List getInputValues = property.getGetInputValues(); + if (CollectionUtils.isEmpty(getInputValues)) { + log.debug("No input information provided. Cannot set get_input."); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT); + } + if (getInputValues.size() > 1) { + log.debug("More than one input provided. Cannot set get_input."); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT); + } + final GetInputValueDataDefinition getInputValueDataDefinition = getInputValues.get(0); + + if (!property.getType().equals(getInputValueDataDefinition.getInputType())) { + log.debug("Input type '{}' diverges from the property type '{}'. Cannot set get_input.", + getInputValueDataDefinition.getInputType(), property.getType()); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT); + } + return; + } + + throw new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, + "Tosca function " + property.getToscaGetFunctionType().getToscaGetFunctionName()); + } + private ResponseFormat updateInputOnContainerComponent(ComponentInstanceInput input, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) { StorageOperationStatus status; -- cgit 1.2.3-korg