Bugfix - Workflow operation input type tosca 63/56863/2
authorojasdubey <ojas.dubey@amdocs.com>
Thu, 19 Jul 2018 08:53:40 +0000 (14:23 +0530)
committerAvi Gaffa <avi.gaffa@amdocs.com>
Thu, 19 Jul 2018 14:04:23 +0000 (14:04 +0000)
Fix for incorrect type being populated
for workflow operation inputs

Change-Id: I5a70153b5bde289b8e5f499a9f3f1f21c4786ce6
Issue-ID: SDC-1528
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java

index 8d8eac3..4455c32 100644 (file)
@@ -577,10 +577,10 @@ public class ToscaExportHandler {
             inputDef.forEach(i -> {
                 ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
                 inputs.put(i.getName(), property);
-                addInterfaceDefinitionElement(component, toscaNodeType);
             });
             if (!inputs.isEmpty()) {
                 toscaNodeType.setProperties(inputs);
+                addInterfaceDefinitionElement(component, toscaNodeType);
             }
         }
 
index 8c9c63a..75a65f9 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.openecomp.sdc.be.tosca.utils;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -132,7 +133,7 @@ public class InterfacesOperationsToscaUtil {
                     toscaOperation.setImplementation(operationArtifactPath);
                 }
                 toscaOperation.setDescription(operationEntry.getValue().getDescription());
-                fillToscaOperationInputs(operationEntry.getValue(), toscaOperation);
+                fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType);
 
                 toscaOperations.put(operationEntry.getValue().getName(), toscaOperation);
             }
@@ -179,7 +180,8 @@ public class InterfacesOperationsToscaUtil {
     }
 
     private static void fillToscaOperationInputs(OperationDataDefinition operation,
-            ToscaLifecycleOperationDefinition toscaOperation) {
+                                                 ToscaLifecycleOperationDefinition toscaOperation,
+                                                 ToscaNodeType nodeType) {
         if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) {
             toscaOperation.setInputs(null);
             return;
@@ -189,15 +191,23 @@ public class InterfacesOperationsToscaUtil {
         for (OperationInputDefinition input : operation.getInputs().getListToscaDataDefinition()) {
             ToscaProperty toscaInput = new ToscaProperty();
             toscaInput.setDescription(input.getDescription());
-            toscaInput.setType(DEFAULT_INPUT_TYPE);
-
-            toscaInput.setDefaultp(createDefaultValue(getLastPartOfName(input.getInputId())));
+            String mappedPropertyName = getLastPartOfName(input.getInputId());
+            toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType));
+            toscaInput.setDefaultp(createDefaultValue(mappedPropertyName));
             toscaInputs.put(input.getName(), toscaInput);
         }
 
         toscaOperation.setInputs(toscaInputs);
     }
 
+    private static String getOperationInputType(String inputName, ToscaNodeType nodeType) {
+        if (nodeType.getProperties() != null
+                &&  nodeType.getProperties().containsKey(inputName)) {
+            return nodeType.getProperties().get(inputName).getType();
+        }
+        return DEFAULT_INPUT_TYPE;
+    }
+
     private static Map<String, List<String>> createDefaultValue(String propertyName) {
         Map<String, List<String>> getPropertyMap = new HashMap<>();
         List<String> values = new ArrayList<>();
@@ -210,8 +220,13 @@ public class InterfacesOperationsToscaUtil {
 
 
     private static Map<String, Object> getObjectAsMap(Object obj) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        if (obj instanceof ToscaInterfaceDefinition) {
+            //Prevent empty field serialization in interface definition
+            objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+        }
         Map<String, Object> objectAsMap =
-                obj instanceof Map ? (Map<String, Object>) obj : new ObjectMapper().convertValue(obj, Map.class);
+                obj instanceof Map ? (Map<String, Object>) obj : objectMapper.convertValue(obj, Map.class);
 
         if (objectAsMap.containsKey(DEFAULT)) {
             Object defaultValue = objectAsMap.get(DEFAULT);