aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
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/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
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/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java74
1 files changed, 30 insertions, 44 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 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);
+ }
}