Support import service with yaml tosca function 61/130761/5
authorMichaelMorris <michael.morris@est.tech>
Mon, 5 Sep 2022 17:30:04 +0000 (18:30 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Thu, 8 Sep 2022 10:49:57 +0000 (10:49 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4166
Change-Id: I3c0c3af3a36ccb02fbdd518de8e75175e9a42607

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java

index bf0f1b2..ab43b43 100644 (file)
@@ -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<GetInputValueDataDefinition> 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,