X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fcsar%2FYamlTemplateParsingHandler.java;h=fd2fa4bf1a4529a94ac67730411e245f58f692a9;hb=0278649141c9247b2ec56bb76998c3b9aa412874;hp=7c031a29e7b3192f17db86ff9732f4fcf1d8d03f;hpb=20b062cea965728a12560583d7a4e11a5df0b8f2;p=sdc.git diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 7c031a29e7..fd2fa4bf1a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -90,6 +90,7 @@ import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic; 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.ServiceBusinessLogic; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.utils.PropertiesUtils; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -107,8 +108,10 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefin import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction; import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; +import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.FilterValueType; import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType; import org.openecomp.sdc.be.model.CapabilityDefinition; @@ -123,6 +126,7 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.UploadArtifactInfo; import org.openecomp.sdc.be.model.UploadAttributeInfo; import org.openecomp.sdc.be.model.UploadCapInfo; @@ -154,18 +158,21 @@ public class YamlTemplateParsingHandler { private final GroupTypeBusinessLogic groupTypeBusinessLogic; private final AnnotationBusinessLogic annotationBusinessLogic; private final PolicyTypeBusinessLogic policyTypeBusinessLogic; + private final ServiceBusinessLogic serviceBusinessLogic; private final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler; public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao, GroupTypeBusinessLogic groupTypeBusinessLogic, AnnotationBusinessLogic annotationBusinessLogic, PolicyTypeBusinessLogic policyTypeBusinessLogic, + ServiceBusinessLogic serviceBusinessLogic, final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler ) { this.janusGraphDao = janusGraphDao; this.groupTypeBusinessLogic = groupTypeBusinessLogic; this.annotationBusinessLogic = annotationBusinessLogic; this.policyTypeBusinessLogic = policyTypeBusinessLogic; + this.serviceBusinessLogic = serviceBusinessLogic; this.toscaFunctionYamlParsingHandler = toscaFunctionYamlParsingHandler; } @@ -192,9 +199,16 @@ public class YamlTemplateParsingHandler { parsedToscaYamlInfo.setPolicies(getPolicies(mappedToscaTemplate, component.getModel())); Map substitutionMappings = getSubstitutionMappings(mappedToscaTemplate); if (substitutionMappings != null) { - if (component.isService() && !interfaceTemplateYaml.isEmpty()) { - parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml))); - parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); + if (component.isService()) { + if (!interfaceTemplateYaml.isEmpty()) { + parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml))); + parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); + } else { + Resource resource = serviceBusinessLogic.fetchDerivedFromGenericType(component, null); + List properties = resource.getProperties(); + parsedToscaYamlInfo.setProperties(properties.stream().collect(Collectors.toMap(PropertyDefinition::getName, prop -> prop))); + parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); + } } if (substitutionMappings.get("properties") != null) { parsedToscaYamlInfo.setSubstitutionMappingProperties((Map>) substitutionMappings.get("properties")); @@ -930,7 +944,7 @@ public class YamlTemplateParsingHandler { .createNodeFilterData(nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName()))); } } - + @SuppressWarnings("unchecked") private void setOccurrencesAndInstanceCount(UploadComponentInstanceInfo nodeTemplateInfo, Map nodeTemplateJsonMap) { if (nodeTemplateJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) { @@ -1205,7 +1219,8 @@ public class YamlTemplateParsingHandler { if (toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(propValueObj)) { toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue(propValueMap).ifPresent(propertyDef::setToscaFunction); } else { - final Collection subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); + final Collection subPropertyToscaFunctions = + buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) { Collection existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions(); if (existingSubPropertyToscaFunctions == null) { @@ -1232,7 +1247,7 @@ public class YamlTemplateParsingHandler { } return propertyDef; } - + private Collection buildSubPropertyToscaFunctions(final Map propValueMap, final List path) { Collection subPropertyToscaFunctions = new ArrayList<>(); propValueMap.entrySet().stream().filter(entry -> entry.getValue() instanceof Map).forEach(entry -> { @@ -1240,7 +1255,7 @@ public class YamlTemplateParsingHandler { subPropertyPath.add(entry.getKey()); if (ToscaFunctionType.findType(((Map) entry.getValue()).keySet().iterator().next()).isPresent()) { Optional toscaFunction = - toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue((Map) entry.getValue()); + toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue((Map) entry.getValue()); if (toscaFunction.isPresent()) { SubPropertyToscaFunction subPropertyToscaFunction = new SubPropertyToscaFunction(); subPropertyToscaFunction.setToscaFunction(toscaFunction.get()); @@ -1310,7 +1325,8 @@ public class YamlTemplateParsingHandler { }.getType(); String stringValue = gson.toJson(value, type); if (toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(value)) { - toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue((Map) value).ifPresent(operationInput::setToscaFunction); + toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue((Map) value) + .ifPresent(operationInput::setToscaFunction); } else { final Collection subPropertyToscaFunctions = buildSubPropertyToscaFunctions(valueMap, new ArrayList<>()); if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) { @@ -1420,8 +1436,9 @@ public class YamlTemplateParsingHandler { if (objValue instanceof Map) { Map objMap = (Map) objValue; Map propValueMap = new HashMap(); - propValueMap.put(String.valueOf(index),objValue); - final Collection subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); + propValueMap.put(String.valueOf(index), objValue); + final Collection subPropertyToscaFunctions = + buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) { Collection existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions(); if (existingSubPropertyToscaFunctions == null) {