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=09a84887aa5566863bae40bd846f9bf4893759bd;hb=9699b67917b34c1a10536d353cef09d8904354a6;hp=82aa1343c1a0f76d2b3a79b3f80cd40d1b9965a0;hpb=92b18f188105d5ba4b2c469cdfaedc7d2953d593;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 82aa1343c1..09a84887aa 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 @@ -30,7 +30,6 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaLis import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement; import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement; import static org.openecomp.sdc.be.components.impl.ImportUtils.loadYamlAsStrictMap; -import static org.openecomp.sdc.be.datatypes.enums.MetadataKeyEnum.NAME; import static org.openecomp.sdc.be.model.tosca.ToscaType.STRING; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ATTRIBUTES; @@ -104,9 +103,11 @@ 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.PropertyFilterConstraintDataDefinition; +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.enums.ConstraintType; +import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.enums.FilterValueType; import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType; import org.openecomp.sdc.be.model.CapabilityDefinition; @@ -369,6 +370,7 @@ public class YamlTemplateParsingHandler { 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()); return propertyDefinition; @@ -623,6 +625,7 @@ public class YamlTemplateParsingHandler { private void mergeGroupProperty(final PropertyDataDefinition property, final Object propertyYaml) { final UploadPropInfo uploadPropInfo = buildProperty(property.getName(), propertyYaml); property.setToscaFunction(uploadPropInfo.getToscaFunction()); + property.setSubPropertyToscaFunctions(uploadPropInfo.getSubPropertyToscaFunctions()); property.setValue(convertPropertyValue(ToscaPropertyType.isValidType(property.getType()), uploadPropInfo.getValue())); property.setGetInputValues(uploadPropInfo.getGet_input()); } @@ -1183,6 +1186,16 @@ public class YamlTemplateParsingHandler { } if (toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(propValueObj)) { toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue(propValueMap).ifPresent(propertyDef::setToscaFunction); + } else { + final Collection subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>()); + if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) { + Collection existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions(); + if (existingSubPropertyToscaFunctions == null) { + propertyDef.setSubPropertyToscaFunctions(subPropertyToscaFunctions); + } else { + propertyDef.getSubPropertyToscaFunctions().addAll(subPropertyToscaFunctions); + } + } } if (propValueMap.containsKey(DESCRIPTION.getElementName())) { propertyDef.setDescription((propValueMap).get(DESCRIPTION.getElementName()).toString()); @@ -1201,6 +1214,27 @@ 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 -> { + List subPropertyPath = new ArrayList<>(path); + subPropertyPath.add(entry.getKey()); + if (ToscaFunctionType.findType(((Map) entry.getValue()).keySet().iterator().next()).isPresent()) { + Optional toscaFunction = + toscaFunctionYamlParsingHandler.buildToscaFunctionBasedOnPropertyValue((Map) entry.getValue()); + if (toscaFunction.isPresent()) { + SubPropertyToscaFunction subPropertyToscaFunction = new SubPropertyToscaFunction(); + subPropertyToscaFunction.setToscaFunction(toscaFunction.get()); + subPropertyToscaFunction.setSubPropertyPath(subPropertyPath); + subPropertyToscaFunctions.add(subPropertyToscaFunction); + } + } else { + subPropertyToscaFunctions.addAll(buildSubPropertyToscaFunctions((Map) entry.getValue(), subPropertyPath)); + } + }); + return subPropertyToscaFunctions; + } private UploadInterfaceInfo buildInterface(String interfaceName, Object interfaceValue) { UploadInterfaceInfo interfaceDef = new UploadInterfaceInfo();