From c0ebab732256fed103b7cb1445177ebc58f07050 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Tue, 29 Jan 2019 20:24:39 +0530 Subject: Operation Outputs - Operation screen BE 1. Fixed bug in tosca generation for mapped outputs 2. Fixed issues in validation of modified mapped outputs and tosca generation 3. Unit tests Change-Id: I2cb9a55d58d8e9a8d2a4a064646d6ef7ec93e61f Issue-ID: SDC-2085 Signed-off-by: ojasdubey --- .../validation/InterfaceOperationValidation.java | 55 ++++++++++++++++++---- .../tosca/utils/InterfacesOperationsToscaUtil.java | 38 ++++++++------- 2 files changed, 65 insertions(+), 28 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index d17762fc90..250fc03c21 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -179,11 +179,11 @@ public class InterfaceOperationValidation { } if (MapUtils.isNotEmpty(component.getInterfaces()) && isUpdate) { - Either mappedOutputDeletedResponse = - validateMappedOutputNotDeleted(interfaceOperation, component, inputInterfaceDefinition, + Either mappedOutputModifiedResponse = + validateMappedOutputNotModified(interfaceOperation, component, inputInterfaceDefinition, responseFormatManager); - if (mappedOutputDeletedResponse.isRight()) { - return Either.right(mappedOutputDeletedResponse.right().value()); + if (mappedOutputModifiedResponse.isRight()) { + return Either.right(mappedOutputModifiedResponse.right().value()); } } @@ -191,7 +191,7 @@ public class InterfaceOperationValidation { } - private Either validateMappedOutputNotDeleted(Operation interfaceOperation, + private Either validateMappedOutputNotModified(Operation interfaceOperation, org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition, ResponseFormatManager responseFormatManager) { @@ -222,6 +222,18 @@ public class InterfaceOperationValidation { if (CollectionUtils.isNotEmpty(deletedMappedOutputs)) { return getMappedOutputErrorResponse(responseFormatManager, deletedMappedOutputs); } + + if (currentOutputs != null && !currentOutputs.isEmpty()) { + Set unchangedOutputNames = Sets.intersection(existingOperationOutputNames, + currentOperationOutputNames); + Set modifiedMappedOutputNames = + getModifiedMappedOutputNames(currentOutputs.getListToscaDataDefinition(), + existingOperationOutputs, unchangedOutputNames); + if (CollectionUtils.isNotEmpty(modifiedMappedOutputNames)) { + return getMappedOutputErrorResponse(responseFormatManager, modifiedMappedOutputNames); + } + } + return Either.left(Boolean.TRUE); } @@ -234,13 +246,36 @@ public class InterfaceOperationValidation { .equals(mappedOutputPrefix + "." + outputName)); } + private static Set getModifiedMappedOutputNames(List currentOperationOutputs, + List existingOperationOutputs, + Set unchangedOutputNames) { + Set modifiedOutputDefinitionNames = new HashSet<>(); + Map newOutputMap = + currentOperationOutputs.stream().collect(Collectors.toMap(OperationOutputDefinition::getName, + (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition)); + + Map existingOutputMap = + existingOperationOutputs.stream().collect(Collectors.toMap(OperationOutputDefinition::getName, + (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition)); + + for (String outputName : unchangedOutputNames) { + OperationOutputDefinition existingOutputDefinition = existingOutputMap.get(outputName); + OperationOutputDefinition newOutputDefinition = newOutputMap.get(outputName); + if (!existingOutputDefinition.getType().equals(newOutputDefinition.getType()) + || !existingOutputDefinition.isRequired().equals(newOutputDefinition.isRequired())) { + modifiedOutputDefinitionNames.add(outputName); + } + } + return modifiedOutputDefinitionNames; + } + private Either getMappedOutputErrorResponse(ResponseFormatManager responseFormatManager, - Set deletedMappedOutputs) { - String deletedOutputNameList = String.join(",", deletedMappedOutputs); - LOGGER.error("Cannot update name or delete interface operation output(s) '{}' mapped to an operation input", - deletedOutputNameList); + Set modifiedMappedOutputs) { + String modifiedOutputNameList = String.join(",", modifiedMappedOutputs); + LOGGER.error("Cannot update or delete interface operation output(s) '{}' mapped to an operation input", + modifiedOutputNameList); ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus - .INTERFACE_OPERATION_MAPPED_OUTPUT_DELETED, deletedOutputNameList); + .INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED, modifiedOutputNameList); return Either.right(errorResponse); } 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 efed3e9f15..106aa58133 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 @@ -20,14 +20,12 @@ import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOp import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; - import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; @@ -59,7 +57,7 @@ public class InterfacesOperationsToscaUtil { } /** - * Creates the interface_types element + * Creates the interface_types element. * * @param component to work on * @return the added element @@ -99,7 +97,7 @@ public class InterfacesOperationsToscaUtil { } /** - * Adds the 'interfaces' element to the node type provided + * Adds the 'interfaces' element to the node type provided. * * @param component to work on * @param nodeType to which the interfaces element will be added @@ -131,7 +129,7 @@ public class InterfacesOperationsToscaUtil { toscaOperation.setImplementation(operationArtifactPath); } toscaOperation.setDescription(operationEntry.getValue().getDescription()); - fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, interfaceType, component); + fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, component); toscaOperations.put(operationEntry.getValue().getName(), toscaOperation); } @@ -148,7 +146,7 @@ public class InterfacesOperationsToscaUtil { } } - /*** + /* * workaround for : currently "defaultp" is not being converted to "default" by the relevant code in * ToscaExportHandler so, any string Map key named "defaultp" will have its named changed to "default" * @param operationsMap the map to update @@ -181,7 +179,6 @@ public class InterfacesOperationsToscaUtil { private static void fillToscaOperationInputs(OperationDataDefinition operation, ToscaLifecycleOperationDefinition toscaOperation, - String interfaceType, Component component) { if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) { toscaOperation.setInputs(null); @@ -199,7 +196,7 @@ public class InterfacesOperationsToscaUtil { toscaInput.setDefaultp(createMappedInputPropertyDefaultValue(mappedPropertyName)); } else { mappedPropertyName = input.getInputId(); - toscaInput.setDefaultp(createMappedOutputDefaultValue(mappedPropertyName, interfaceType)); + toscaInput.setDefaultp(createMappedOutputDefaultValue(mappedPropertyName)); } } toscaInput.setType(input.getType()); @@ -224,23 +221,28 @@ public class InterfacesOperationsToscaUtil { } /** - * Create the value for operation input mapped to an operation output + * Create the value for operation input mapped to an operation output. * @param propertyName the mapped other operation output full name - * @param interfaceType full interface name * @return input map for tosca */ - private static Map> createMappedOutputDefaultValue(String propertyName, String interfaceType) { + private static Map> createMappedOutputDefaultValue(String propertyName) { Map> getOperationOutputMap = new HashMap<>(); //For operation input mapped to other operation output parameter, the mapped property value // should be of the format .. + // Operation name and output param name should not contain "." List defaultMappedOperationOutputValue = new ArrayList<>(); - defaultMappedOperationOutputValue.add(SELF); - String fullOutputPropertyName = - propertyName.substring(propertyName.indexOf(interfaceType) + interfaceType.length() + 1); - defaultMappedOperationOutputValue.add(interfaceType); - //Output name should not contain dot - defaultMappedOperationOutputValue.addAll(Arrays.asList(fullOutputPropertyName.split("\\."))); - getOperationOutputMap.put(GET_OPERATION_OUTPUT, defaultMappedOperationOutputValue); + String[] tokens = propertyName.split("\\."); + if (tokens.length > 2) { + defaultMappedOperationOutputValue.add(SELF); + String outputPropertyName = tokens[tokens.length - 1]; + String operationName = tokens[tokens.length - 2]; + String mappedPropertyInterfaceType = + propertyName.substring(0, propertyName.indexOf(operationName + '.' + outputPropertyName) - 1); + String interfaceName = + mappedPropertyInterfaceType.substring(mappedPropertyInterfaceType.lastIndexOf('.') + 1); + defaultMappedOperationOutputValue.addAll(Arrays.asList(interfaceName, operationName, outputPropertyName)); + getOperationOutputMap.put(GET_OPERATION_OUTPUT, defaultMappedOperationOutputValue); + } return getOperationOutputMap; } -- cgit 1.2.3-korg