summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
diff options
context:
space:
mode:
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.java448
1 files changed, 176 insertions, 272 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 3aabe82db5..e23818c957 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
@@ -13,12 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.openecomp.sdc.be.components.impl;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
+import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
+
import com.google.gson.Gson;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -57,147 +76,101 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
-import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
-
@Component("interfaceOperationBusinessLogic")
public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class);
- private static final String EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION =
- "Exception occurred during {}. 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";
-
private final ArtifactCassandraDao artifactCassandraDao;
private final InterfaceOperationValidation interfaceOperationValidation;
@Autowired
- public InterfaceOperationBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactCassandraDao artifactCassandraDao,
- InterfaceOperationValidation interfaceOperationValidation, ArtifactsOperations artifactToscaOperation) {
- super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ public InterfaceOperationBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation,
+ IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation,
+ InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
+ ArtifactCassandraDao artifactCassandraDao, InterfaceOperationValidation interfaceOperationValidation,
+ ArtifactsOperations artifactToscaOperation) {
+ super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
+ artifactToscaOperation);
this.artifactCassandraDao = artifactCassandraDao;
this.interfaceOperationValidation = interfaceOperationValidation;
}
- public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId,
- String interfaceId, List<String> operationsToDelete, User user, boolean lock) {
+ public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceId,
+ List<String> operationsToDelete, User user, boolean lock) {
validateUserExists(user.getUserId());
-
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();
-
lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
-
-
try {
- Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
- storedComponent, interfaceId);
+ Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(storedComponent, interfaceId);
if (!optionalInterface.isPresent()) {
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
}
InterfaceDefinition interfaceDefinition = optionalInterface.get();
-
Map<String, Operation> operationsCollection = new HashMap<>();
for (String operationId : operationsToDelete) {
- Optional<Map.Entry<String, Operation>> optionalOperation =
- getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
+ Optional<Map.Entry<String, Operation>> optionalOperation = getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
if (!optionalOperation.isPresent()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
- storedComponent.getUniqueId()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, storedComponent.getUniqueId()));
}
-
Operation storedOperation = optionalOperation.get().getValue();
- Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutputResponse =
- interfaceOperationValidation.validateDeleteOperationContainsNoMappedOutput(storedOperation,
- storedComponent, interfaceDefinition);
+ Either<Boolean, ResponseFormat> validateDeleteOperationContainsNoMappedOutputResponse = interfaceOperationValidation
+ .validateDeleteOperationContainsNoMappedOutput(storedOperation, storedComponent, interfaceDefinition);
if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
}
-
String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
- if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)){
- Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
- artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
- if(getArtifactEither.isLeft()){
- Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
- artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
- true);
- if(removeArifactFromComponent.isRight()){
+ if (!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)) {
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither = artifactToscaOperation
+ .getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if (getArtifactEither.isLeft()) {
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent = artifactToscaOperation
+ .removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()), true);
+ if (removeArifactFromComponent.isRight()) {
janusGraphDao.rollback();
- ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ ResponseFormat responseFormatByArtifactId = componentsUtils
+ .getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
storedOperation.getImplementation().getArtifactDisplayName());
return Either.right(responseFormatByArtifactId);
}
-
CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
if (cassandraStatus != CassandraOperationStatus.OK) {
janusGraphDao.rollback();
ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
+ componentsUtils.convertFromStorageResponse(componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
return Either.right(responseFormatByArtifactId);
}
}
}
-
operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
interfaceDefinition.getOperations().remove(operationId);
}
-
- Either<List<InterfaceDefinition>, StorageOperationStatus> deleteOperationEither =
- interfaceOperation.updateInterfaces(storedComponent.getUniqueId(),
- Collections.singletonList(interfaceDefinition));
+ Either<List<InterfaceDefinition>, StorageOperationStatus> deleteOperationEither = interfaceOperation
+ .updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(interfaceDefinition));
if (deleteOperationEither.isRight()) {
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
- deleteOperationEither.right().value(), storedComponent.getComponentType())));
+ return Either.right(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(deleteOperationEither.right().value(), storedComponent.getComponentType())));
}
-
if (interfaceDefinition.getOperations().isEmpty()) {
- Either<String, StorageOperationStatus> deleteInterfaceEither = interfaceOperation.deleteInterface(
- storedComponent.getUniqueId(), interfaceDefinition.getUniqueId());
+ Either<String, StorageOperationStatus> deleteInterfaceEither = interfaceOperation
+ .deleteInterface(storedComponent.getUniqueId(), interfaceDefinition.getUniqueId());
if (deleteInterfaceEither.isRight()) {
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
- deleteInterfaceEither.right().value(), storedComponent.getComponentType())));
+ return Either.right(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(deleteInterfaceEither.right().value(), storedComponent.getComponentType())));
}
}
-
janusGraphDao.commit();
interfaceDefinition.getOperations().putAll(operationsCollection);
interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToDelete.contains(key)));
@@ -207,177 +180,144 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
janusGraphDao.rollback();
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
} finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ graphLockOperation
+ .unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> getComponentDetails(String componentId) {
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither =
- toscaOperationFacade.getToscaElement(componentId);
+ Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade
+ .getToscaElement(componentId);
if (componentStorageOperationStatusEither.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(componentStorageOperationStatusEither.right().value())));
+ return Either.right(
+ componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentStorageOperationStatusEither.right().value())));
}
return Either.left(componentStorageOperationStatusEither.left().value());
}
- private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock,
- org.openecomp.sdc.be.model.Component component, String action) {
+ private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action) {
if (lock) {
try {
lockComponent(component.getUniqueId(), component, action);
} catch (ComponentException e) {
- janusGraphDao.rollback();
- throw e;
+ janusGraphDao.rollback();
+ throw e;
+ }
}
- }
return Either.left(true);
}
- public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId,
- String interfaceId, List<String> operationsToGet, User user, boolean lock) {
+ public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId, String interfaceId,
+ List<String> operationsToGet, User user, boolean lock) {
validateUserExists(user);
-
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();
-
lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
-
try {
- Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
- storedComponent, interfaceId);
+ Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(storedComponent, interfaceId);
if (!optionalInterface.isPresent()) {
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId));
}
InterfaceDefinition interfaceDefinition = optionalInterface.get();
-
for (String operationId : operationsToGet) {
- Optional<Map.Entry<String, Operation>> optionalOperation =
- getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
+ Optional<Map.Entry<String, Operation>> optionalOperation = getOperationFromInterfaceDefinition(interfaceDefinition, operationId);
if (!optionalOperation.isPresent()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
- storedComponent.getUniqueId()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, storedComponent.getUniqueId()));
}
}
-
janusGraphDao.commit();
interfaceDefinition.getOperations().keySet().removeIf(key -> !(operationsToGet.contains(key)));
return Either.left(Collections.singletonList(interfaceDefinition));
} catch (Exception e) {
LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
janusGraphDao.rollback();
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
} finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ graphLockOperation
+ .unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
public Either<List<InterfaceDefinition>, ResponseFormat> createInterfaceOperation(String componentId,
- List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, false,
- CREATE_INTERFACE_OPERATION, lock);
+ List<InterfaceDefinition> interfaceDefinitions, User user,
+ boolean lock) {
+ return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, false, CREATE_INTERFACE_OPERATION, lock);
}
private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId,
- List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext,
- boolean lock) {
+ List<InterfaceDefinition> interfaceDefinitions,
+ User user, boolean isUpdate, String errorContext,
+ boolean lock) {
validateUserExists(user);
-
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();
-
lockComponentResult(lock, storedComponent, errorContext);
-
-
- Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes =
- getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes();
if (interfaceLifecycleTypes.isRight()) {
return Either.right(interfaceLifecycleTypes.right().value());
}
-
try {
List<InterfaceDefinition> interfacesCollection = new ArrayList<>();
Map<String, Operation> operationsCollection = new HashMap<>();
for (InterfaceDefinition inputInterfaceDefinition : interfaceDefinitions) {
- Optional<InterfaceDefinition> optionalInterface =
- getInterfaceDefinitionFromComponentByInterfaceType(
- storedComponent, inputInterfaceDefinition.getType());
- Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither =
- interfaceOperationValidation
- .validateInterfaceOperations(inputInterfaceDefinition, storedComponent,
- optionalInterface.orElse(null), interfaceLifecycleTypes.left().value(),
- isUpdate);
+ Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceType(storedComponent,
+ inputInterfaceDefinition.getType());
+ Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
+ .validateInterfaceOperations(inputInterfaceDefinition, storedComponent, optionalInterface.orElse(null),
+ interfaceLifecycleTypes.left().value(), isUpdate);
if (interfaceOperationValidationResponseEither.isRight()) {
return Either.right(interfaceOperationValidationResponseEither.right().value());
}
-
Map<String, Operation> operationsToAddOrUpdate = inputInterfaceDefinition.getOperationsMap();
operationsCollection.putAll(operationsToAddOrUpdate);
inputInterfaceDefinition.getOperations().clear();
-
- Either<InterfaceDefinition, ResponseFormat> getInterfaceEither =
- getOrCreateInterfaceDefinition(storedComponent, inputInterfaceDefinition,
- optionalInterface.orElse(null));
+ Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getOrCreateInterfaceDefinition(storedComponent,
+ inputInterfaceDefinition, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
}
InterfaceDefinition interfaceDef = getInterfaceEither.left().value();
-
updateOperationInputDefs(storedComponent, operationsToAddOrUpdate.values());
-
for (Operation operation : operationsToAddOrUpdate.values()) {
if (!isUpdate) {
addOperationToInterface(interfaceDef, operation);
} else {
- Optional<Map.Entry<String, Operation>> optionalOperation =
- getOperationFromInterfaceDefinition(interfaceDef,
- operation.getUniqueId());
+ Optional<Map.Entry<String, Operation>> optionalOperation = getOperationFromInterfaceDefinition(interfaceDef,
+ operation.getUniqueId());
if (!optionalOperation.isPresent()) {
janusGraphDao.rollback();
- return Either.right(componentsUtils
- .getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
- storedComponent.getUniqueId()));
+ return Either
+ .right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, storedComponent.getUniqueId()));
}
-
Operation storedOperation = optionalOperation.get().getValue();
String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
-
- if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)){
- Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
- artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
- if(getArtifactEither.isLeft()){
- Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
- artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
- true);
- if(removeArifactFromComponent.isRight()){
+ if (!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)) {
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither = artifactToscaOperation
+ .getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if (getArtifactEither.isLeft()) {
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent = artifactToscaOperation
+ .removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()), true);
+ if (removeArifactFromComponent.isRight()) {
janusGraphDao.rollback();
ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
- storedOperation.getImplementation().getArtifactDisplayName());
+ componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ storedOperation.getImplementation().getArtifactDisplayName());
return Either.right(responseFormatByArtifactId);
}
-
CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
if (cassandraStatus != CassandraOperationStatus.OK) {
janusGraphDao.rollback();
- ResponseFormat responseFormatByArtifactId =
- componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(
- cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
return Either.right(responseFormatByArtifactId);
}
}
@@ -387,73 +327,64 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
interfacesCollection.add(interfaceDef);
}
-
- Either<List<InterfaceDefinition>, StorageOperationStatus> addCreateOperationEither =
- interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), interfacesCollection);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> addCreateOperationEither = interfaceOperation
+ .updateInterfaces(storedComponent.getUniqueId(), interfacesCollection);
if (addCreateOperationEither.isRight()) {
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
- addCreateOperationEither.right().value(), storedComponent.getComponentType())));
+ return Either.right(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(addCreateOperationEither.right().value(), storedComponent.getComponentType())));
}
-
janusGraphDao.commit();
interfacesCollection.forEach(interfaceDefinition -> interfaceDefinition.getOperations().entrySet().removeIf(
- entry -> !operationsCollection.values().stream().map(OperationDataDefinition::getName)
- .collect(Collectors.toList()).contains(entry.getValue().getName())));
+ entry -> !operationsCollection.values().stream().map(OperationDataDefinition::getName).collect(Collectors.toList())
+ .contains(entry.getValue().getName())));
return Either.left(interfacesCollection);
} catch (Exception e) {
janusGraphDao.rollback();
LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ graphLockOperation
+ .unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
-
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes =
- interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes();
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleTypeOperation
+ .getAllInterfaceLifecycleTypes();
if (interfaceLifecycleTypes.isRight()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
}
- interfaceLifecycleTypes.left().value().values().forEach(id -> id.setOperations(
- id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(
- id.getUniqueId() + ".", ""), i -> id.getOperations().get(i)))));
-
+ interfaceLifecycleTypes.left().value().values().forEach(id -> id.setOperations(id.getOperations().keySet().stream()
+ .collect(Collectors.toMap(key -> key.replaceFirst(id.getUniqueId() + ".", ""), i -> id.getOperations().get(i)))));
return Either.left(interfaceLifecycleTypes.left().value());
}
- private Either<InterfaceDefinition, ResponseFormat> getOrCreateInterfaceDefinition(
- org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDefinition,
- InterfaceDefinition storedInterfaceDef) {
+ private Either<InterfaceDefinition, ResponseFormat> getOrCreateInterfaceDefinition(org.openecomp.sdc.be.model.Component component,
+ InterfaceDefinition interfaceDefinition,
+ InterfaceDefinition storedInterfaceDef) {
if (storedInterfaceDef != null) {
return Either.left(storedInterfaceDef);
}
interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
interfaceDefinition.setToscaResourceName(interfaceDefinition.getType());
- Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceCreateEither =
- interfaceOperation.addInterfaces(component.getUniqueId(),
- Collections.singletonList(interfaceDefinition));
+ Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceCreateEither = interfaceOperation
+ .addInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition));
if (interfaceCreateEither.isRight()) {
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
- interfaceCreateEither.right().value(), component.getComponentType())));
+ return Either.right(componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceCreateEither.right().value(), component.getComponentType())));
}
return Either.left(interfaceCreateEither.left().value().get(0));
}
- private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component,
- Collection<Operation> interfaceOperations) {
+ private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component, Collection<Operation> interfaceOperations) {
interfaceOperations.stream().filter(operation -> Objects.nonNull(operation.getInputs())).forEach(
- operation -> operation.getInputs().getListToscaDataDefinition().forEach(
- inp -> component.getInputs()
- .forEach(in -> updateOperationInputDefinition(component, inp, in))));
+ operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(inp -> component.getInputs().forEach(in -> updateOperationInputDefinition(component, inp, in))));
}
- private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component,
- OperationInputDefinition operationInput,
+ private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component, OperationInputDefinition operationInput,
InputDefinition componentInput) {
if (operationInput.getInputId().equals(componentInput.getUniqueId())) {
//Set the default value, value and schema only for inputs mapped to component inputs
@@ -461,41 +392,32 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
operationInput.setValue(componentInput.getValue());
operationInput.setSchema(componentInput.getSchema());
- operationInput.setParentPropertyType(componentInput.getParentPropertyType());
- operationInput.setSubPropertyInputPath(componentInput.getSubPropertyInputPath());
+ operationInput.setParentPropertyType(componentInput.getParentPropertyType());
+ operationInput.setSubPropertyInputPath(componentInput.getSubPropertyInputPath());
}
//Set the tosca default value for inputs mapped to component inputs as well as other outputs
operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component));
}
- private String getInputToscaDefaultValue(OperationInputDefinition input,
- org.openecomp.sdc.be.model.Component component) {
+ private String getInputToscaDefaultValue(OperationInputDefinition input, org.openecomp.sdc.be.model.Component component) {
Map<String, List<String>> defaultInputValue = null;
if (isOperationInputMappedToComponentInput(input, component.getInputs())) {
String propertyName = input.getInputId().substring(input.getInputId().indexOf('.') + 1);
- setParentPropertyTypeAndInputPath(input, component);
+ setParentPropertyTypeAndInputPath(input, component);
defaultInputValue = createMappedInputPropertyDefaultValue(propertyName);
} else if (isCapabilityProperty(input.getInputId(), component).isPresent()) {
- Optional<ComponentInstanceProperty> instancePropertyOpt = isCapabilityProperty(input.getInputId(),
- component);
+ Optional<ComponentInstanceProperty> instancePropertyOpt = isCapabilityProperty(input.getInputId(), component);
Optional<String> parentPropertyIdOpt = instancePropertyOpt.map(PropertyDataDefinition::getParentUniqueId);
Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities();
- if(MapUtils.isNotEmpty(componentCapabilities)) {
- List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream()
- .flatMap(Collection::stream)
- .filter(capabilityDefinition -> capabilityDefinition.getOwnerId().equals(component.getUniqueId()))
- .collect(Collectors.toList());
-
+ if (MapUtils.isNotEmpty(componentCapabilities)) {
+ List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values().stream().flatMap(Collection::stream)
+ .filter(capabilityDefinition -> capabilityDefinition.getOwnerId().equals(component.getUniqueId())).collect(Collectors.toList());
defaultInputValue = parentPropertyIdOpt
- .flatMap(parentPropertyId ->
- getPropertyCapabilityFromAllCapProps(parentPropertyId, capabilityDefinitionList))
- .flatMap(capability ->
- instancePropertyOpt.map(instanceProperty ->
- new ImmutablePair<>(capability.getName(), instanceProperty.getName())))
- .map(tuple -> {
+ .flatMap(parentPropertyId -> getPropertyCapabilityFromAllCapProps(parentPropertyId, capabilityDefinitionList)).flatMap(
+ capability -> instancePropertyOpt
+ .map(instanceProperty -> new ImmutablePair<>(capability.getName(), instanceProperty.getName()))).map(tuple -> {
String propertyName = tuple.right;
String capabilityName = tuple.left;
-
return createMappedCapabilityPropertyDefaultValue(capabilityName, propertyName);
}).orElse(null);
}
@@ -506,36 +428,28 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return new Gson().toJson(defaultInputValue);
}
- private void setParentPropertyTypeAndInputPath(OperationInputDefinition input,
- org.openecomp.sdc.be.model.Component component) {
- if (CollectionUtils.isEmpty(component.getInputs())) {
- return;
- }
-
- component.getInputs()
- .stream()
- .filter(inp -> inp.getUniqueId().equals(
- input.getInputId().substring(0, input.getInputId().lastIndexOf('.'))))
- .forEach(inp -> {
- input.setParentPropertyType(inp.getParentPropertyType());
- if (Objects.nonNull(input.getName())) {
- input.setSubPropertyInputPath(input.getName().replaceAll("\\.", "#"));
- }
- });
- }
+ private void setParentPropertyTypeAndInputPath(OperationInputDefinition input, org.openecomp.sdc.be.model.Component component) {
+ if (CollectionUtils.isEmpty(component.getInputs())) {
+ return;
+ }
+ component.getInputs().stream().filter(inp -> inp.getUniqueId().equals(input.getInputId().substring(0, input.getInputId().lastIndexOf('.'))))
+ .forEach(inp -> {
+ input.setParentPropertyType(inp.getParentPropertyType());
+ if (Objects.nonNull(input.getName())) {
+ input.setSubPropertyInputPath(input.getName().replaceAll("\\.", "#"));
+ }
+ });
+ }
private void addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation) {
interfaceOperation.setUniqueId(UUID.randomUUID().toString());
interfaceOperation.setImplementation(createArtifactDefinition(UUID.randomUUID().toString(), interfaceOperation));
- interfaceDefinition.getOperations()
- .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
+ interfaceDefinition.getOperations().put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
}
- private void updateOperationOnInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation,
- String artifactUuId) {
+ private void updateOperationOnInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation, String artifactUuId) {
interfaceOperation.setImplementation(createArtifactDefinition(artifactUuId, interfaceOperation));
- interfaceDefinition.getOperations()
- .put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
+ interfaceDefinition.getOperations().put(interfaceOperation.getUniqueId(), new OperationDataDefinition(interfaceOperation));
}
private ArtifactDefinition createArtifactDefinition(String artifactUuId, Operation operation) {
@@ -551,60 +465,50 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
public Either<List<InterfaceDefinition>, ResponseFormat> updateInterfaceOperation(String componentId,
- List<InterfaceDefinition> interfaceDefinitions, User user, boolean lock) {
- return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, true,
- UPDATE_INTERFACE_OPERATION, lock);
+ List<InterfaceDefinition> interfaceDefinitions, User user,
+ boolean lock) {
+ return createOrUpdateInterfaceOperation(componentId, interfaceDefinitions, user, true, UPDATE_INTERFACE_OPERATION, lock);
}
- public Either<List<OperationInputDefinition>, ResponseFormat> getInputsListForOperation(String componentId,
- String componentInstanceId, String interfaceId, String operationId, User user) {
+ public Either<List<OperationInputDefinition>, ResponseFormat> getInputsListForOperation(String componentId, String componentInstanceId,
+ String interfaceId, String operationId, User user) {
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
- if (componentEither.isRight()){
+ if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
}
-
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId());
-
Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION);
if (lockResult.isRight()) {
return Either.right(lockResult.right().value());
}
-
- try{
+ try {
org.openecomp.sdc.be.model.Component parentComponent = componentEither.left().value();
- Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
- parentComponent.getComponentInstancesInterfaces();
- if(MapUtils.isEmpty(componentInstanceInterfaces)) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND,
- componentInstanceId));
+ Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = parentComponent.getComponentInstancesInterfaces();
+ if (MapUtils.isEmpty(componentInstanceInterfaces)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentInstanceId));
}
-
- List<ComponentInstanceInterface> componentInstanceInterfaceList =
- componentInstanceInterfaces.get(componentInstanceId);
- for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaceList) {
- if(componentInstanceInterface.getInterfaceId().equals(interfaceId)){
+ List<ComponentInstanceInterface> componentInstanceInterfaceList = componentInstanceInterfaces.get(componentInstanceId);
+ for (ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaceList) {
+ if (componentInstanceInterface.getInterfaceId().equals(interfaceId)) {
Map<String, OperationDataDefinition> operations = componentInstanceInterface.getOperations();
- if(MapUtils.isNotEmpty(operations) && operations.containsKey(operationId)) {
+ if (MapUtils.isNotEmpty(operations) && operations.containsKey(operationId)) {
ListDataDefinition<OperationInputDefinition> inputs = operations.get(operationId).getInputs();
- return Either.left(CollectionUtils.isEmpty(inputs.getListToscaDataDefinition())
- ? new ArrayList<>() : inputs.getListToscaDataDefinition());
+ return Either.left(
+ CollectionUtils.isEmpty(inputs.getListToscaDataDefinition()) ? new ArrayList<>() : inputs.getListToscaDataDefinition());
}
}
}
return Either.left(new ArrayList<>());
- }
- catch (Exception e) {
+ } catch (Exception e) {
LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "get", e);
janusGraphDao.rollback();
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND));
- }
- finally {
+ } finally {
if (lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
+ graphLockOperation
+ .unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
}
-
}