aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java22
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java16
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java40
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java3
5 files changed, 117 insertions, 13 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 aa58c14227..e57c7b9496 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
@@ -89,6 +89,13 @@ public class InterfaceOperationValidation {
if(inputParametersResponse.isRight()) {
return Either.right(inputParametersResponse.right().value());
}
+
+ Either<Boolean, ResponseFormat> outputParametersResponse = validateOutputParameters(interfaceOperation,
+ responseFormatManager);
+ if(outputParametersResponse.isRight()) {
+ return Either.right(outputParametersResponse.right().value());
+ }
+
return Either.left(Boolean.TRUE);
}
@@ -223,6 +230,28 @@ public class InterfaceOperationValidation {
return Either.left(Boolean.TRUE);
}
+
+ private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation,
+ ResponseFormatManager responseFormatManager) {
+ if (isOutputParameterNameEmpty(interfaceOperation)) {
+ LOGGER.error("Interface operation output parameter name can't be empty");
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY);
+ return Either.right(inputResponse);
+ }
+
+ Either<Boolean, Set<String>> validateOutputParametersUniqueResponse = isOutputParametersUnique(interfaceOperation);
+ if(validateOutputParametersUniqueResponse.isRight()) {
+ LOGGER.error("Interface operation output parameter names {} already in use",
+ validateOutputParametersUniqueResponse.right().value().toString());
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
+ .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
+ return Either.right(inputResponse);
+ }
+ return Either.left(Boolean.TRUE);
+ }
+
+
private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
@@ -238,11 +267,29 @@ public class InterfaceOperationValidation {
return Either.left(Boolean.TRUE);
}
+ private Either<Boolean, Set<String>> isOutputParametersUnique(Operation operationDataDefinition) {
+ Set<String> outputParamNamesSet = new HashSet<>();
+ Set<String> duplicateParamNamesToReturn = new HashSet<>();
+ operationDataDefinition.getOutputs().getListToscaDataDefinition()
+ .forEach(outputParam -> {
+ if(!outputParamNamesSet.add(outputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(outputParam.getName().trim());
+ }
+ });
+ if(!duplicateParamNamesToReturn.isEmpty()) {
+ return Either.right(duplicateParamNamesToReturn);
+ }
+ return Either.left(Boolean.TRUE);
+ }
+
private Boolean isInputParameterNameEmpty(Operation operationDataDefinition) {
return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
.anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
-
+ private Boolean isOutputParameterNameEmpty(Operation operationDataDefinition) {
+ return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
+ .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+ }
private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation,
Map<String, String> operationTypes) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
index 78b2354615..2db551643c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
@@ -23,6 +23,7 @@ import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationParamDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.Operation;
public class InterfaceUIDataConverter {
@@ -40,11 +41,21 @@ public class InterfaceUIDataConverter {
interfaceOperationParamDataDefinition.getParamId())).collect(Collectors.toList());
inputList.forEach(inputs::add);
}
+ ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams = interfaceOperation.getOutputParams();
+ ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>();
+ if(outputParams != null) {
+ List<OperationOutputDefinition> outputList = outputParams.getListToscaDataDefinition().stream()
+ .map(interfaceOperationParamDataDefinition -> new OperationOutputDefinition(interfaceOperationParamDataDefinition.getParamName(),
+ interfaceOperationParamDataDefinition.getParamId())).collect(Collectors.toList());
+ outputList.forEach(outputs::add);
+ }
+
Operation operationData = new Operation();
operationData.setDescription(interfaceOperation.getDescription());
operationData.setName(interfaceOperation.getOperationType());
operationData.setUniqueId(interfaceOperation.getUniqueId());
operationData.setInputs(inputs);
+ operationData.setOutputs(outputs);
return operationData;
}
@@ -53,16 +64,25 @@ public class InterfaceUIDataConverter {
ListDataDefinition<OperationInputDefinition> inputs = operationData.getInputs();
List<InterfaceOperationParamDataDefinition> inputParamList = inputs.getListToscaDataDefinition().stream()
- .map(a -> new InterfaceOperationParamDataDefinition(a.getName(), a.getInputId())).collect(
+ .map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(),
+ operationInputDefinition.getInputId())).collect(
Collectors.toList());
ListDataDefinition<InterfaceOperationParamDataDefinition> inputParams = new ListDataDefinition<>();
inputParamList.forEach(inputParams::add);
+ ListDataDefinition<OperationOutputDefinition> outputs = operationData.getOutputs();
+ List<InterfaceOperationParamDataDefinition> outputParamList = outputs.getListToscaDataDefinition()
+ .stream().map(operationOutputDefinition -> new InterfaceOperationParamDataDefinition(operationOutputDefinition.getName(),
+ operationOutputDefinition.getInputId())).collect(Collectors.toList());
+ ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams = new ListDataDefinition<>();
+ outputParamList.forEach(outputParams::add);
+
InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition();
interfaceOperationDataDefinition.setUniqueId(operationData.getUniqueId());
interfaceOperationDataDefinition.setOperationType(operationData.getName());
interfaceOperationDataDefinition.setDescription(operationData.getDescription());
interfaceOperationDataDefinition.setInputParams(inputParams);
+ interfaceOperationDataDefinition.setOutputParams(outputParams);
interfaceOperationDataDefinition.setArtifactUUID(operationData.getImplementation().getArtifactUUID());
return interfaceOperationDataDefinition;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
index f38848c1be..cf3d5d5bdc 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
@@ -21,6 +21,7 @@ import java.util.Map;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
@@ -46,13 +47,15 @@ public interface InterfaceOperationTestUtils {
default Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition,
- ListDataDefinition<OperationInputDefinition> inputs, String name) {
+ ListDataDefinition<OperationInputDefinition> inputs,
+ ListDataDefinition<OperationOutputDefinition> outputs, String name) {
Operation operation = new Operation();
operation.setUniqueId(uniqueID);
operation.setDescription(description);
operation.setImplementation(artifactDefinition);
operation.setInputs(inputs);
+ operation.setOutputs(outputs);
operation.setName(name);
return operation;
@@ -65,6 +68,10 @@ public interface InterfaceOperationTestUtils {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
operation.setInputs(operationInputDefinitionList);
+ ListDataDefinition<OperationOutputDefinition> operationOutputDefList = new ListDataDefinition<>();
+ operationOutputDefList.add(createMockOperationOutputDefinition("op1"));
+ operation.setOutputs(operationOutputDefList);
+
operation.setDefinition(false);
operation.setName("CREATE");
operation.setUniqueId("uniqueId1");
@@ -85,6 +92,13 @@ public interface InterfaceOperationTestUtils {
return operationInputDefinition;
}
+ default OperationOutputDefinition createMockOperationOutputDefinition(String name) {
+ OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition();
+ operationOutputDefinition.setName(name);
+ operationOutputDefinition.setUniqueId("uniqueId1");
+ return operationOutputDefinition;
+ }
+
default Map<String, InterfaceDefinition> createMockInterfaceDefinition(String resourceName) {
Map<String, Operation> operationMap = createMockOperationMap();
Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
index a8686c179a..02c212d7e6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
@@ -35,6 +35,7 @@ import org.openecomp.sdc.be.components.InterfaceOperationTestUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -61,6 +62,7 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
private static final String RESOURCE_ID = "resource1";
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
@Before
public void init() {
MockitoAnnotations.initMocks(this);
@@ -75,8 +77,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testValidInterfaceOperation() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"upgrade");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"upgrade");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
@@ -85,11 +89,12 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testInterfaceOperationDescriptionLength() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
"interface operation2 - The Spring Initializer provides a project generator to make you " +
"productive with the certain technology stack from the beginning. You can create a skeleton project" +
"with web, data access (relational and NoSQL datastores), cloud, or messaging support",
- new ArtifactDefinition(), operationInputDefinitionList,"update");
+ new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
@@ -100,8 +105,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testInterfaceOperationForEmptyType() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList, "");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
@@ -110,8 +117,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testInterfaceOperationForEmptyInputParam() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"input2");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"input2");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
@@ -120,8 +129,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testInterfaceOperationForNonUniqueType() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"CREATE");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"CREATE");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
@@ -130,8 +141,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
@Test
public void testInterfaceOperationTypeLength() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,
"interface operation2 - The Spring Initializer provides a project generator to make you " +
"productive with the certain technology stack from the beginning. You can create a skeleton project" +
"with web, data access (relational and NoSQL datastores), cloud, or messaging support");
@@ -147,8 +160,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"create");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"create");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, RESOURCE_ID, false);
@@ -159,8 +174,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
public void testInterfaceOperationUniqueInputParamNameValid() {
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
operationInputDefinitionList.add(createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"update");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
@@ -172,8 +189,10 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
public void testInterfaceOperationeInputParamNameEmpty() {
operationInputDefinitionList.add(createMockOperationInputDefinition(" "));
operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"update");
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
@@ -182,8 +201,9 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
}
private Set<Operation> createInterfaceOperationData( String uniqueID, String description, ArtifactDefinition artifactDefinition,
- ListDataDefinition<OperationInputDefinition> inputs, String name) {
- return Sets.newHashSet(createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, name));
+ ListDataDefinition<OperationInputDefinition> inputs,
+ ListDataDefinition<OperationOutputDefinition> outputs, String name) {
+ return Sets.newHashSet(createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name));
}
private <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java
index 5ed11a553e..b158ddf5da 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java
@@ -9,6 +9,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.Operation;
public class InterfaceUIDataConverterTest {
@@ -27,7 +28,9 @@ public class InterfaceUIDataConverterTest {
Operation operationData = new Operation();
InterfaceOperationDataDefinition result;
ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>();
operationData.setInputs(inputs);
+ operationData.setOutputs(outputs);
operationData.setImplementation(new ArtifactDataDefinition());
// default test
result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData);