aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-08-09 02:57:47 +0530
committerpriyanshu <pagarwal@amdocs.com>2018-08-09 02:57:47 +0530
commitbe05c17a3824d38d37adaba1a58291f7bd919646 (patch)
tree194f67b92f2a11fe93b3b1dc5fc32d84329ed7a0 /catalog-be/src/main
parentf0811d5711a03c3b4b3e02ecdce4a2cd0f7f7a35 (diff)
Interface operations Bug Fixes
1. create and modify operation bug fix 2. Get and Delete negative use case handling 3. refactored code Change-Id: I472abb7f487cb0399e63e413e616a03143a1e2ac Issue-ID: SDC-1535 Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java215
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java174
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java32
3 files changed, 193 insertions, 228 deletions
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 803cdbf277..2f4519beb9 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,18 +18,14 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Map;
import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
+import java.util.UUID;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentParametersView;
+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;
@@ -37,7 +33,8 @@ 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.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,23 +42,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("interfaceOperationBusinessLogic")
-public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
+public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
- public static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}. ";
+ private static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}";
+ private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION = "Exception occurred during {}. Response is {}";
+ private static final String DELETE_INTERFACE_OPERATION = "deleteInterfaceOperation";
+ private static final String GET_INTERFACE_OPERATION = "getInterfaceOperation";
+ private static final String CREATE_INTERFACE_OPERATION = "createInterfaceOperation";
+ private static final String UPDATE_INTERFACE_OPERATION = "updateInterfaceOperation";
@Autowired
private InterfaceOperationValidation interfaceOperationValidation;
@Autowired
- private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
-
- @Autowired
private InterfaceOperation interfaceOperation;
- @Autowired
- private UiComponentDataConverter uiComponentDataConverter;
-
public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
this.interfaceOperation = interfaceOperation;
}
@@ -71,20 +67,16 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
public Either<Operation, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceOperationToDelete, User user, boolean lock) {
- if (StringUtils.isEmpty(interfaceOperationToDelete)){
- LOGGER.debug("Invalid parameter interfaceOperationToDelete was empty");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
- }
-
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()){
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, "deleteInterfaceOperation");
+ validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
+ Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Delete interface Operation on a storedComponent");
+ 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();
@@ -94,43 +86,49 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
+ }
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
+
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToDelete);
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
Either<Operation, StorageOperationStatus> deleteEither = interfaceOperation.deleteInterfaceOperation(componentId, interfaceDefinition, interfaceOperationToDelete);
if (deleteEither.isRight()){
- LOGGER.error("Failed to delete interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), deleteEither.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), ComponentTypeEnum.RESOURCE)));
+ LOGGER.error("Failed to delete interface operation from component {}. Response is {}", storedComponent.getName(), deleteEither.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), storedComponent.getComponentType())));
}
+
titanDao.commit();
return Either.left(deleteEither.left().value());
- } catch (Exception e){
- LOGGER.error("Exception occurred during delete interface operation : {}", e.getMessage(), e);
+ }
+ catch (Exception e){
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "delete", e);
titanDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
+ }
+ finally {
+ if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ }
}
}
public Either<Operation, ResponseFormat> getInterfaceOperation(String componentId, String interfaceOperationToGet, User user, boolean lock) {
- if (StringUtils.isEmpty(interfaceOperationToGet)){
- LOGGER.debug("Invalid parameter interfaceOperationToGet was empty");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
- }
-
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()){
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, "getInterfaceOperation");
+ validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
+ Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Get interface Operation on a storedComponent");
+ 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();
@@ -140,25 +138,29 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
- Either<Operation, StorageOperationStatus> getEither = interfaceOperation.getInterfaceOperation(interfaceDefinition, interfaceOperationToGet);
- if (getEither.isRight()){
- LOGGER.error("Failed to get interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), getEither.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getEither.right().value(), ComponentTypeEnum.RESOURCE)));
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, interfaceOperationToGet);
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
}
+
titanDao.commit();
- return Either.left(getEither.left().value());
- } catch (Exception e){
- LOGGER.error("Exception occurred during get interface operation : {}", e.getMessage(), e);
+ return Either.left(getOperationEither.left().value());
+ }
+ catch (Exception e){
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
titanDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
+ }
+ finally {
+ if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ }
}
}
@@ -171,19 +173,19 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
Either<InterfaceDefinition, StorageOperationStatus> interfaceCreateEither = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
if (interfaceCreateEither.isRight()){
StorageOperationStatus sValue = interfaceCreateEither.right().value();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue,
- ComponentTypeEnum.RESOURCE), ""));
+ LOGGER.error("Failed to get interface from component {}. Response is {}", component.getName(), sValue);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue, component.getComponentType()), ""));
}
return Either.left(interfaceCreateEither.left().value());
}
}
public Either<Operation, ResponseFormat> createInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, operation, user, false, "createInterfaceOperation", lock);
+ return createOrUpdateInterfaceOperation(componentId, operation, user, false, CREATE_INTERFACE_OPERATION, lock);
}
public Either<Operation, ResponseFormat> updateInterfaceOperation(String componentId, Operation operation, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, operation, user, true, "updateInterfaceOperation", lock);
+ return createOrUpdateInterfaceOperation(componentId, operation, user, true, UPDATE_INTERFACE_OPERATION, lock);
}
private Either<Operation, ResponseFormat> createOrUpdateInterfaceOperation(String componentId, Operation operation, User user, boolean isUpdate, String errorContext, boolean lock) {
@@ -192,18 +194,18 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
return Either.right(componentEither.right().value());
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserAndRole(storedComponent, user, errorContext);
+ validateUserExists(user.getUserId(), errorContext, true);
- InterfaceUtils.createInputOutput(operation, storedComponent.getInputs());
+ InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs());
Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
- .validateInterfaceOperations(Arrays.asList(operation), componentId, isUpdate);
+ .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate);
if(interfaceOperationValidationResponseEither.isRight()) {
return Either.right(interfaceOperationValidationResponseEither.right().value());
}
Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Create or Update interface Operation on Component");
+ 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();
@@ -211,24 +213,32 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
}
- Either<Operation, StorageOperationStatus> result;
try {
Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
- Either<InterfaceDefinition, ResponseFormat> sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
- if (sValue.isRight()) {
- return Either.right(sValue.right().value());
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
+ if (getInterfaceEither.isRight()) {
+ return Either.right(getInterfaceEither.right().value());
}
- InterfaceDefinition interfaceDefinition = sValue.left().value();
+ InterfaceDefinition interfaceDefinition = getInterfaceEither.left().value();
- if (isUpdate) {
- result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
- } else {
+ Either<Operation, StorageOperationStatus> result;
+ if(!isUpdate){
+ initNewOperation(operation);
result = interfaceOperation.addInterfaceOperation(componentId, interfaceDefinition, operation);
}
+ else {
+ Either<Operation, ResponseFormat> getOperationEither = getOperationFromInterfaceDef(storedComponent, interfaceDefinition, operation.getUniqueId());
+ if (getOperationEither.isRight()){
+ return Either.right(getOperationEither.right().value());
+ }
+ operation.setImplementation(getOperationEither.left().value().getImplementation());
+ result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation);
+ }
+
if (result.isRight()) {
titanDao.rollback();
- LOGGER.debug("Failed to add/update interface operation on component {}. Response is {}. ", storedComponent.getName(), result.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.RESOURCE)));
+ LOGGER.debug("Failed to addOrUpdate interface operation on component {}. Response is {}", storedComponent.getName(), result.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), storedComponent.getComponentType())));
}
titanDao.commit();
@@ -236,64 +246,45 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{
}
catch (Exception e) {
titanDao.rollback();
- LOGGER.error("Exception occurred during add or update interface operation property values:{}", e.getMessage(), e);
+ LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
finally {
if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
}
- private void validateUserAndRole(org.openecomp.sdc.be.model.Component component, User user, String errorContext) {
- user = validateUser(user, errorContext, component, null, false);
- validateUserRole(user, component, new ArrayList<>(), null, null);
- }
-
private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId){
Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
if (componentStorageOperationStatusEither.isRight()) {
StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
- LOGGER.error("Failed to fetch component information by component id {}, error {}", componentId, errorStatus);
+ LOGGER.error("Failed to fetch component information by component id {}, Response is {}", componentId, errorStatus);
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
}
return Either.left(componentStorageOperationStatusEither.left().value());
}
- @Override
- public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn) {
- ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResultEither = toscaOperationFacade.getToscaElement(componentId, paramsToRetuen);
-
- if (componentResultEither.isRight()) {
- if (componentResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
- LOGGER.error("Failed to found component with id {} ", componentId);
- Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, componentId));
- }
- LOGGER.error("failed to get component by id {} with filters {}", componentId, dataParamsToReturn);
- return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(componentResultEither.right().value()), ""));
+ private Either<Operation, ResponseFormat> getOperationFromInterfaceDef(
+ org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition, String operationToFetch) {
+ Optional<Map.Entry<String, Operation>> operationMap = interfaceDefinition.getOperationsMap().entrySet().stream()
+ .filter(entry -> entry.getValue().getUniqueId().equals(operationToFetch)).findAny();
+ if (!operationMap.isPresent()) {
+ LOGGER.error("Failed to get interface operation from component {}. Response is {}", component.getUniqueId(), ActionStatus.INTERFACE_OPERATION_NOT_FOUND);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, component.getUniqueId()));
}
-
- org.openecomp.sdc.be.model.Component component = componentResultEither.left().value();
- UiComponentDataTransfer dataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams((Resource)component, dataParamsToReturn);
- return Either.left(dataTransfer);
+ return Either.left(operationMap.get().getValue());
}
- @Override
- public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(
- String componentId, String userId) {
- return null;
+ private void initNewOperation(Operation operation){
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ String artifactUUID = UUID.randomUUID().toString();
+ artifactDefinition.setArtifactUUID(artifactUUID);
+ artifactDefinition.setUniqueId(artifactUUID);
+ artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType());
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE);
+ operation.setUniqueId(UUID.randomUUID().toString());
+ operation.setImplementation(artifactDefinition);
}
-
- @Override
- public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
- return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
- }
-
- @Override
- public ComponentInstanceBusinessLogic getComponentInstanceBL() {
- return componentInstanceBusinessLogic;
- }
-
}
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 9225f36a06..affafaed12 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,45 +17,43 @@
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.model.ComponentParametersView;
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.jsontitan.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
- @Autowired
- private ToscaOperationFacade toscaOperationFacade;
private static final String TYPE_VALIDATION_REGEX = "^[a-zA-Z]{1,200}$";
private static final int DESCRIPTION_MAX_LENGTH = 200;
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationValidation.class);
public Either<Boolean, ResponseFormat> validateInterfaceOperations(
- Collection<Operation> interfaceOperations,
- String resourceId, boolean isUpdate) {
+ Collection<Operation> interfaceOperations, org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
for(Operation interfaceOperation : interfaceOperations) {
Either<Boolean, ResponseFormat> interfaceOperationValidatorResponse = validateInterfaceOperation(
- interfaceOperation, resourceId, isUpdate);
+ interfaceOperation, component, isUpdate);
if (interfaceOperationValidatorResponse.isRight()) {
return interfaceOperationValidatorResponse;
}
@@ -64,29 +62,29 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> validateInterfaceOperation(Operation interfaceOperation,
- String resourceId, boolean isUpdate) {
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
Either<Boolean, ResponseFormat> interfaceOperationTypeResponse = isInterfaceOperationTypeValid(interfaceOperation,
- responseFormatManager, resourceId, isUpdate);
+ responseFormatManager, component, isUpdate);
if (interfaceOperationTypeResponse.isRight()) {
return Either.right(interfaceOperationTypeResponse.right().value());
}
Either<Boolean, ResponseFormat> descriptionResponseEither = isValidDescription(responseFormatManager,
- interfaceOperation.getDescription());
+ interfaceOperation.getDescription());
if (descriptionResponseEither.isRight()) {
return Either.right(descriptionResponseEither.right().value());
}
Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
- responseFormatManager);
+ responseFormatManager);
if(inputParametersResponse.isRight()) {
return Either.right(inputParametersResponse.right().value());
}
Either<Boolean, ResponseFormat> outputParametersResponse = validateOutputParameters(interfaceOperation,
- responseFormatManager);
+ responseFormatManager);
if(outputParametersResponse.isRight()) {
return Either.right(outputParametersResponse.right().value());
}
@@ -95,64 +93,64 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> isInterfaceOperationTypeValid(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager,
- String resourceId, boolean isUpdate) {
+ ResponseFormatManager responseFormatManager,
+ org.openecomp.sdc.be.model.Component component, boolean isUpdate) {
- Either<Boolean, ResponseFormat> operationTypeEmptyEither = isOperationTypeEmpty(responseFormatManager,
- interfaceOperation.getName()); // treating name as type for now
+ Either<Boolean, ResponseFormat> operationTypeEmptyEither =
+ isOperationTypeEmpty(responseFormatManager, interfaceOperation.getName());
if (operationTypeEmptyEither.isRight()) {
return Either.right(operationTypeEmptyEither.right().value());
}
Either<Boolean, ResponseFormat> operationTypeRegexValidationResponse =
- isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
+ isOperationTypeRegexValid(responseFormatManager, interfaceOperation.getName());
if (operationTypeRegexValidationResponse.isRight()) {
return Either.right(operationTypeRegexValidationResponse.right().value());
}
Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
- resourceId, isUpdate, responseFormatManager );
+ component, isUpdate, responseFormatManager );
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_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isOperationTypeRegexValid(ResponseFormatManager responseFormatManager,
- String operationType) {
+ String operationType) {
if (!isValidOperationType(operationType)) {
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);
+ "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_TYPE_INVALID, operationType);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isOperationTypeEmpty(ResponseFormatManager responseFormatManager,
- String operationType) {
+ String operationType) {
if (StringUtils.isEmpty(operationType)) {
LOGGER.error("Interface Operation type is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_MANDATORY);
+ .INTERFACE_OPERATION_TYPE_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
}
private Either<Boolean, ResponseFormat> isValidDescription(ResponseFormatManager responseFormatManager,
- String description) {
+ String description) {
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);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -163,63 +161,57 @@ public class InterfaceOperationValidation {
}
private Either<Boolean, ResponseFormat> validateOperationTypeUnique(
- Operation interfaceOperation,
- String resourceId,
- boolean isUpdate,
- ResponseFormatManager responseFormatManager) {
+ Operation interfaceOperation,
+ org.openecomp.sdc.be.model.Component component,
+ boolean isUpdate,
+ ResponseFormatManager responseFormatManager) {
boolean isOperationTypeUnique = false;
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreInterfaces(false);
- Either<Resource, StorageOperationStatus> interfaceOperationOrigin = toscaOperationFacade
- .getToscaElement(resourceId, filter);
- if (interfaceOperationOrigin.isRight()){
- LOGGER.error("Failed to fetch interface operation information by resource id {} ", resourceId);
- return Either.right(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- Collection<InterfaceDefinition> interfaceDefinitions = interfaceOperationOrigin.left().value()
- .getInterfaces().values();
- if(CollectionUtils.isEmpty(interfaceDefinitions)){
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces();
+ if(interfaceDefinitionMap.isEmpty()){
isOperationTypeUnique = true;
return Either.left(isOperationTypeUnique);
}
- Collection<Operation> allOperations = interfaceDefinitions.stream()
- .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
- .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
- .collect(Collectors.toList());
+
+ Collection<Operation> allOperations = interfaceDefinitionMap.values().stream()
+ .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap()))
+ .map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
+ .collect(Collectors.toList());
if(CollectionUtils.isEmpty(allOperations)){
isOperationTypeUnique = true;
return Either.left(isOperationTypeUnique);
}
Map<String, String> operationTypes = new HashMap<>();
- allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(),
- operationType.getName()) );
+ allOperations.forEach(operationType -> operationTypes.put(operationType.getUniqueId(), operationType.getName()));
- if (isUpdate){
- isOperationTypeUnique = validateOperationTypeUniqueForUpdate(interfaceOperation, operationTypes);
- }
- else
if (!operationTypes.values().contains(interfaceOperation.getName())){
isOperationTypeUnique = true;
}
+ if (!isOperationTypeUnique && isUpdate){
+ 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;
+ }
+ }
+
return Either.left(isOperationTypeUnique);
}
private Either<Boolean, ResponseFormat> validateInputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ ResponseFormatManager responseFormatManager) {
if (isInputParameterNameEmpty(interfaceOperation)) {
- LOGGER.error("Interface operation input parameter name can't be empty");
- ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
+ LOGGER.error("Interface operation input parameter name can't be empty");
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_NAME_MANDATORY);
return Either.right(inputResponse);
}
Either<Boolean, Set<String>> validateInputParametersUniqueResponse = isInputParametersUnique(interfaceOperation);
if(validateInputParametersUniqueResponse.isRight()) {
- LOGGER.error("Interface operation input parameter names {} already in use",
- validateInputParametersUniqueResponse.right().value().toString());
+ LOGGER.error("Interface operation input parameter names {} already in use",
+ validateInputParametersUniqueResponse.right().value());
ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
+ .INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, validateInputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
@@ -227,20 +219,19 @@ public class InterfaceOperationValidation {
private Either<Boolean, ResponseFormat> validateOutputParameters(Operation interfaceOperation,
- ResponseFormatManager responseFormatManager) {
+ 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);
+ 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());
+ LOGGER.error("Interface operation output parameter names {} already in use",
+ validateOutputParametersUniqueResponse.right().value());
ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
+ .INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, validateOutputParametersUniqueResponse.right().value().toString());
return Either.right(inputResponse);
}
return Either.left(Boolean.TRUE);
@@ -251,11 +242,11 @@ public class InterfaceOperationValidation {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
operationDataDefinition.getInputs().getListToscaDataDefinition()
- .forEach(inputParam -> {
- if(!inputParamNamesSet.add(inputParam.getName().trim())) {
- duplicateParamNamesToReturn.add(inputParam.getName().trim());
- }
- });
+ .forEach(inputParam -> {
+ if(!inputParamNamesSet.add(inputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(inputParam.getName().trim());
+ }
+ });
if(!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
@@ -266,11 +257,11 @@ public class InterfaceOperationValidation {
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());
- }
- });
+ .forEach(outputParam -> {
+ if(!outputParamNamesSet.add(outputParam.getName().trim())) {
+ duplicateParamNamesToReturn.add(outputParam.getName().trim());
+ }
+ });
if(!duplicateParamNamesToReturn.isEmpty()) {
return Either.right(duplicateParamNamesToReturn);
}
@@ -279,26 +270,19 @@ public class InterfaceOperationValidation {
private Boolean isInputParameterNameEmpty(Operation operationDataDefinition) {
return operationDataDefinition.getInputs().getListToscaDataDefinition().stream()
- .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
+ .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));
+ .anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
- private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation,
- Map<String, String> operationTypes) {
+ private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) {
boolean isOperationTypeUnique = false;
- for(Map.Entry<String, String> entry : operationTypes.entrySet()){
- if (entry.getKey().equals(interfaceOperation.getUniqueId()) && entry.getValue().
- equals(interfaceOperation.getName())) {
- isOperationTypeUnique = true;
- }
-
- if(entry.getKey().equals(interfaceOperation.getUniqueId()) && !operationTypes.values()
- .contains(interfaceOperation.getName())){
- isOperationTypeUnique = true;
- }
+ 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;
}
return isOperationTypeUnique;
}
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/ResourceInterfaceOperationServlet.java
index 4d84e2c1a0..3e43dd7a91 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/ResourceInterfaceOperationServlet.java
@@ -139,17 +139,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start get request of {} with modifier id {}", url, userId);
- Response response;
-
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
- log.debug("failed to get interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to get interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -158,7 +155,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations");
- log.debug("get resource interface operations failed with exception", e);
+ log.error("get resource interface operations failed with exception", e);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -173,17 +170,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start delete request of {} with modifier id {}", url, userId);
- Response response;
-
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
- log.debug("failed to delete interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to delete interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -192,9 +186,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation");
- log.debug("Delete interface operation with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ log.error("Delete interface operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
@@ -206,7 +199,6 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
modifier.setUserId(userId);
log.debug("Start create or update request of {} with modifier id {}", url, userId);
- Response response;
try {
String resourceIdLower = resourceId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
@@ -220,9 +212,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
if (actionResponse.isRight()) {
- log.debug("failed to update or create interface operation");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
+ log.error("failed to update or create interface operation");
+ return buildErrorResponse(actionResponse.right().value());
}
InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value());
@@ -231,9 +222,8 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update");
- log.debug("create or update interface Operation with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ log.error("create or update interface Operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}