Fix substitution_mapping property mapping 02/114002/2
authorandre.schmid <andre.schmid@est.tech>
Tue, 29 Sep 2020 10:37:47 +0000 (11:37 +0100)
committerS�bastien Determe <sebastien.determe@intl.att.com>
Fri, 23 Oct 2020 14:53:39 +0000 (14:53 +0000)
Currently the properties in substitution_mapping are being generated
as property definition, copying the inputs. They should be property
mappings referring inputs.

Change-Id: I0b3b056adeab79915db1b42218364c22f07a079f
Issue-ID: SDC-3307
Signed-off-by: andre.schmid <andre.schmid@est.tech>
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java

index 0907dd1..d0c14f7 100644 (file)
@@ -28,6 +28,7 @@ import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterf
 import java.beans.IntrospectionException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -367,9 +368,10 @@ public class ToscaExportHandler {
             return Either.right(requirements.right().value());
         }
         substitutionMapping = requirements.left().value();
-
-        final Optional<Map<String, ToscaProperty>> proxyInputProperties = getProxyNodeTypeInputProperties(component, dataTypes);
-        proxyInputProperties.ifPresent(substitutionMapping::setProperties);
+        final Map<String, String[]> propertyMappingMap = buildSubstitutionMappingPropertyMapping(component);
+        if (!propertyMappingMap.isEmpty()) {
+            substitutionMapping.setProperties(propertyMappingMap);
+        }
 
         topologyTemplate.setSubstitution_mappings(substitutionMapping);
 
@@ -1735,14 +1737,18 @@ public class ToscaExportHandler {
 
     }
 
-    private Optional<Map<String, ToscaProperty>> getProxyNodeTypeInputProperties(final Component proxyComponent,
-                                                                                 final Map<String, DataTypeDefinition> dataTypes) {
-        if (Objects.isNull(proxyComponent)) {
-            return Optional.empty();
+    private Map<String, String[]> buildSubstitutionMappingPropertyMapping(final Component component) {
+        if (component == null || CollectionUtils.isEmpty(component.getInputs())) {
+            return Collections.emptyMap();
         }
-        final Map<String, ToscaProperty> proxyInputProperties = new HashMap<>();
-        addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyInputProperties);
-        return MapUtils.isNotEmpty(proxyInputProperties) ? Optional.of(proxyInputProperties) : Optional.empty();
+        return component.getInputs().stream()
+            .map(PropertyDataDefinition::getName)
+            .collect(
+                Collectors.toMap(
+                    inputName -> inputName,
+                    inputName -> new String[]{inputName},
+                    (inputName1, inputName2) -> inputName1)
+            );
     }
 
     Optional<Map<String, ToscaProperty>> getProxyNodeTypeProperties(Component proxyComponent,
index 13a28db..1a2a138 100644 (file)
@@ -38,5 +38,5 @@ public class SubstitutionMapping {
     private Map<String, String[]> capabilities;
     private Map<String, String[]> requirements;
     private NodeFilter substitution_filter;
-    private Map<String, ToscaProperty> properties;
+    private Map<String, String[]> properties;
 }