From 39dd951527bf62568cf5815a6b1e4901c2b89c3f Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 2 Oct 2023 12:28:06 +0100 Subject: Allow import of handcrafted templates with specific substitution filter format Signed-off-by: Vasyl Razinkov Change-Id: I363e36c349aac35653de92a43cc14c9a68327c65 Issue-ID: SDC-4641 --- .../csar/YamlTemplateParsingHandler.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'catalog-be/src') 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 2d29f80017..5556548b50 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 @@ -257,21 +257,30 @@ public class YamlTemplateParsingHandler { return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>()); } - private ListDataDefinition getSubstitutionFilterProperties(Map toscaJson) { - ListDataDefinition propertyList = new ListDataDefinition<>(); - Map substitutionFilters = findFirstToscaMapElement(toscaJson, SUBSTITUTION_FILTERS).left().on(err -> new HashMap<>()); + private ListDataDefinition getSubstitutionFilterProperties(final Map toscaJson) { + final ListDataDefinition propertyList = new ListDataDefinition<>(); + final Map substitutionFilters = findFirstToscaMapElement(toscaJson, SUBSTITUTION_FILTERS).left().on(err -> new HashMap<>()); if (MapUtils.isEmpty(substitutionFilters)) { return propertyList; } - ArrayList>>> substitutionFilterProperties = - (ArrayList>>>) substitutionFilters.get("properties"); + final List> substitutionFilterProperties = (List>) substitutionFilters.get("properties"); if (CollectionUtils.isEmpty(substitutionFilterProperties)) { return propertyList; } - for (Map>> filterProps : substitutionFilterProperties) { - for (Map.Entry>> propertyFilterEntry : filterProps.entrySet()) { + for (final Map filterProps : substitutionFilterProperties) { + for (final Map.Entry propertyFilterEntry : filterProps.entrySet()) { final String propertyName = propertyFilterEntry.getKey(); - for (Map filterValueMap : propertyFilterEntry.getValue()) { + final Object value = propertyFilterEntry.getValue(); + if (value instanceof List) { + final List> propertyFilterEntryValue = (List>) value; + for (final Map filterValueMap : propertyFilterEntryValue) { + final var substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition(); + substitutionFilterPropertyDataDefinition.setName(propertyName); + substitutionFilterPropertyDataDefinition.setConstraints(createSubstitutionFilterConstraints(propertyName, filterValueMap)); + propertyList.add(substitutionFilterPropertyDataDefinition); + } + } else if (value instanceof Map) { + final Map filterValueMap = (Map) value; final var substitutionFilterPropertyDataDefinition = new SubstitutionFilterPropertyDataDefinition(); substitutionFilterPropertyDataDefinition.setName(propertyName); substitutionFilterPropertyDataDefinition.setConstraints(createSubstitutionFilterConstraints(propertyName, filterValueMap)); -- cgit 1.2.3-korg