From: MichaelMorris Date: Mon, 5 Sep 2022 17:30:04 +0000 (+0100) Subject: Support import service with yaml tosca function X-Git-Tag: 1.11.8~4 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=c0c2637f201f488a74cb1916f05eece0cc207e9d;p=sdc.git Support import service with yaml tosca function Signed-off-by: MichaelMorris Issue-ID: SDC-4166 Change-Id: I3c0c3af3a36ccb02fbdd518de8e75175e9a42607 --- diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index bf0f1b2812..ab43b4329e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -68,6 +68,7 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; @@ -1893,7 +1894,19 @@ public class ServiceImportBusinessLogic { final var property = new ComponentInstanceProperty(curPropertyDef, value, null); String validatePropValue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); property.setValue(validatePropValue); - property.setToscaFunction(propertyInfo.getToscaFunction()); + + if (tryHandlingAsYamlToscaFunction(validatePropValue, value, propertyInfo)) { + try { + final Object yamlValue = new Yaml().loadAs(value, Object.class); + CustomYamlFunction toscaFunction = new CustomYamlFunction(); + toscaFunction.setYamlValue(yamlValue); + property.setToscaFunction(toscaFunction); + } catch (Exception exception) { + log.info("Cannot create YAML value for {}", propName); + } + } else { + property.setToscaFunction(propertyInfo.getToscaFunction()); + } if (!getInputs.isEmpty()) { final List getInputValues = new ArrayList<>(); for (final GetInputValueDataDefinition getInput : getInputs) { @@ -1927,6 +1940,10 @@ public class ServiceImportBusinessLogic { instProperties.put(currentCompInstance.getUniqueId(), instPropList); return componentsUtils.getResponseFormat(ActionStatus.OK); } + + private boolean tryHandlingAsYamlToscaFunction(String validatePropValue, String value, UploadPropInfo propertyInfo) { + return StringUtils.isEmpty(validatePropValue) && StringUtils.isNotEmpty(value) && propertyInfo.getToscaFunction() == null; + } protected ResponseFormat addInterfaceValuesToRi( UploadComponentInstanceInfo uploadComponentInstanceInfo,