diff options
Diffstat (limited to 'catalog-be')
2 files changed, 13 insertions, 47 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index e56472a426..cce0ad19a3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -21,35 +21,27 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.google.gson.Gson; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import org.json.JSONObject; -import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; -import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; -import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.DataTypeDefinition; @@ -140,42 +132,10 @@ public class InterfacesOperationsConverter { mappedOutputValue.remove(1); mappedOutputValue.add(1, interfaceName); inputValue = gson.toJson(consumptionValue); - } else { - String finalInputValue = inputValue; - if (inputValue != null && - Arrays.stream(ToscaFunctionType.values()).anyMatch(toscaType -> finalInputValue.contains(toscaType.getName().toUpperCase()))) { - inputValue = getInputValuesAsToscaFunction(inputValue); - } } return inputValue; } - private static String getInputValuesAsToscaFunction(String inputValue) { - Gson gson = new Gson(); - Map<String, Object> mapOfValues = gson.fromJson(inputValue, Map.class); - for (Entry<String, Object> entry : mapOfValues.entrySet()) { - Object value = entry.getValue(); - if (value instanceof Map) { - Map<String, Object> valueMap = (Map<String, Object>) value; - if (valueMap.containsKey("type")) { - String type = (String) valueMap.get("type"); - Optional<ToscaFunctionType> toscaType = ToscaFunctionType.findType(type); - if (toscaType.isPresent()) { - ObjectMapper mapper = new ObjectMapper(); - try { - String json = gson.toJson(value); - ToscaFunction toscaFunction = mapper.readValue(json, ToscaFunction.class); - entry.setValue(toscaFunction.getJsonObjectValue()); - } catch (JsonProcessingException e) { - throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); - } - } - } - } - } - return String.valueOf(new JSONObject(mapOfValues)); - } - private static String getInterfaceType(Component component, String interfaceType) { if (LOCAL_INTERFACE_TYPE.equals(interfaceType)) { return DERIVED_FROM_BASE_DEFAULT + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java index 5158ae7945..5ba29cbbef 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue; import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -49,6 +50,7 @@ import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; @@ -238,8 +240,11 @@ class InterfacesOperationsConverterTest { "name_for_op_0")) .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream() .filter(operationInputDefinition -> operationInputDefinition.getName().contains("integer")) - .forEach(operationInputDefinition -> operationInputDefinition.setInputId(addedInterfaceType + - ".name_for_op_1.output_integer_1"))); + .forEach(operationInputDefinition -> { + operationInputDefinition.setInputId(addedInterfaceType + ".name_for_op_1.output_integer_1"); + operationInputDefinition.setToscaDefaultValue( + new Gson().toJson(createMappedOutputDefaultValue(SELF, operationInputDefinition.getInputId()))); + })); component.setInterfaces(new HashMap<>()); component.getInterfaces().put(addedInterfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); @@ -572,11 +577,12 @@ class InterfacesOperationsConverterTest { Map<String, Object> complexInput = (Map<String, Object>) operation0Inputs.get("input_Complex_2"); assertTrue(complexInput.containsKey("stringProp")); Map<String, Object> complexInputStringProp = (Map<String, Object>) complexInput.get("stringProp"); - assertTrue(complexInputStringProp.containsKey("get_attribute")); - List<String> complexInputStringPropToscaFunction = (List<String>) complexInputStringProp.get("get_attribute"); - assertEquals(2, complexInputStringPropToscaFunction.size()); - assertEquals("SELF", complexInputStringPropToscaFunction.get(0)); - assertEquals("designer", complexInputStringPropToscaFunction.get(1)); + assertTrue(complexInputStringProp.containsKey("type")); + assertTrue(ToscaFunctionType.findType((String) complexInputStringProp.get("type")).isPresent()); + assertTrue(complexInputStringProp.containsKey("propertyName")); + assertEquals("designer", complexInputStringProp.get("propertyName")); + assertTrue(complexInputStringProp.containsKey("propertySource")); + assertEquals("SELF", complexInputStringProp.get("propertySource")); } private void addComplexTypeToDataTypes() { |