aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-09-05 18:05:36 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-09-13 13:00:27 +0000
commitb65c8eeb334a2c579a2dc0241f480d81e9309f9c (patch)
treeb3b3ed06b53703f771da51bec4b40e71b9e1bd1d /catalog-be/src
parentf1e032cf4ae3505eb8acbce56ac978649d6f63d4 (diff)
Interface operation support for service - BE
1. Interface operation support for service 2. Refactored common code of operationspa 3. ONAP Bug fixes VF operations Change-Id: If1c4fd5f17626dbe568ee66ad997eb8ffb772e29 Issue-ID: SDC-1739 Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java74
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java)58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java52
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml60
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java120
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java71
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java84
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java152
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java8
14 files changed, 489 insertions, 302 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index e7ae0612f4..fee386ab29 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -40,6 +40,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.*;
@@ -122,6 +123,12 @@ public abstract class BaseBusinessLogic {
@Autowired
protected ApplicationDataTypeCache dataTypeCache;
+ @Autowired
+ protected InterfaceOperation interfaceOperation;
+
+ @Autowired
+ protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
@javax.annotation.Resource
private UserValidations userValidations;
@@ -156,6 +163,10 @@ public abstract class BaseBusinessLogic {
this.propertyOperation = propertyOperation;
}
+ public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
+ this.interfaceOperation = interfaceOperation;
+ }
+
User validateUserNotEmpty(User user, String ecompErrorContext) {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
index 2f4519beb9..792e23af3b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
@@ -18,7 +18,7 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -28,9 +28,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -55,13 +53,6 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
@Autowired
private InterfaceOperationValidation interfaceOperationValidation;
- @Autowired
- private InterfaceOperation interfaceOperation;
-
- public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
- this.interfaceOperation = interfaceOperation;
- }
-
public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) {
this.interfaceOperationValidation = interfaceOperationValidation;
}
@@ -74,18 +65,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, DELETE_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -112,7 +98,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -126,18 +112,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, GET_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -158,13 +139,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
}
- public Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) {
+ private Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) {
if (interfaceDef != null){
return Either.left(interfaceDef);
} else {
@@ -195,26 +176,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), errorContext, true);
-
- InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs());
Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
- .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate);
+ .validateInterfaceOperations(Collections.singletonList(operation), storedComponent, isUpdate);
if(interfaceOperationValidationResponseEither.isRight()) {
return Either.right(interfaceOperationValidationResponseEither.right().value());
}
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, errorContext);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -250,7 +224,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -287,4 +261,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
operation.setUniqueId(UUID.randomUUID().toString());
operation.setImplementation(artifactDefinition);
}
+
+ private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action){
+ if (lock) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
+ if (lockResult.isRight()) {
+ LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(), lockResult.right().value().getFormattedMessage());
+ titanDao.rollback();
+ return Either.right(lockResult.right().value());
+ }
+ }
+ return Either.left(true);
+ }
}
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 affafaed12..8c90501140 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
@@ -17,29 +17,33 @@
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.common.Strings;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
@@ -77,6 +81,13 @@ public class InterfaceOperationValidation {
return Either.right(descriptionResponseEither.right().value());
}
+ Either<Boolean, ResponseFormat> inputPropertyExistInComponent = validateInputPropertyExistInComponent(interfaceOperation,
+ component.getInputs(), responseFormatManager);
+ if(inputPropertyExistInComponent.isRight()) {
+ return Either.right(inputPropertyExistInComponent.right().value());
+
+ }
+
Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
responseFormatManager);
if(inputParametersResponse.isRight()) {
@@ -109,14 +120,14 @@ public class InterfaceOperationValidation {
}
Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
- component, isUpdate, responseFormatManager );
+ component, isUpdate );
if(operationTypeUniqueResponse.isRight()) {
return Either.right(operationTypeUniqueResponse.right().value());
}
if (!operationTypeUniqueResponse.left().value()) {
LOGGER.error("Interface Operation type {} already in use ", interfaceOperation.getName());
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
+ .INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -128,7 +139,7 @@ public class InterfaceOperationValidation {
LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain" +
"Special character, space, numbers and should not be greater than 200 characters", operationType);
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_INVALID, operationType);
+ .INTERFACE_OPERATION_NAME_INVALID, operationType);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -139,7 +150,7 @@ public class InterfaceOperationValidation {
if (StringUtils.isEmpty(operationType)) {
LOGGER.error("Interface Operation type is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_MANDATORY);
+ .INTERFACE_OPERATION_NAME_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -150,7 +161,7 @@ public class InterfaceOperationValidation {
if (!Strings.isNullOrEmpty(description) && description.length() > DESCRIPTION_MAX_LENGTH) {
LOGGER.error("Interface Operation description {} is invalid, maximum 200 characters allowed", description);
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH);
+ .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, description);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -163,14 +174,12 @@ public class InterfaceOperationValidation {
private Either<Boolean, ResponseFormat> validateOperationTypeUnique(
Operation interfaceOperation,
org.openecomp.sdc.be.model.Component component,
- boolean isUpdate,
- ResponseFormatManager responseFormatManager) {
+ boolean isUpdate) {
boolean isOperationTypeUnique = false;
- Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = component.getInterfaces();
if(interfaceDefinitionMap.isEmpty()){
- isOperationTypeUnique = true;
- return Either.left(isOperationTypeUnique);
+ return Either.left(true);
}
Collection<Operation> allOperations = interfaceDefinitionMap.values().stream()
@@ -178,8 +187,7 @@ public class InterfaceOperationValidation {
.map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(allOperations)){
- isOperationTypeUnique = true;
- return Either.left(isOperationTypeUnique);
+ return Either.left(true);
}
Map<String, String> operationTypes = new HashMap<>();
@@ -236,8 +244,6 @@ public class InterfaceOperationValidation {
}
return Either.left(Boolean.TRUE);
}
-
-
private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
@@ -277,17 +283,32 @@ public class InterfaceOperationValidation {
.anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
- private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) {
- boolean isOperationTypeUnique = false;
- Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName()))
- .map(Map.Entry::getKey).findAny();
- if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){
- isOperationTypeUnique = true;
+ private Either<Boolean, ResponseFormat> validateInputPropertyExistInComponent(Operation operation,
+ List<InputDefinition> inputs,
+ ResponseFormatManager responseFormatManager) {
+ ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
+ if (inputDefinitionListDataDefinition == null) {
+ return Either.left(Boolean.TRUE);
+ }
+ List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition();
+
+ for(OperationInputDefinition inputDefinition : inputListToscaDataDefinition ) {
+ if(!validateInputExistsInComponent(inputDefinition, inputs)) {
+ String missingPropertyName = inputDefinition.getInputId().contains(".") ? inputDefinition.getInputId().substring(inputDefinition.getInputId().indexOf(".") + 1) : inputDefinition.getInputId();
+ LOGGER.error("Interface operation input property {} not found in component input properties", missingPropertyName);
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, missingPropertyName);
+ return Either.right(inputResponse);
+ }
}
- return isOperationTypeUnique;
+ return Either.left(Boolean.TRUE);
+ }
+
+ private boolean validateInputExistsInComponent(OperationInputDefinition input,
+ List<InputDefinition> inputs) {
+ return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId()));
}
- protected ResponseFormatManager getResponseFormatManager() {
+ private ResponseFormatManager getResponseFormatManager() {
return ResponseFormatManager.getInstance();
}
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 f0cdf3ec70..bdbf20a2b7 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
@@ -40,7 +40,7 @@ public class InterfaceUIDataConverter {
.map(interfaceOperationParamDataDefinition -> new OperationInputDefinition(
interfaceOperationParamDataDefinition.getName(),
interfaceOperationParamDataDefinition.getProperty(),
- interfaceOperationParamDataDefinition.getMandatory(),
+ interfaceOperationParamDataDefinition.getMandatory() == null ? false : interfaceOperationParamDataDefinition.getMandatory(),
interfaceOperationParamDataDefinition.getType()
)).collect(Collectors.toList());
inputList.forEach(inputs::add);
@@ -70,7 +70,6 @@ public class InterfaceUIDataConverter {
}
public static InterfaceOperationDataDefinition convertOperationDataToInterfaceData(Operation operationData){
-
ListDataDefinition<OperationInputDefinition> inputs = operationData.getInputs();
List<InterfaceOperationParamDataDefinition> inputParamList = inputs.getListToscaDataDefinition().stream()
.map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(),
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index a3731dd9b9..899a7b1cb8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -339,6 +339,9 @@ public class UiComponentDataConverter {
UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
+ case INTERFACES:
+ setInterfaces(service, dataTransfer);
+ break;
default:
setUiTranferDataByFieldName(dataTransfer, service, fieldName);
}
@@ -362,6 +365,13 @@ public class UiComponentDataConverter {
}
}
+ private void setInterfaces(Service service, UiServiceDataTransfer dataTransfer) {
+ if (service.getInterfaces() == null) {
+ dataTransfer.setInterfaces(new HashMap<>());
+ } else {
+ dataTransfer.setInterfaces(service.getInterfaces());
+ }
+ }
public static UiComponentMetadata convertToUiComponentMetadata(Component component) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
index 3e43dd7a91..815f9763f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
@@ -49,21 +49,21 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/resources/{resourceId}/interfaceOperations")
+@Path("/v1/catalog/{componentType}/{componentId}/interfaceOperations")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Api(value = "Interface Operation", description = "Interface Operation Servlet")
@Singleton
-public class ResourceInterfaceOperationServlet extends AbstractValidationsServlet {
+public class InterfaceOperationServlet extends AbstractValidationsServlet {
- private static final Logger log = LoggerFactory.getLogger(ResourceInterfaceOperationServlet.class);
+ private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@@ -76,10 +76,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 409, message = "Interface Operation already exist")})
public Response createInterfaceOperation(
@ApiParam(value = "Interface Operation to create", required = true) String data,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component type") @PathParam("componentType") String componentType,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, resourceId, request, userId, false);
+ return createOrUpdate(data, componentType ,componentId, request, userId, false);
}
@PUT
@@ -92,10 +93,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response updateInterfaceOperation(
@ApiParam(value = "Interface Operation to update", required = true) String data,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component type") @PathParam("componentType") String componentType,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, resourceId, request, userId, true);
+ return createOrUpdate(data, componentType,componentId, request, userId, true);
}
@DELETE
@@ -108,10 +110,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response deleteInterfaceOperation(
@ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(interfaceOperationId, resourceId, request, userId);
+ return delete(interfaceOperationId, componentId, request, userId);
}
@GET
@@ -124,14 +126,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response getInterfaceOperation(
@ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return get(interfaceOperationId, resourceId, request, userId);
+ return get(interfaceOperationId, componentId, request, userId);
}
- private Response get (String interfaceOperationId, String resourceId, HttpServletRequest request, String userId){
+ private Response get (String interfaceOperationId, String componentId, HttpServletRequest request, String userId){
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
@@ -140,10 +142,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start get request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
+ Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
log.error("failed to get interface operation");
return buildErrorResponse(actionResponse.right().value());
@@ -154,13 +156,13 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
}
catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations");
- log.error("get resource interface operations failed with exception", e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations");
+ log.error("get component interface operations failed with exception", e);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
- private Response delete (String interfaceOperationId, String resourceId, HttpServletRequest
+ private Response delete (String interfaceOperationId, String componentId, HttpServletRequest
request, String userId){
ServletContext context = request.getSession().getServletContext();
@@ -171,10 +173,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start delete request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
+ Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
log.error("failed to delete interface operation");
return buildErrorResponse(actionResponse.right().value());
@@ -191,7 +193,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
}
- private Response createOrUpdate (String data, String resourceId, HttpServletRequest request, String userId, boolean isUpdate) {
+ private Response createOrUpdate (String data, String componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate) {
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
@@ -200,15 +202,15 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start create or update request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Operation operation = getMappedOperationData(data, isUpdate, modifier);
+ Operation operation = getMappedOperationData(data, isUpdate, modifier, ComponentTypeEnum.findByParamName(componentType));
Either<Operation, ResponseFormat> actionResponse ;
if (isUpdate) {
- actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, operation, modifier, true);
+ actionResponse = businessLogic.updateInterfaceOperation(componentIdLower, operation, modifier, true);
} else {
- actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, operation, modifier, true);
+ actionResponse = businessLogic.createInterfaceOperation(componentIdLower, operation, modifier, true);
}
if (actionResponse.isRight()) {
@@ -227,9 +229,9 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
}
- private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user){
- Either<UiResourceDataTransfer, ResponseFormat> uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE);
- Optional<InterfaceOperationDataDefinition> opDef = uiResourceEither.left().value().getInterfaceOperations().values().stream().findFirst();
+ private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user, ComponentTypeEnum componentTypeEnum){
+ Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ Optional<InterfaceOperationDataDefinition> opDef = uiComponentEither.left().value().getInterfaceOperations().values().stream().findFirst();
InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition();
if(opDef.isPresent()) {
interfaceOperationDataDefinition = opDef.get();
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 e5e5f1648a..d62c2c64eb 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
@@ -561,7 +561,7 @@ public class ToscaExportHandler {
List<InputDefinition> inputDef = component.getInputs();
Map<String, ToscaProperty> inputs = new HashMap<>();
-
+ addInterfaceDefinitionElement(component, toscaNodeType);
if (inputDef != null) {
inputDef.forEach(i -> {
ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
@@ -569,7 +569,6 @@ public class ToscaExportHandler {
});
if (!inputs.isEmpty()) {
toscaNodeType.setProperties(inputs);
- addInterfaceDefinitionElement(component, toscaNodeType);
}
}
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
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 75a65f95da..5370a7849e 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
@@ -18,29 +18,25 @@ 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;
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;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Product;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
-/**
- * @author KATYR
- * @since March 20, 2018
- */
public class InterfacesOperationsToscaUtil {
@@ -50,7 +46,6 @@ public class InterfacesOperationsToscaUtil {
private static final String DEFAULT = "default";
private static final String DEFAULT_HAS_UNDERSCORE = "_default";
private static final String DOT = ".";
- private static final String DEFAULT_INPUT_TYPE = "string";
private static final String SELF = "SELF";
private static final String GET_PROPERTY = "get_property";
private static final String DEFAULTP = "defaultp";
@@ -65,16 +60,11 @@ public class InterfacesOperationsToscaUtil {
* @return the added element
*/
public static Map<String, Object> addInterfaceTypeElement(Component component) {
- Map<String, Object> toscaInterfaceTypes = new HashMap<>();
- if ((component instanceof Service) || (component instanceof Product)) {
- return null;
- }
-
- final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
- if (MapUtils.isEmpty(interfaces)) {
+ if (component instanceof Product) {
return null;
}
-
+ final Map<String, InterfaceDefinition> interfaces = component.getInterfaces();
+ Map<String, Object> toscaInterfaceTypes = new HashMap<>();
for (InterfaceDefinition interfaceDefinition : interfaces.values()) {
ToscaInterfaceNodeType toscaInterfaceType = new ToscaInterfaceNodeType();
toscaInterfaceType.setDerived_from(DERIVED_FROM_STANDARD_INTERFACE);
@@ -86,8 +76,6 @@ public class InterfacesOperationsToscaUtil {
toscaOperations.put(operationEntry.getValue().getName(),
null); //currently not initializing any of the operations' fields as it is not needed
}
-
-
toscaInterfaceType.setOperations(toscaOperations);
Map<String, Object> interfacesAsMap = getObjectAsMap(toscaInterfaceType);
Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS_KEY);
@@ -95,7 +83,7 @@ public class InterfacesOperationsToscaUtil {
toscaInterfaceTypes.put(interfaceDefinition.getToscaResourceName(), interfacesAsMap);
}
- return toscaInterfaceTypes;
+ return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null;
}
/**
@@ -105,16 +93,14 @@ public class InterfacesOperationsToscaUtil {
* @param nodeType to which the interfaces element will be added
*/
public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) {
- Map<String, Object> toscaInterfaceDefinitions = new HashMap<>();
-
- if ((component instanceof Service) || (component instanceof Product)) {
+ if (component instanceof Product) {
return;
}
-
- final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
+ final Map<String, InterfaceDefinition> interfaces = component.getInterfaces();
if (MapUtils.isEmpty(interfaces)) {
return;
}
+ Map<String, Object> toscaInterfaceDefinitions = new HashMap<>();
for (InterfaceDefinition interfaceDefinition : interfaces.values()) {
ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition();
final String toscaResourceName = interfaceDefinition.getToscaResourceName();
@@ -133,7 +119,7 @@ public class InterfacesOperationsToscaUtil {
toscaOperation.setImplementation(operationArtifactPath);
}
toscaOperation.setDescription(operationEntry.getValue().getDescription());
- fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType);
+ fillToscaOperationInputs(operationEntry.getValue(), toscaOperation);
toscaOperations.put(operationEntry.getValue().getName(), toscaOperation);
}
@@ -145,7 +131,9 @@ public class InterfacesOperationsToscaUtil {
interfaceDefAsMap.putAll(operationsMap);
toscaInterfaceDefinitions.put(getLastPartOfName(toscaResourceName), interfaceDefAsMap);
}
- nodeType.setInterfaces(toscaInterfaceDefinitions);
+ if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) {
+ nodeType.setInterfaces(toscaInterfaceDefinitions);
+ }
}
/***
@@ -180,8 +168,7 @@ public class InterfacesOperationsToscaUtil {
}
private static void fillToscaOperationInputs(OperationDataDefinition operation,
- ToscaLifecycleOperationDefinition toscaOperation,
- ToscaNodeType nodeType) {
+ ToscaLifecycleOperationDefinition toscaOperation) {
if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) {
toscaOperation.setInputs(null);
return;
@@ -192,22 +179,15 @@ public class InterfacesOperationsToscaUtil {
ToscaProperty toscaInput = new ToscaProperty();
toscaInput.setDescription(input.getDescription());
String mappedPropertyName = getLastPartOfName(input.getInputId());
- toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType));
+ toscaInput.setType(input.getType());
toscaInput.setDefaultp(createDefaultValue(mappedPropertyName));
+ toscaInput.setRequired(input.isRequired());
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<String, List<String>> createDefaultValue(String propertyName) {
Map<String, List<String>> getPropertyMap = new HashMap<>();
List<String> values = new ArrayList<>();
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 26fee5b28e..6156090df3 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2025,50 +2025,50 @@ errors:
messageId: "SVC4694"
}
#---------SVC4695-----------------------------
-# %1 - Interface operation type
- INTERFACE_OPERATION_TYPE_ALREADY_IN_USE: {
+# %1 - Interface Operation Name
+ INTERFACE_OPERATION_NAME_ALREADY_IN_USE: {
code: 400,
- message: "Error: Interface Operation type %1 already in use",
+ message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4695"
}
#---------SVC4696-----------------------------
-# %1 - workflow operation type
- INTERFACE_OPERATION_TYPE_INVALID: {
+# %1 - Interface Operation Name
+ INTERFACE_OPERATION_NAME_INVALID: {
code: 400,
- message: "Error: Interface Operation type %1 is Invalid, Operation type should not contain
- special character, space, numbers and should not be greater than 200 characters ",
+ message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space, numbers and should not be greater than 200 characters.",
messageId: "SVC4696"
}
#---------SVC4697-----------------------------
- INTERFACE_OPERATION_TYPE_MANDATORY: {
+ INTERFACE_OPERATION_NAME_MANDATORY: {
code: 404,
- message: "Error: Interface Operation type is mandatory, Operation type can't be empty",
+ message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
messageId: "SVC4697"
}
#---------SVC4698-----------------------------
-# %1 - workflow operation description
+# %1 - Interface Operation description
INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH: {
code: 400,
- message: "Error: Interface Operation description %1 is invalid, maximum 200 characters allowed",
+ message: "Error: Interface Operation description '%1' is invalid, maximum 200 characters allowed.",
messageId: "SVC4698"
}
#---------SVC4699-----------------------------
+# %1 - Interface Operation input parameter name
INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE: {
code: 400,
- message: "Error: Interface Operation input parameter names %1 already in use",
+ message: "Error: Interface Operation input parameter name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4699"
}
#---------SVC4700-----------------------------
- INTERFACE_OPERATION_OUTPUT_NAME_INVALID: {
- code: 400,
- message: "Error: Interface Operation output parameters invalid, should be unique and mandatory",
- messageId: "SVC4700"
+ INTERFACE_OPERATION_INPUT_NAME_MANDATORY: {
+ code: 404,
+ message: "Error: Interface operation input parameter name should not be empty.",
+ messageId: "SVC4700"
}
#---------SVC4701-----------------------------
# %1 - resource Id
INTERFACE_OPERATION_NOT_FOUND: {
code: 404,
- message: "Error: Interface operations not found in the resource %1",
+ message: "Error: Interface operation not found in the resource '%1'.",
messageId: "SVC4701"
}
#---------SVC4702-----------------------------
@@ -2127,10 +2127,24 @@ errors:
message: "Error: CSAR packaging failed for %1 %2.",
messageId: "SVC4706"
}
-#---------SVC46708-----------------------------
- INTERFACE_OPERATION_INPUT_NAME_MANDATORY: {
- code: 404,
- message: "Error: Interface operation input parameter name should not be empty",
- messageId: "SVC46707"
- }
+#---------SVC4704-----------------------------
+# %1 - Interface Operation input property name
+ INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT: {
+ code: 404,
+ message: "Error: Interface operation input parameter property '%1' not found in component input properties.",
+ messageId: "SVC4704"
+ }
+#---------SVC4705-----------------------------
+# %1 - Interface Operation output parameter name
+ INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE: {
+ code: 400,
+ message: "Error: Interface Operation output parameter name '%1' already in use, Your current changes will not be saved.",
+ messageId: "SVC4705"
+ }
+#---------SVC4706-----------------------------
+ INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY: {
+ code: 404,
+ message: "Error: Interface operation output parameter name should not be empty.",
+ messageId: "SVC4706"
+ }
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
index eb17d56154..e8a698fec1 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
@@ -40,7 +40,6 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
-import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -56,7 +55,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.Resource;
@@ -83,42 +81,37 @@ import org.springframework.web.context.WebApplicationContext;
public class InterfaceOperationBusinessLogicTest {
- public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
- public static final String RESOURCE_SUBCATEGORY = "Router";
-
- private String resourceId = "resourceId1";
- private String operationId = "uniqueId1";
- Resource resourceUpdate;
- Operation operation;
-
- public static final String RESOURCE_NAME = "My-Resource_Name with space";
-
- final ServletContext servletContext = Mockito.mock(ServletContext.class);
- IElementOperation mockElementDao;
- TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
- UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
- ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
- NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
- TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
- final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
- final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
- WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- UserValidations userValidations = Mockito.mock(UserValidations.class);
- WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
- ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
- InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
- InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
-
- ResponseFormatManager responseManager = null;
- GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
- User user = null;
- Resource resourceResponse = null;
- ComponentsUtils componentsUtils;
- ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
- private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
+ private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
+ private static final String RESOURCE_SUBCATEGORY = "Router";
+
+ private final String resourceId = "resourceId1";
+ private final String operationId = "uniqueId1";
+ private Operation operation;
+
+ private static final String RESOURCE_NAME = "My-Resource_Name with space";
+
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
+ private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
+ private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
+ private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
+ private final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
+ private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private final UserValidations userValidations = Mockito.mock(UserValidations.class);
+ private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
+ private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+ private final InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
+
+ private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ private User user = null;
+ private final ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
@InjectMocks
+ private
InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic();
@Before
@@ -132,10 +125,10 @@ public class InterfaceOperationBusinessLogicTest {
String appConfigDir = "src/test/resources/config/catalog-be";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
- componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
+ ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
// Elements
- mockElementDao = new ElementOperationMock();
+ IElementOperation mockElementDao = new ElementOperationMock();
// User data and management
user = new User();
@@ -172,23 +165,22 @@ public class InterfaceOperationBusinessLogicTest {
when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
// createResource
- resourceResponse = createResourceObject(true);
+ Resource resourceResponse = createResourceObject(true);
Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
- Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
//TODO Remove if passes
/*when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);*/
- Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
//InterfaceOperation
when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true));
when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
- when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
- when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
- when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME)));
+ when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
@@ -210,7 +202,6 @@ public class InterfaceOperationBusinessLogicTest {
setCanWorkOnResource(resourceCsar);
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
- responseManager = ResponseFormatManager.getInstance();
}
@Test
@@ -260,37 +251,13 @@ public class InterfaceOperationBusinessLogicTest {
private void validateUserRoles(Role... roles) {
List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
- }
+ }
- private Resource setCanWorkOnResource(Resource resource) {
+ private void setCanWorkOnResource(Resource resource) {
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setLastUpdaterUserId(user.getUserId());
- return resource;
- }
-
- private Resource setUpResourceMock(){
- Resource resource = new Resource();
- resource.setUniqueId(resourceId);
- resource.setName(RESOURCE_NAME);
- resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
- resource.setDescription("My short description");
- resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME));
-
- List<InputDefinition> inputDefinitionList = new ArrayList<>();
- inputDefinitionList.add(createInputDefinition("uniqueId1"));
- resource.setInputs(inputDefinitionList);
-
- return resource;
}
- private InputDefinition createInputDefinition(String inputId) {
- InputDefinition inputDefinition = new InputDefinition();
- inputDefinition.setInputId(inputId);
- inputDefinition.setDescription("Input Description");
-
- return inputDefinition;
-
- }
private Resource createResourceForInterfaceOperation() {
Resource resource = new Resource();
resource.setUniqueId(resourceId);
@@ -306,11 +273,11 @@ public class InterfaceOperationBusinessLogicTest {
resource.setName(RESOURCE_NAME);
resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
resource.setDescription("My short description");
- List<String> tgs = new ArrayList<String>();
+ List<String> tgs = new ArrayList<>();
tgs.add("test");
tgs.add(resource.getName());
resource.setTags(tgs);
- List<String> template = new ArrayList<String>();
+ List<String> template = new ArrayList<>();
template.add("Root");
resource.setDerivedFrom(template);
resource.setVendorName("Motorola");
@@ -324,7 +291,6 @@ public class InterfaceOperationBusinessLogicTest {
if (afterCreate) {
resource.setName(resource.getName());
resource.setVersion("0.1");
-
resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
resource.setCreatorUserId(user.getUserId());
resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
@@ -338,11 +304,11 @@ public class InterfaceOperationBusinessLogicTest {
resource.setName(RESOURCE_NAME);
resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
resource.setDescription("My short description");
- List<String> tgs = new ArrayList<String>();
+ List<String> tgs = new ArrayList<>();
tgs.add("test");
tgs.add(resource.getName());
resource.setTags(tgs);
- List<String> template = new ArrayList<String>();
+ List<String> template = new ArrayList<>();
template.add("Root");
resource.setDerivedFrom(template);
resource.setVendorName("Motorola");
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 d41294b4c2..6fe2f1308c 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
@@ -21,8 +21,11 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
import fj.data.Either;
+
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
@@ -35,20 +38,23 @@ 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.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
public class InterfaceOperationValidationTest {
- private Resource resource = setUpResourceMock();
- ResponseFormatManager responseFormatManagerMock;
+ private final Component component = setUpComponentMock();
+ private ResponseFormatManager responseFormatManagerMock;
- InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
- ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
- ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
+ private final InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest();
+ private final ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ private final ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
@Before
public void init() {
@@ -67,7 +73,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"upgrade");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@@ -78,10 +84,10 @@ public class InterfaceOperationValidationTest {
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",
+ "with web, data access (relational and NoSQL data stores), cloud, or messaging support",
new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -95,7 +101,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList, "");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -107,7 +113,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"input2");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -119,7 +125,7 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"CREATE");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -132,9 +138,9 @@ public class InterfaceOperationValidationTest {
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");
+ "with web, data access (relational and NoSQL data stores), cloud, or messaging support");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -151,7 +157,7 @@ public class InterfaceOperationValidationTest {
operationOutputDefinitionList,"create");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -166,12 +172,12 @@ public class InterfaceOperationValidationTest {
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
- public void testInterfaceOperationeInputParamNameEmpty() {
+ public void testInterfaceOperationInputParamNameEmpty() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" "));
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
@@ -181,7 +187,7 @@ public class InterfaceOperationValidationTest {
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, resource, false);
+ .validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isRight());
}
@@ -191,10 +197,33 @@ public class InterfaceOperationValidationTest {
return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name));
}
- private Resource setUpResourceMock(){
- Resource resource = new Resource();
- resource.setInterfaces(createMockInterfaceDefinition());
- return resource;
+ private Component setUpComponentMock(){
+ Component component = new Resource();
+
+ List<InputDefinition> inputs = new ArrayList<>();
+ InputDefinition inputDefinition = new InputDefinition();
+ InputDefinition inputDefinition1 = new InputDefinition();
+
+ List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>();
+ ComponentInstanceInput componentInstanceInput1 = new ComponentInstanceInput();
+ componentInstanceInput1.setComponentInstanceName("componentInstance1");
+ componentInstanceInput1.setUniqueId("inputId1");
+ ComponentInstanceInput componentInstanceInput2 = new ComponentInstanceInput();
+ componentInstanceInput2.setComponentInstanceName("componentInstance2");
+ componentInstanceInput2.setUniqueId("inputId2");
+
+ componentInstanceInputs.add(componentInstanceInput1);
+ componentInstanceInputs.add(componentInstanceInput2);
+
+ inputDefinition.setUniqueId("inputId1");
+ inputDefinition.setInputs(componentInstanceInputs);
+ inputDefinition1.setUniqueId("uniqueId3");
+
+ inputs.add(inputDefinition);
+ inputs.add(inputDefinition1);
+ component.setInputs(inputs);
+ component.setInterfaces(createMockInterfaceDefinition());
+ return component;
}
private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
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 b158ddf5da..0c02e71bd2 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
@@ -1,38 +1,104 @@
package org.openecomp.sdc.be.datamodel.utils;
-import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IO_INPUT_PARAMETERS;
-
-import java.util.LinkedList;
-
+import org.junit.Assert;
import org.junit.Test;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
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;
+import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationInputDefinition;
+import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationOutputDefinition;
+
public class InterfaceUIDataConverterTest {
@Test
- public void testConvertInterfaceDataToOperationData() throws Exception {
- InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition();
+ public void testConvertInterfaceDataToOperationData() {
+ InterfaceOperationDataDefinition interfaceOperation = createIODD("test",
+ "test description",
+ createParamDataList("inpName", "property", true, "String"),
+ createParamDataList("OutName", null, true, "String"),
+ "workflowId",
+ "workflowVersionId");
+ Operation result;
+ result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void testConvertInterfaceDataToOperationDataWithoutMandatory() {
+ ListDataDefinition<InterfaceOperationParamDataDefinition> iopd = new ListDataDefinition<>();
+ iopd.add(createParamData("test", "property", "String"));
+ InterfaceOperationDataDefinition interfaceOperation = createIODD("test",
+ "test description", iopd, iopd,
+ "workflowId",
+ "workflowVersionId");
Operation result;
+ result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
+ }
- // default test
+ @Test
+ public void testConvertInterfaceDataToOperationDataWithoutOptionalFields() {
+ InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition();
+ interfaceOperation.setOperationType("operationType");
+ Operation result;
result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation);
+ Assert.assertNotNull(result);
}
@Test
- public void testConvertOperationDataToInterfaceData() throws Exception {
+ public void testConvertOperationDataToInterfaceData() {
Operation operationData = new Operation();
InterfaceOperationDataDefinition result;
ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ inputs.add(createMockOperationInputDefinition("Inp1"));
ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>();
+ outputs.add(createMockOperationOutputDefinition("out1"));
operationData.setInputs(inputs);
operationData.setOutputs(outputs);
operationData.setImplementation(new ArtifactDataDefinition());
- // default test
result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData);
+ Assert.assertNotNull(result);
+ }
+
+ private InterfaceOperationDataDefinition createIODD(String operationType, String description,
+ ListDataDefinition<InterfaceOperationParamDataDefinition> inputParams,
+ ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams,
+ String workflowId,
+ String workflowVersionId) {
+ InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition();
+ interfaceOperation.setOperationType(operationType);
+ interfaceOperation.setDescription(description);
+ interfaceOperation.setInputParams(inputParams);
+ interfaceOperation.setOutputParams(outputParams);
+ interfaceOperation.setWorkflowId(workflowId);
+ interfaceOperation.setWorkflowVersionId(workflowVersionId);
+ return interfaceOperation;
+ }
+
+ private InterfaceOperationParamDataDefinition createParamData(String name, String property, boolean mandatory, String type) {
+ InterfaceOperationParamDataDefinition definition = createParamData(name, property, type);
+ definition.setMandatory(mandatory);
+ return definition;
+ }
+
+ private InterfaceOperationParamDataDefinition createParamData(String name, String property, String type) {
+ InterfaceOperationParamDataDefinition definition = new InterfaceOperationParamDataDefinition();
+ definition.setName(name);
+ definition.setProperty(property);
+ definition.setType(type);
+ return definition;
}
+
+ private ListDataDefinition<InterfaceOperationParamDataDefinition> createParamDataList(String name,
+ String property, boolean mandatory, String type) {
+ ListDataDefinition<InterfaceOperationParamDataDefinition> list = new ListDataDefinition<>();
+ list.add(createParamData(name, property, mandatory, type));
+ return list;
+ }
+
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
index bebfbd19d8..7a88d0a9d3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
@@ -16,6 +16,12 @@
package org.openecomp.sdc.be.tosca.utils;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -27,31 +33,41 @@ import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.tosca.ToscaRepresentation;
+import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
-
-import java.util.HashMap;
-import java.util.Map;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
public class InterfacesOperationsToscaUtilTest {
+ private static final String MAPPED_PROPERTY_NAME = "mapped_property";
+ private static final String INPUT_NAME_PREFIX = "input_";
+ private static final String NODE_TYPE_NAME = "test";
+ private String[] inputTypes = {"string", "integer", "float", "boolean"};
+ private static ObjectMapper mapper;
+
@BeforeClass
public static void setUp() {
new DummyConfigurationManager();
+ mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
- @Test()
- public void addInterfaceTypeElement() {
+
+ @Test
+ public void addInterfaceTypeElementToResource() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setToscaResourceName("interface.types.test_resource_name");
addOperationsToInterface(addedInterface, 5, 3, true);
final String interfaceType = "normalizedComponentName-interface";
- ((Resource) component).setInterfaces(new HashMap<>());
- ((Resource) component).getInterfaces().put(interfaceType, addedInterface);
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
final Map<String, Object> interfaceTypeElement =
InterfacesOperationsToscaUtil.addInterfaceTypeElement(component);
@@ -65,7 +81,29 @@ public class InterfacesOperationsToscaUtilTest {
}
@Test
- public void addInterfaceDefinitionElement() {
+ public void addInterfaceTypeElementToService() {
+ Component component = new Service();
+ component.setNormalizedName("normalizedServiceComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setToscaResourceName("interface.types.test_service_name");
+ addOperationsToInterface(addedInterface, 5, 3, true);
+ final String interfaceType = "normalizedServiceComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ final Map<String, Object> interfaceTypeElement =
+ InterfacesOperationsToscaUtil.addInterfaceTypeElement(component);
+
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
+ ToscaTemplate template = new ToscaTemplate("testService");
+ template.setInterface_types(interfaceTypeElement);
+ final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
+
+ Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
+ Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_service_name"));
+ }
+
+ @Test
+ public void addInterfaceDefinitionElementToResource() {
Component component = new Resource();
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
@@ -73,25 +111,58 @@ public class InterfacesOperationsToscaUtilTest {
addOperationsToInterface(addedInterface, 3, 2, true);
final String interfaceType = "normalizedComponentName-interface";
- ((Resource) component).setInterfaces(new HashMap<>());
- ((Resource) component).getInterfaces().put(interfaceType, addedInterface);
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
- ToscaTemplate template = new ToscaTemplate("test");
+ ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- nodeTypes.put("test", nodeType);
+ nodeTypes.put(NODE_TYPE_NAME, nodeType);
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceName:"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("inputs:"));
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("naming_function_"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName"));
+ String mainYaml = toscaRepresentation.getMainYaml();
+ Assert.assertFalse(mainYaml.contains("operations"));
+ Assert.assertTrue(mainYaml.contains("resourceName:"));
+ Assert.assertTrue(mainYaml.contains("inputs:"));
+ validateOperationInputs(mainYaml);
+ Assert.assertFalse(mainYaml.contains("defaultp"));
+ Assert.assertTrue(mainYaml.contains("has description"));
+ Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
+ Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName"));
+ }
+
+ @Test
+ public void addInterfaceDefinitionElementToService() {
+ Component component = new Service();
+ component.setNormalizedName("normalizedServiceComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setToscaResourceName("com.some.service.or.other.serviceName");
+
+ addOperationsToInterface(addedInterface, 3, 2, true);
+ final String interfaceType = "normalizedServiceComponentName-interface";
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
+ ToscaNodeType nodeType = new ToscaNodeType();
+ InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
+
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
+ ToscaTemplate template = new ToscaTemplate("testService");
+ Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
+ nodeTypes.put(NODE_TYPE_NAME, nodeType);
+ template.setNode_types(nodeTypes);
+ final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
+ String mainYaml = toscaRepresentation.getMainYaml();
+ Assert.assertFalse(mainYaml.contains("operations"));
+ Assert.assertTrue(mainYaml.contains("serviceName:"));
+ Assert.assertTrue(mainYaml.contains("inputs:"));
+ validateOperationInputs(mainYaml);
+ Assert.assertFalse(mainYaml.contains("defaultp"));
+ Assert.assertTrue(mainYaml.contains("has description"));
+ Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
+ Assert.assertTrue(mainYaml.contains("com.some.service.or.other.serviceName"));
}
@Test
@@ -103,8 +174,8 @@ public class InterfacesOperationsToscaUtilTest {
addOperationsToInterface(addedInterface, 3, 3, false);
final String interfaceType = "normalizedComponentName-interface";
- ((Resource) component).setInterfaces(new HashMap<>());
- ((Resource) component).getInterfaces().put(interfaceType, addedInterface);
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType);
@@ -116,7 +187,7 @@ public class InterfacesOperationsToscaUtilTest {
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("input_"));
+ Assert.assertFalse(toscaRepresentation.getMainYaml().contains(INPUT_NAME_PREFIX));
Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp"));
Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceNameNoInputs:"));
Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description"));
@@ -146,17 +217,48 @@ public class InterfacesOperationsToscaUtilTest {
private ListDataDefinition<OperationInputDefinition> createInputs(int numOfInputs) {
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
for (int i = 0; i < numOfInputs; i++) {
- operationInputDefinitionList.add(createMockOperationInputDefinition("input_" + i,
- java.util.UUID.randomUUID().toString() + "." + "naming_function_" + i));
+ operationInputDefinitionList.add(createMockOperationInputDefinition(
+ INPUT_NAME_PREFIX + inputTypes[i] + "_" + i,
+ java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME, i));
}
return operationInputDefinitionList;
}
- private OperationInputDefinition createMockOperationInputDefinition(String name, String id) {
+ private OperationInputDefinition createMockOperationInputDefinition(String name, String id, int index) {
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
operationInputDefinition.setName(name);
operationInputDefinition.setInputId(id);
+ operationInputDefinition.setType(inputTypes[index]);
+ operationInputDefinition.setRequired(index % 2 == 0);
return operationInputDefinition;
}
+
+ private void validateOperationInputs(String mainYaml) {
+ String nodeTypeKey = NODE_TYPE_NAME + ":";
+ String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(),
+ mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length());
+ YamlToObjectConverter objectConverter = new YamlToObjectConverter();
+ ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class);
+ Map<String, Object> interfaces = toscaNodeType.getInterfaces();
+ for (Object interfaceVal : interfaces.values()) {
+ Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceVal, Map.class);
+ for (Object operationVal : interfaceDefinition.values()) {
+ if (operationVal instanceof Map) {
+ validateOperationInputDefinition(operationVal);
+ }
+ }
+ }
+ }
+
+ private void validateOperationInputDefinition(Object operationVal) {
+ ToscaLifecycleOperationDefinition operation =
+ mapper.convertValue(operationVal, ToscaLifecycleOperationDefinition.class);
+ Map<String, ToscaProperty> inputs = operation.getInputs();
+ for (Map.Entry<String, ToscaProperty> inputEntry : inputs.entrySet()) {
+ Assert.assertEquals(inputEntry.getKey().split("_")[1], inputEntry.getValue().getType());
+ Boolean expectedIsRequired = Integer.parseInt(inputEntry.getKey().split("_")[2]) % 2 == 0;
+ Assert.assertEquals(expectedIsRequired, inputEntry.getValue().getRequired());
+ }
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
index 76e73bab75..10acd69a79 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
@@ -51,13 +51,13 @@ public class InterfaceOperationTestUtils {
return operation;
}
- public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) {
+ public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceName) {
Map<String, Operation> operationMap = createMockOperationMap();
return createInterface("int1", "Interface 1",
- "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap);
+ "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap);
}
- public static Operation mockOperationToReturn(String resourceNamme) {
+ public static Operation mockOperationToReturn() {
return createMockOperation();
}
@@ -93,6 +93,7 @@ public class InterfaceOperationTestUtils {
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
operationInputDefinition.setName(name);
operationInputDefinition.setUniqueId("uniqueId1");
+ operationInputDefinition.setInputId("inputId1");
return operationInputDefinition;
}
@@ -100,6 +101,7 @@ public class InterfaceOperationTestUtils {
OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition();
operationOutputDefinition.setName(name);
operationOutputDefinition.setUniqueId("uniqueId1");
+ operationOutputDefinition.setInputId("inputId1");
return operationOutputDefinition;
}