Fix wrongly generated tosca implementation
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / csar / YamlTemplateParsingHandler.java
index a68bbf3..25d5c1f 100644 (file)
@@ -23,6 +23,7 @@
 package org.openecomp.sdc.be.components.csar;
 
 import static java.util.stream.Collectors.toList;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE;
 import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
 import static org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
 import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaListElement;
@@ -62,22 +63,25 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TE
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES;
 
+import com.att.aft.dme2.internal.gson.reflect.TypeToken;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import fj.data.Either;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.regex.Pattern;
+import java.util.UUID;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
@@ -88,13 +92,15 @@ 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;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
@@ -114,10 +120,12 @@ import org.openecomp.sdc.be.model.UploadArtifactInfo;
 import org.openecomp.sdc.be.model.UploadAttributeInfo;
 import org.openecomp.sdc.be.model.UploadCapInfo;
 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadInterfaceInfo;
 import org.openecomp.sdc.be.model.UploadPropInfo;
 import org.openecomp.sdc.be.model.UploadReqInfo;
 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
 import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
+import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
 import org.openecomp.sdc.be.ui.model.OperationUi;
 import org.openecomp.sdc.be.ui.model.PropertyAssignmentUi;
 import org.openecomp.sdc.be.utils.TypeUtils;
@@ -130,22 +138,28 @@ import org.yaml.snakeyaml.parser.ParserException;
 @org.springframework.stereotype.Component
 public class YamlTemplateParsingHandler {
 
-    private static final Pattern propertyValuePattern = Pattern.compile("[ ]*\\{[ ]*(str_replace=|token=|get_property=|concat=|get_attribute=)+");
     private static final int SUB_MAPPING_CAPABILITY_OWNER_NAME_IDX = 0;
     private static final int SUB_MAPPING_CAPABILITY_NAME_IDX = 1;
     private static final Logger log = Logger.getLogger(YamlTemplateParsingHandler.class);
-    private Gson gson = new Gson();
-    private JanusGraphDao janusGraphDao;
-    private GroupTypeBusinessLogic groupTypeBusinessLogic;
-    private AnnotationBusinessLogic annotationBusinessLogic;
-    private PolicyTypeBusinessLogic policyTypeBusinessLogic;
-
-    public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao, GroupTypeBusinessLogic groupTypeBusinessLogic,
-                                      AnnotationBusinessLogic annotationBusinessLogic, PolicyTypeBusinessLogic policyTypeBusinessLogic) {
+    private static final String WITH_ATTRIBUTE = "with attribute '{}': '{}'";
+    private final Gson gson = new Gson();
+    private final JanusGraphDao janusGraphDao;
+    private final GroupTypeBusinessLogic groupTypeBusinessLogic;
+    private final AnnotationBusinessLogic annotationBusinessLogic;
+    private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
+    private final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler;
+
+    public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao,
+                                      GroupTypeBusinessLogic groupTypeBusinessLogic,
+                                      AnnotationBusinessLogic annotationBusinessLogic,
+                                      PolicyTypeBusinessLogic policyTypeBusinessLogic,
+                                      final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler
+    ) {
         this.janusGraphDao = janusGraphDao;
         this.groupTypeBusinessLogic = groupTypeBusinessLogic;
         this.annotationBusinessLogic = annotationBusinessLogic;
         this.policyTypeBusinessLogic = policyTypeBusinessLogic;
+        this.toscaFunctionYamlParsingHandler = toscaFunctionYamlParsingHandler;
     }
 
     public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
@@ -162,7 +176,10 @@ public class YamlTemplateParsingHandler {
             .filter(entry -> entry.getKey().equals(OUTPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
         parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs));
         parsedToscaYamlInfo.setOutputs(getOutputs(mappedTopologyTemplateOutputs));
-        parsedToscaYamlInfo.setInstances(getInstances(mappedToscaTemplate, createdNodesToscaResourceNames));
+        parsedToscaYamlInfo.setInstances(getInstances(
+                mappedToscaTemplate,
+                createdNodesToscaResourceNames
+        ));
         associateRelationshipTemplatesToInstances(parsedToscaYamlInfo.getInstances(), mappedTopologyTemplate);
         parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel()));
         parsedToscaYamlInfo.setPolicies(getPolicies(mappedToscaTemplate, component.getModel()));
@@ -306,31 +323,36 @@ public class YamlTemplateParsingHandler {
         return policyTypeDefinition;
     }
 
-    private List<PropertyDataDefinition> validateFillPolicyProperties(PolicyTypeDefinition policyTypeDefinition,
-                                                                      Map<String, Object> policyTemplateJsonMap) {
-        if (MapUtils.isEmpty(policyTemplateJsonMap) || Objects.isNull(policyTypeDefinition)) {
+    private List<PropertyDataDefinition> validateFillPolicyProperties(final PolicyTypeDefinition policyTypeDefinition,
+                                                                      final Map<String, Object> policyTemplateJsonMap) {
+        if (policyTypeDefinition == null || CollectionUtils.isEmpty(policyTypeDefinition.getProperties())
+            || MapUtils.isEmpty(policyTemplateJsonMap)) {
             return Collections.emptyList();
         }
-        List<PropertyDataDefinition> propertyDataDefinitionList = new ArrayList<>();
-        Map<String, Object> propertiesMap = (Map<String, Object>) policyTemplateJsonMap.get(PROPERTIES.getElementName());
-        if (MapUtils.isEmpty(propertiesMap)) {
+        final Map<String, Object> propertiesJsonMap = (Map<String, Object>) policyTemplateJsonMap.get(PROPERTIES.getElementName());
+        if (MapUtils.isEmpty(propertiesJsonMap)) {
             return Collections.emptyList();
         }
-        if (CollectionUtils.isNotEmpty(policyTypeDefinition.getProperties())) {
-            propertyDataDefinitionList = policyTypeDefinition.getProperties().stream()
-                .map(propertyDefinition -> setPropertyValue(propertiesMap, propertyDefinition)).collect(Collectors.toList());
-        }
-        return propertyDataDefinitionList;
-    }
-
-    private PropertyDataDefinition setPropertyValue(Map<String, Object> propertiesMap, PropertyDataDefinition srcPropertyDataDefinition) {
-        PropertyDataDefinition newPropertyDef = new PropertyDataDefinition(srcPropertyDataDefinition);
-        String propertyName = newPropertyDef.getName();
-        if (Objects.nonNull(propertiesMap.get(propertyName))) {
-            Object propValue = propertiesMap.get(propertyName);
-            newPropertyDef.setValue(PropertiesUtils.trimQuotes(gson.toJson(propValue)));
-        }
-        return newPropertyDef;
+        return propertiesJsonMap.entrySet().stream()
+            .map(propertyJson -> {
+                final PropertyDefinition originalProperty =
+                    policyTypeDefinition.getProperties().stream()
+                        .filter(propertyDefinition -> propertyDefinition.getName().equals(propertyJson.getKey()))
+                        .findFirst()
+                        .orElse(null);
+                if (originalProperty == null) {
+                    return null;
+                }
+                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.setGetInputValues(uploadPropInfo.getGet_input());
+                propertyDefinition.setDescription(uploadPropInfo.getDescription());
+                return propertyDefinition;
+            })
+            .filter(Objects::nonNull)
+            .collect(Collectors.toList());
     }
 
     private Map<PolicyTargetType, List<String>> validateFillPolicyTargets(Map<String, Object> policyTemplateJson) {
@@ -342,20 +364,34 @@ public class YamlTemplateParsingHandler {
         return targets;
     }
 
-    private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson,
-                                                                  Map<String, String> createdNodesToscaResourceNames) {
-        Map<String, Object> nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES).left().on(err -> new HashMap<>());
+    private Map<String, UploadComponentInstanceInfo> getInstances(
+            Map<String, Object> toscaJson,
+            Map<String, String> createdNodesToscaResourceNames
+    ) {
+        Map<String, Object> nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES)
+                .left().on(err -> new HashMap<>());
         if (nodeTemplates.isEmpty()) {
             return Collections.emptyMap();
         }
-        return getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemplates);
+        return getInstances(
+                toscaJson,
+                createdNodesToscaResourceNames,
+                nodeTemplates
+        );
     }
 
-    private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames,
-                                                                  Map<String, Object> nodeTemplates) {
+    private Map<String, UploadComponentInstanceInfo> getInstances(
+            Map<String, Object> toscaJson,
+            Map<String, String> createdNodesToscaResourceNames,
+            Map<String, Object> nodeTemplates
+    ) {
         Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson);
         return nodeTemplates.entrySet().stream()
-            .map(node -> buildModuleComponentInstanceInfo(node, substitutionMappings, createdNodesToscaResourceNames))
+            .map(node -> buildModuleComponentInstanceInfo(
+                    node,
+                    substitutionMappings,
+                    createdNodesToscaResourceNames
+            ))
             .collect(Collectors.toMap(UploadComponentInstanceInfo::getName, i -> i));
     }
 
@@ -415,10 +451,7 @@ public class YamlTemplateParsingHandler {
         if (MapUtils.isEmpty(operationToscaMap) || !operationToscaMap.containsKey(IMPLEMENTATION.getElementName())) {
             return Optional.empty();
         }
-        final Map<String, Object> implementationToscaMap = (Map<String, Object>) operationToscaMap.get(IMPLEMENTATION.getElementName());
-        return Optional.ofNullable(
-            implementationToscaMap.computeIfPresent("toscaPresentation", (key, value) -> ((Map<String, Object>) value).get(NAME.getName()))
-        );
+        return Optional.ofNullable(operationToscaMap.get(IMPLEMENTATION.getElementName()));
     }
 
     private List<PropertyAssignmentUi> getOperationsInputs(final Map<String, Object> operationToscaMap) {
@@ -473,8 +506,8 @@ public class YamlTemplateParsingHandler {
                 .collect(Collectors.toMap(GroupDefinition::getName, g -> g));
             Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson);
             if (capabilitiesSubstitutionMappingsExist(substitutionMappings)) {
-                groups.entrySet().forEach(entry -> updateCapabilitiesNames(entry.getValue(),
-                    getNamesToUpdate(entry.getKey(), (Map<String, List<String>>) substitutionMappings.get(CAPABILITIES.getElementName()))));
+                groups.forEach((key, value) -> updateCapabilitiesNames(value,
+                    getNamesToUpdate(key, (Map<String, List<String>>) substitutionMappings.get(CAPABILITIES.getElementName()))));
             }
             return groups;
         }
@@ -555,28 +588,21 @@ public class YamlTemplateParsingHandler {
         }
     }
 
-    private void mergeGroupProperties(GroupDefinition groupInfo, Map<String, Object> parsedProperties) {
-        if (CollectionUtils.isNotEmpty(groupInfo.getProperties())) {
-            validateGroupProperties(parsedProperties, groupInfo);
-            groupInfo.getProperties().forEach(p -> mergeGroupProperty(p, parsedProperties));
-        }
-    }
-
-    private void mergeGroupProperty(PropertyDataDefinition property, Map<String, Object> parsedProperties) {
-        if (parsedProperties.containsKey(property.getName())) {
-            Object propValue = parsedProperties.get(property.getName());
-            if (valueNotContainsPattern(propertyValuePattern, propValue)) {
-                setPropertyValueAndGetInputsValues(property, propValue);
-            }
+    private void mergeGroupProperties(final GroupDefinition groupDefinition, final Map<String, Object> parsedProperties) {
+        if (CollectionUtils.isEmpty(groupDefinition.getProperties())) {
+            return;
         }
+        validateGroupProperties(parsedProperties, groupDefinition);
+        groupDefinition.getProperties().stream()
+            .filter(property -> parsedProperties.containsKey(property.getName()))
+            .forEach(property -> mergeGroupProperty(property, parsedProperties.get(property.getName())));
     }
 
-    private void setPropertyValueAndGetInputsValues(PropertyDataDefinition property, Object propValue) {
-        if (propValue != null) {
-            UploadPropInfo uploadPropInfo = buildProperty(property.getName(), propValue);
-            property.setValue(convertPropertyValue(ToscaPropertyType.isValidType(property.getType()), uploadPropInfo.getValue()));
-            property.setGetInputValues(uploadPropInfo.getGet_input());
-        }
+    private void mergeGroupProperty(final PropertyDataDefinition property, final Object propertyYaml) {
+        final UploadPropInfo uploadPropInfo = buildProperty(property.getName(), propertyYaml);
+        property.setToscaFunction(uploadPropInfo.getToscaFunction());
+        property.setValue(convertPropertyValue(ToscaPropertyType.isValidType(property.getType()), uploadPropInfo.getValue()));
+        property.setGetInputValues(uploadPropInfo.getGet_input());
     }
 
     private String convertPropertyValue(ToscaPropertyType type, Object value) {
@@ -675,7 +701,7 @@ public class YamlTemplateParsingHandler {
     }
 
     private void validateGroupProperties(Map<String, Object> parsedProperties, GroupDefinition groupInfo) {
-        List<String> parsedPropertiesNames = parsedProperties.entrySet().stream().map(Map.Entry::getKey).collect(toList());
+        List<String> parsedPropertiesNames = new ArrayList<>(parsedProperties.keySet());
         validateProperties(groupInfo.getProperties().stream().map(PropertyDataDefinition::getName).collect(toList()), parsedPropertiesNames,
             ActionStatus.GROUP_PROPERTY_NOT_FOUND, groupInfo.getName(), groupInfo.getType());
     }
@@ -741,9 +767,11 @@ public class YamlTemplateParsingHandler {
     }
 
     @SuppressWarnings("unchecked")
-    private UploadComponentInstanceInfo buildModuleComponentInstanceInfo(Map.Entry<String, Object> nodeTemplateJsonEntry,
-                                                                         Map<String, Object> substitutionMappings,
-                                                                         Map<String, String> createdNodesToscaResourceNames) {
+    private UploadComponentInstanceInfo buildModuleComponentInstanceInfo(
+            Map.Entry<String, Object> nodeTemplateJsonEntry,
+            Map<String, Object> substitutionMappings,
+            Map<String, String> createdNodesToscaResourceNames
+    ) {
         UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
         nodeTemplateInfo.setName(nodeTemplateJsonEntry.getKey());
         try {
@@ -758,6 +786,7 @@ public class YamlTemplateParsingHandler {
                 setArtifacts(nodeTemplateInfo, nodeTemplateJsonMap);
                 updateProperties(nodeTemplateInfo, nodeTemplateJsonMap);
                 updateAttributes(nodeTemplateInfo, nodeTemplateJsonMap);
+                updateInterfaces(nodeTemplateInfo, nodeTemplateJsonMap);
                 setDirectives(nodeTemplateInfo, nodeTemplateJsonMap);
                 setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap);
                 setSubstitutions(substitutionMappings, nodeTemplateInfo);
@@ -788,7 +817,8 @@ public class YamlTemplateParsingHandler {
 
     private void updateProperties(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
         if (nodeTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
-            Map<String, List<UploadPropInfo>> properties = buildPropModuleFromYaml(nodeTemplateJsonMap);
+            Map<String, List<UploadPropInfo>> properties =
+                buildPropModuleFromYaml((Map<String, Object>) nodeTemplateJsonMap.get(PROPERTIES.getElementName()));
             if (!properties.isEmpty()) {
                 nodeTemplateInfo.setProperties(properties);
             }
@@ -804,6 +834,20 @@ public class YamlTemplateParsingHandler {
         }
     }
 
+    private void updateInterfaces(
+            UploadComponentInstanceInfo nodeTemplateInfo,
+            Map<String, Object> nodeTemplateJsonMap
+    ){
+        if (nodeTemplateJsonMap.containsKey(INTERFACES.getElementName())) {
+            Map<String, UploadInterfaceInfo> interfaces = buildInterfacesModuleFromYaml(
+                    nodeTemplateJsonMap
+            );
+            if (!interfaces.isEmpty()) {
+                nodeTemplateInfo.setInterfaces(interfaces);
+            }
+        }
+    }
+
     private void setCapabilities(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
         if (nodeTemplateJsonMap.containsKey(CAPABILITIES.getElementName())) {
             Map<String, List<UploadCapInfo>> eitherCapRes = createCapModuleFromYaml(nodeTemplateJsonMap);
@@ -942,7 +986,8 @@ public class YamlTemplateParsingHandler {
             artifactTemplateInfo.setFile((String) nodeTemplateJsonMap.get(FILE.getElementName()));
         }
         if (nodeTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
-            Map<String, List<UploadPropInfo>> props = buildPropModuleFromYaml(nodeTemplateJsonMap);
+            Map<String, List<UploadPropInfo>> props =
+                buildPropModuleFromYaml((Map<String, Object>) nodeTemplateJsonMap.get(PROPERTIES.getElementName()));
             if (!props.isEmpty()) {
                 List<UploadPropInfo> properties = props.values().stream().flatMap(Collection::stream).collect(toList());
                 artifactTemplateInfo.setProperties(properties);
@@ -1011,7 +1056,8 @@ public class YamlTemplateParsingHandler {
             }
         }
         if (nodeTemplateJsonMap.containsKey(PROPERTIES.getElementName())) {
-            Map<String, List<UploadPropInfo>> props = buildPropModuleFromYaml(nodeTemplateJsonMap);
+            Map<String, List<UploadPropInfo>> props =
+                buildPropModuleFromYaml((Map<String, Object>) nodeTemplateJsonMap.get(PROPERTIES.getElementName()));
             if (!props.isEmpty()) {
                 List<UploadPropInfo> properties = props.values().stream().flatMap(Collection::stream).collect(toList());
                 capTemplateInfo.setProperties(properties);
@@ -1043,7 +1089,8 @@ public class YamlTemplateParsingHandler {
         return regTemplateInfo;
     }
 
-    private Map<String, UploadAttributeInfo> buildAttributeModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
+    private Map<String, UploadAttributeInfo> buildAttributeModuleFromYaml(
+            Map<String, Object> nodeTemplateJsonMap) {
         Map<String, UploadAttributeInfo> moduleAttribute = new HashMap<>();
         Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(nodeTemplateJsonMap, ATTRIBUTES);
         if (toscaAttributes.isLeft()) {
@@ -1063,18 +1110,24 @@ public class YamlTemplateParsingHandler {
         return attributeDef;
     }
 
-    private Map<String, List<UploadPropInfo>> buildPropModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
-        Map<String, List<UploadPropInfo>> moduleProp = new HashMap<>();
-        Either<Map<String, Object>, ResultStatusEnum> toscaProperties = findFirstToscaMapElement(nodeTemplateJsonMap, PROPERTIES);
-        if (toscaProperties.isLeft()) {
-            Map<String, Object> jsonProperties = toscaProperties.left().value();
-            for (Map.Entry<String, Object> jsonPropObj : jsonProperties.entrySet()) {
-                if (valueNotContainsPattern(propertyValuePattern, jsonPropObj.getValue())) {
-                    addProperty(moduleProp, jsonPropObj);
-                }
+    private Map<String, List<UploadPropInfo>> buildPropModuleFromYaml(final Map<String, Object> propertyMap) {
+        final Map<String, List<UploadPropInfo>> moduleProp = new HashMap<>();
+        propertyMap.entrySet().forEach(propertyMapEntry -> addProperty(moduleProp, propertyMapEntry));
+        return moduleProp;
+    }
+
+    private Map<String, UploadInterfaceInfo> buildInterfacesModuleFromYaml(
+            Map<String, Object> nodeTemplateJsonMap
+    ) {
+        Map<String, UploadInterfaceInfo> moduleInterfaces = new HashMap<>();
+        Either<Map<String, Object>, ResultStatusEnum> toscaInterfaces = findFirstToscaMapElement(nodeTemplateJsonMap, INTERFACES);
+        if (toscaInterfaces.isLeft()) {
+            Map<String, Object> jsonInterfaces = toscaInterfaces.left().value();
+            for (Map.Entry<String, Object> jsonInterfacesObj : jsonInterfaces.entrySet()) {
+                addInterfaces(moduleInterfaces, jsonInterfacesObj);
             }
         }
-        return moduleProp;
+        return moduleInterfaces;
     }
 
     private void addProperty(Map<String, List<UploadPropInfo>> moduleProp, Map.Entry<String, Object> jsonPropObj) {
@@ -1088,37 +1141,181 @@ public class YamlTemplateParsingHandler {
         }
     }
 
+    private void addInterfaces(Map<String, UploadInterfaceInfo> moduleInterface, Map.Entry<String, Object> jsonPropObj) {
+        UploadInterfaceInfo interfaceInfo = buildInterface(jsonPropObj.getKey(), jsonPropObj.getValue());
+        moduleInterface.put(jsonPropObj.getKey(), interfaceInfo);
+    }
+
     @SuppressWarnings("unchecked")
-    private UploadPropInfo buildProperty(String propName, Object propValue) {
-        UploadPropInfo propertyDef = new UploadPropInfo();
-        propertyDef.setValue(propValue);
+    private UploadPropInfo buildProperty(String propName, Object propValueObj) {
+        final var propertyDef = new UploadPropInfo();
+        propertyDef.setValue(propValueObj);
         propertyDef.setName(propName);
-        if (propValue instanceof Map) {
-            if (((Map<String, Object>) propValue).containsKey(TYPE.getElementName())) {
-                propertyDef.setType(((Map<String, Object>) propValue).get(TYPE.getElementName()).toString());
+        if (propValueObj instanceof Map) {
+            final Map<String, Object> propValueMap = (Map<String, Object>) propValueObj;
+            if (propValueMap.containsKey(TYPE.getElementName())) {
+                propertyDef.setType(propValueMap.get(TYPE.getElementName()).toString());
+            }
+            if (containsGetInput(propValueObj)) {
+                fillInputRecursively(propName, propValueMap, propertyDef);
             }
-            if (containsGetInput(propValue)) {
-                fillInputRecursively(propName, (Map<String, Object>) propValue, propertyDef);
+            if (toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(propValueObj)) {
+                toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue(propValueMap).ifPresent(propertyDef::setToscaFunction);
             }
-            if (((Map<String, Object>) propValue).containsKey(DESCRIPTION.getElementName())) {
-                propertyDef.setDescription(((Map<String, Object>) propValue).get(DESCRIPTION.getElementName()).toString());
+            if (propValueMap.containsKey(DESCRIPTION.getElementName())) {
+                propertyDef.setDescription((propValueMap).get(DESCRIPTION.getElementName()).toString());
             }
-            if (((Map<String, Object>) propValue).containsKey(DEFAULT_VALUE.getElementName())) {
-                propertyDef.setValue(((Map<String, Object>) propValue).get(DEFAULT_VALUE.getElementName()));
+            if (propValueMap.containsKey(DEFAULT_VALUE.getElementName())) {
+                propertyDef.setValue(propValueMap.get(DEFAULT_VALUE.getElementName()));
             }
-            if (((Map<String, Object>) propValue).containsKey(IS_PASSWORD.getElementName())) {
-                propertyDef.setPassword(Boolean.getBoolean(((Map<String, Object>) propValue).get(IS_PASSWORD.getElementName()).toString()));
+            if (propValueMap.containsKey(IS_PASSWORD.getElementName())) {
+                propertyDef.setPassword(Boolean.getBoolean(propValueMap.get(IS_PASSWORD.getElementName()).toString()));
             } else {
-                propertyDef.setValue(propValue);
+                propertyDef.setValue(propValueObj);
             }
-        } else if (propValue instanceof List) {
-            List<Object> propValueList = (List<Object>) propValue;
-            fillInputsListRecursively(propertyDef, propValueList);
-            propertyDef.setValue(propValue);
+        } else if (propValueObj instanceof List) {
+            fillInputsListRecursively(propertyDef, (List<Object>) propValueObj);
+            propertyDef.setValue(propValueObj);
         }
         return propertyDef;
     }
 
+    private UploadInterfaceInfo buildInterface(String interfaceName, Object interfaceValue) {
+        UploadInterfaceInfo interfaceDef = new UploadInterfaceInfo();
+        interfaceDef.setValue(interfaceValue);
+        interfaceDef.setName(interfaceName);
+        interfaceDef.setKey(interfaceName);
+        Map<String, OperationDataDefinition> operations = new HashMap<>();
+        if (interfaceValue instanceof Map) {
+            Map<String, Object> operationsMap = (Map<String, Object>) interfaceValue;
+            for (Map.Entry<String, Object> operationEntry : operationsMap.entrySet()) {
+                OperationDataDefinition operationDef = new OperationDataDefinition();
+                operationDef.setName(operationEntry.getKey());
+                Map<String, Object> operationValue = (Map<String, Object>) operationEntry.getValue();
+                if (operationValue.containsKey(DESCRIPTION.getElementName())) {
+                    operationDef.setDescription(operationValue.get(DESCRIPTION.getElementName()).toString());
+                }
+                operationDef.setImplementation(handleOperationImplementation(operationValue).orElse(new ArtifactDataDefinition()));
+                if (operationValue.containsKey(INPUTS.getElementName())) {
+                    final Map<String, Object> interfaceInputs = (Map<String, Object>) operationValue.get(INPUTS.getElementName());
+                    operationDef.setInputs(handleInterfaceOperationInputs(interfaceInputs));
+                }
+                operations.put(operationEntry.getKey(), operationDef);
+            }
+            interfaceDef.setOperations(operations);
+            if (operationsMap.containsKey(TYPE.getElementName())) {
+                interfaceDef.setType(((Map<String, Object>) interfaceValue).get(TYPE.getElementName()).toString());
+            }
+        }
+        return interfaceDef;
+    }
+
+    private ListDataDefinition<OperationInputDefinition> handleInterfaceOperationInputs(final Map<String, Object> interfaceInputs) {
+        final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+        for (final Entry<String, Object> interfaceInput : interfaceInputs.entrySet()) {
+            final OperationInputDefinition operationInput = new OperationInputDefinition();
+            operationInput.setUniqueId(UUID.randomUUID().toString());
+            operationInput.setInputId(operationInput.getUniqueId());
+            operationInput.setName(interfaceInput.getKey());
+            handleInputToscaDefinition(interfaceInput.getKey(), interfaceInput.getValue(), operationInput);
+            inputs.add(operationInput);
+        }
+        return inputs;
+    }
+
+    private void handleInputToscaDefinition(
+        final String inputName,
+        final Object value,
+        final OperationInputDefinition operationInput
+    ) {
+        if (value instanceof Map) {
+            log.debug("Creating interface operation input '{}'", inputName);
+            Gson gson = new Gson();
+            Type type = new TypeToken<LinkedHashMap<String, Object>>(){}.getType();
+            String stringValue = gson.toJson(value, type);
+            operationInput.setValue(stringValue);
+        }
+        if (value instanceof String) {
+            final String stringValue = (String) value;
+            operationInput.setDefaultValue(stringValue);
+            operationInput.setToscaDefaultValue(stringValue);
+            operationInput.setValue(stringValue);
+        }
+    }
+
+    private Optional<ArtifactDataDefinition> handleOperationImplementation(
+        final Map<String, Object> operationDefinitionMap
+    ) {
+        if (!operationDefinitionMap.containsKey(IMPLEMENTATION.getElementName())) {
+            return Optional.empty();
+        }
+        final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+        if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map &&
+                ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) {
+            
+            final Object primary = ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary");
+            if(primary instanceof Map) {
+                Map<String, Object> implDetails = (Map) primary;
+
+                if (implDetails.get("file") != null) {
+                    final String file = implDetails.get("file").toString();
+                    artifactDataDefinition.setArtifactName(generateArtifactName(file));
+                }
+                if (implDetails.get("type") != null) {
+                    artifactDataDefinition.setArtifactType(implDetails.get("type").toString());
+                }
+                if (implDetails.get("artifact_version") != null) {
+                    artifactDataDefinition.setArtifactVersion(implDetails.get("artifact_version").toString());
+                }
+
+                if(implDetails.get("properties") instanceof Map) {
+                    List<PropertyDataDefinition> operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties();
+                    Map<String, Object> properties = (Map<String, Object>) implDetails.get("properties");
+                    properties.forEach((k,v) -> {
+                        ToscaPropertyType type = getTypeFromObject(v);
+                        if (type != null) {
+                            PropertyDataDefinition propertyDef = new PropertyDataDefinition();
+                            propertyDef.setName(k);
+                            propertyDef.setValue(v.toString());
+                            artifactDataDefinition.addProperty(propertyDef);
+                        }
+                    });
+                }
+            } else {
+                artifactDataDefinition.setArtifactName(generateArtifactName(primary.toString()));
+            }
+        }
+        if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof String) {
+            final String implementation = (String) operationDefinitionMap.get(IMPLEMENTATION.getElementName());
+            artifactDataDefinition.setArtifactName(generateArtifactName(implementation));
+        }
+        return Optional.of(artifactDataDefinition);
+    }
+
+    private String generateArtifactName(final String name) {
+        if (OperationArtifactUtil.artifactNameIsALiteralValue(name)) {
+            return name;
+        } else {
+            return QUOTE + name + QUOTE;
+        }
+    }
+
+    private ToscaPropertyType getTypeFromObject(final Object value) {
+        if (value instanceof String) {
+            return ToscaPropertyType.STRING;
+        }
+        if (value instanceof Integer) {
+            return ToscaPropertyType.INTEGER;
+        }
+        if (value instanceof Boolean) {
+            return ToscaPropertyType.BOOLEAN;
+        }
+        if (value instanceof Float || value instanceof Double) {
+            return ToscaPropertyType.FLOAT;
+        }
+        return null;
+    }
+
     @SuppressWarnings("unchecked")
     private boolean containsGetInput(Object propValue) {
         return ((Map<String, Object>) propValue).containsKey(GET_INPUT.getElementName()) || ImportUtils.containsGetInput(propValue);
@@ -1217,10 +1414,6 @@ public class YamlTemplateParsingHandler {
         }
     }
 
-    private boolean valueNotContainsPattern(Pattern pattern, Object propValue) {
-        return propValue == null || !pattern.matcher(propValue.toString()).find();
-    }
-
     private Object failIfNotTopologyTemplate(String fileName) {
         janusGraphDao.rollback();
         throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);