From 7bfba3ec8f482a36884f9675bf8b2f3ca8b56033 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Thu, 19 Jul 2018 14:23:40 +0530 Subject: Bugfix - Workflow operation input type tosca Fix for incorrect type being populated for workflow operation inputs Change-Id: I5a70153b5bde289b8e5f499a9f3f1f21c4786ce6 Issue-ID: SDC-1528 Signed-off-by: ojasdubey --- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 2 +- .../tosca/utils/InterfacesOperationsToscaUtil.java | 27 +++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 8d8eac36b9..4455c3205a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -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); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index 8c9c63af03..75a65f95da 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -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> createDefaultValue(String propertyName) { Map> getPropertyMap = new HashMap<>(); List values = new ArrayList<>(); @@ -210,8 +220,13 @@ public class InterfacesOperationsToscaUtil { private static Map 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 objectAsMap = - obj instanceof Map ? (Map) obj : new ObjectMapper().convertValue(obj, Map.class); + obj instanceof Map ? (Map) obj : objectMapper.convertValue(obj, Map.class); if (objectAsMap.containsKey(DEFAULT)) { Object defaultValue = objectAsMap.get(DEFAULT); -- cgit 1.2.3-korg