aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2019-01-29 20:24:39 +0530
committerojasdubey <ojas.dubey@amdocs.com>2019-01-31 14:26:43 +0530
commitc0ebab732256fed103b7cb1445177ebc58f07050 (patch)
tree82eacd615a36b2ae3d97d680062a436a8858230b /catalog-be/src/main/java/org
parente5d23233b1597d61bdd4eddbce7c94b272088fbc (diff)
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 <ojas.dubey@amdocs.com>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java38
2 files changed, 65 insertions, 28 deletions
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<Boolean, ResponseFormat> mappedOutputDeletedResponse =
- validateMappedOutputNotDeleted(interfaceOperation, component, inputInterfaceDefinition,
+ Either<Boolean, ResponseFormat> 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<Boolean, ResponseFormat> validateMappedOutputNotDeleted(Operation interfaceOperation,
+ private Either<Boolean, ResponseFormat> 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<String> unchangedOutputNames = Sets.intersection(existingOperationOutputNames,
+ currentOperationOutputNames);
+ Set<String> 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<String> getModifiedMappedOutputNames(List<OperationOutputDefinition> currentOperationOutputs,
+ List<OperationOutputDefinition> existingOperationOutputs,
+ Set<String> unchangedOutputNames) {
+ Set<String> modifiedOutputDefinitionNames = new HashSet<>();
+ Map<String, OperationOutputDefinition> newOutputMap =
+ currentOperationOutputs.stream().collect(Collectors.toMap(OperationOutputDefinition::getName,
+ (OperationOutputDefinition operationOutputDefinition) -> operationOutputDefinition));
+
+ Map<String, OperationOutputDefinition> 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<Boolean, ResponseFormat> getMappedOutputErrorResponse(ResponseFormatManager responseFormatManager,
- Set<String> deletedMappedOutputs) {
- String deletedOutputNameList = String.join(",", deletedMappedOutputs);
- LOGGER.error("Cannot update name or delete interface operation output(s) '{}' mapped to an operation input",
- deletedOutputNameList);
+ Set<String> 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<String, List<String>> createMappedOutputDefaultValue(String propertyName, String interfaceType) {
+ private static Map<String, List<String>> createMappedOutputDefaultValue(String propertyName) {
Map<String, List<String>> getOperationOutputMap = new HashMap<>();
//For operation input mapped to other operation output parameter, the mapped property value
// should be of the format <interface name>.<operation name>.<output parameter name>
+ // Operation name and output param name should not contain "."
List<String> 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;
}