Allign properties import during service import
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / csar / YamlTemplateParsingHandler.java
index b57e2cb..e9d5c02 100644 (file)
@@ -91,6 +91,7 @@ import org.openecomp.sdc.be.components.impl.ImportUtils;
 import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
 import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.utils.PropertiesUtils;
 import org.openecomp.sdc.be.config.BeEcompErrorManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
@@ -195,6 +196,9 @@ public class YamlTemplateParsingHandler {
                 parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml)));
                 parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
             }
+            if (substitutionMappings.get("properties") != null) {
+                parsedToscaYamlInfo.setSubstitutionMappingProperties((Map<String, List<String>>) substitutionMappings.get("properties"));
+            }
             parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) substitutionMappings.get(NODE_TYPE.getElementName()));
         }
         log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName);
@@ -367,11 +371,15 @@ public class YamlTemplateParsingHandler {
                 }
                 final UploadPropInfo uploadPropInfo = buildProperty(propertyJson.getKey(), propertyJson.getValue());
                 final PropertyDefinition propertyDefinition = new PropertyDefinition(originalProperty);
-                propertyDefinition.setValue(gson.toJson(uploadPropInfo.getValue()));
                 propertyDefinition.setToscaFunction(uploadPropInfo.getToscaFunction());
                 propertyDefinition.setSubPropertyToscaFunctions(uploadPropInfo.getSubPropertyToscaFunctions());
                 propertyDefinition.setGetInputValues(uploadPropInfo.getGet_input());
                 propertyDefinition.setDescription(uploadPropInfo.getDescription());
+                String propertyValue = gson.toJson(uploadPropInfo.getValue());
+                if (!propertyDefinition.isToscaFunction()) {
+                    propertyValue = PropertiesUtils.trimQuotes(propertyValue);
+                }
+                propertyDefinition.setValue(propertyValue);
                 return propertyDefinition;
             })
             .filter(Objects::nonNull)
@@ -1023,21 +1031,12 @@ public class YamlTemplateParsingHandler {
     @SuppressWarnings("unchecked")
     private Map<String, List<UploadCapInfo>> createCapModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
         Map<String, List<UploadCapInfo>> moduleCap = new HashMap<>();
-        Either<List<Object>, ResultStatusEnum> capabilitiesListRes = findFirstToscaListElement(nodeTemplateJsonMap, CAPABILITIES);
-        if (capabilitiesListRes.isLeft()) {
-            for (Object jsonCapObj : capabilitiesListRes.left().value()) {
-                String key = ((Map<String, Object>) jsonCapObj).keySet().iterator().next();
-                Object capJson = ((Map<String, Object>) jsonCapObj).get(key);
-                addModuleNodeTemplateCap(moduleCap, capJson, key);
-            }
-        } else {
-            Either<Map<String, Object>, ResultStatusEnum> capabilitiesMapRes = findFirstToscaMapElement(nodeTemplateJsonMap, CAPABILITIES);
-            if (capabilitiesMapRes.isLeft()) {
-                for (Map.Entry<String, Object> entry : capabilitiesMapRes.left().value().entrySet()) {
-                    String capName = entry.getKey();
-                    Object capJson = entry.getValue();
-                    addModuleNodeTemplateCap(moduleCap, capJson, capName);
-                }
+        Map<String, Object> capabilities = (Map<String, Object>) nodeTemplateJsonMap.get(CAPABILITIES.getElementName());
+        if (MapUtils.isNotEmpty(capabilities)) {
+            for (Map.Entry<String, Object> entry : capabilities.entrySet()) {
+                String capName = entry.getKey();
+                Object capJson = entry.getValue();
+                addModuleNodeTemplateCap(moduleCap, capJson, capName);
             }
         }
         return moduleCap;
@@ -1378,9 +1377,21 @@ public class YamlTemplateParsingHandler {
 
     @SuppressWarnings("unchecked")
     private void fillInputsListRecursively(UploadPropInfo propertyDef, List<Object> propValueList) {
+        int index = 0;
         for (Object objValue : propValueList) {
             if (objValue instanceof Map) {
                 Map<String, Object> objMap = (Map<String, Object>) objValue;
+                Map<String, Object> propValueMap = new HashMap<String, Object>();
+                propValueMap.put(String.valueOf(index),objValue);
+                final Collection<SubPropertyToscaFunction> subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>());
+                if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) {
+                    Collection<SubPropertyToscaFunction> existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions();
+                    if (existingSubPropertyToscaFunctions == null) {
+                        propertyDef.setSubPropertyToscaFunctions(subPropertyToscaFunctions);
+                    } else {
+                        propertyDef.getSubPropertyToscaFunctions().addAll(subPropertyToscaFunctions);
+                    }
+                }
                 if (objMap.containsKey(GET_INPUT.getElementName())) {
                     fillInputRecursively(propertyDef.getName(), objMap, propertyDef);
                 } else {
@@ -1391,6 +1402,7 @@ public class YamlTemplateParsingHandler {
                 List<Object> propSubValueList = (List<Object>) objValue;
                 fillInputsListRecursively(propertyDef, propSubValueList);
             }
+            index++;
         }
     }