summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java6
4 files changed, 47 insertions, 49 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
index b0344007f0..3794343ee4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
@@ -1247,14 +1247,15 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
String artifactType = artifact.getArtifactType();
final ArtifactTypeEnum artifactTypeEnum = ArtifactTypeEnum.parse(artifactType);
if (artifactTypeEnum != ArtifactTypeEnum.HEAT_ENV) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic
- .handleDelete(resourceId, artifact.getUniqueId(), user, AuditingActionEnum.ARTIFACT_DELETE,
- ComponentTypeEnum.RESOURCE, updatedResource, shouldLock, inTransaction);
+ Either<ArtifactDefinition, ResponseFormat> handleDelete = artifactsBusinessLogic
+ .handleDelete(resourceId, artifact.getUniqueId(), user,
+ updatedResource, shouldLock, inTransaction);
+
if (handleDelete.isRight()) {
return Either.right(handleDelete.right().value());
}
- deletedArtifacts.add(handleDelete.left().value().left().value());
+ deletedArtifacts.add(handleDelete.left().value());
}
}
@@ -1740,7 +1741,9 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
for(GroupDefinition gr : vfGroupsToDelete){
List<String> artifacts = gr.getArtifacts();
for (String artifactId : artifacts) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(updatedResource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE,
+ Either<ArtifactDefinition, ResponseFormat> handleDelete =
+ artifactsBusinessLogic.handleDelete(
+ updatedResource.getUniqueId(), artifactId, csarInfo.getModifier(),
updatedResource, shouldLock, inTransaction);
if (handleDelete.isRight()) {
log.debug("Couldn't delete artifact {}", artifactId);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index f34f3a6c00..94c379ae29 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -1248,26 +1248,31 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
// This method is here for backward compatibility - when other parts of the code are cleaned can change to use the internal version
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete(String parentId, String artifactId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType, Component parent,
- boolean shouldLock, boolean inTransaction) {
+ public Either<ArtifactDefinition, ResponseFormat> handleDelete(
+ String parentId, String artifactId, User user, Component parent,
+ boolean shouldLock, boolean inTransaction) {
+
ResponseFormat responseFormat;
boolean operationSucceeded = false;
if (shouldLock) {
- lockComponent(componentType, artifactId, auditingAction, user, parent);
+ lockComponent(ComponentTypeEnum.RESOURCE, artifactId, AuditingActionEnum.ARTIFACT_DELETE, user, parent);
}
try {
- ArtifactDefinition artifactDefinition = handleDeleteInternal(parentId, artifactId, componentType, parent);
+ ArtifactDefinition artifactDefinition = handleDeleteInternal(parentId, artifactId,
+ ComponentTypeEnum.RESOURCE, parent);
operationSucceeded = true;
- return Either.left(Either.left(artifactDefinition));
+ return Either.left(artifactDefinition);
}
catch (ComponentException ce) {
responseFormat = componentsUtils.getResponseFormat(ce);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(AuditingActionEnum.ARTIFACT_DELETE, parent, parentId, user, null, null,
+ artifactId, responseFormat, ComponentTypeEnum.RESOURCE, null);
return Either.right(responseFormat);
}
catch (StorageException se) {
responseFormat = componentsUtils.getResponseFormat(se);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(AuditingActionEnum.ARTIFACT_DELETE, parent, parentId, user, null, null,
+ artifactId, responseFormat, ComponentTypeEnum.RESOURCE, null);
return Either.right(responseFormat);
} finally {
handleLockingAndCommit(parent, shouldLock, inTransaction, operationSucceeded);
@@ -2670,28 +2675,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(decodedPayload);
}
+ public Either<ArtifactDefinition, ResponseFormat> deleteArtifactByInterface(
+ String resourceId, String userUserId, String artifactId, boolean inTransaction) {
- public Either<Operation, ResponseFormat> deleteArtifactByInterface(String resourceId, String userUserId, String artifactId,
- boolean inTransaction) {
- User user = new User();
- user.setUserId(userUserId);
- Either<Resource, StorageOperationStatus> parent = toscaOperationFacade.getToscaElement(resourceId, JsonParseFlagEnum.ParseMetadata);
- if (parent.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(parent
- .right()
- .value()));
- return Either.right(responseFormat);
- }
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = handleDelete(resourceId, artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, parent
- .left()
- .value(),
- false, inTransaction);
- if (handleDelete.isRight()) {
- return Either.right(handleDelete.right().value());
- }
- Either<ArtifactDefinition, Operation> result = handleDelete.left().value();
- return Either.left(result.right().value());
-
+ return toscaOperationFacade
+ .getToscaElement(resourceId, JsonParseFlagEnum.ParseMetadata)
+ .right().map(componentsUtils.toResponseFormat())
+ .left().bind(parentComponent -> {
+ User user = new User(userUserId);
+ return handleDelete(resourceId, artifactId, user,
+ parentComponent,
+ false, inTransaction);
+ });
}
private Operation convertToOperation(ArtifactDefinition artifactInfo, String operationName) {
@@ -4230,7 +4225,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactInfo);
}
-
/**
* updates an artifact on a component by UUID
*
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 71707e61f9..114a9c76cc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -2319,22 +2319,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Either<Boolean, ResponseFormat> result = Either.left(true);
if (operation.isUpdate() || operation.isDelete()) {
if (isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic
+ Either<ArtifactDefinition, ResponseFormat> handleDelete = artifactsBusinessLogic
.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(),
- AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, shouldLock,
+ resource, shouldLock,
inTransaction);
if (handleDelete.isRight()) {
result = Either.right(handleDelete.right()
.value());
} else {
- Either<ArtifactDefinition, Operation> value = handleDelete.left().value();
- if (value.isLeft()) {
- String updatedArtifactId = value.left().value().getUniqueId();
- if (artifactGroupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
- resource.getDeploymentArtifacts().remove(updatedArtifactId);
- } else {
- resource.getArtifacts().remove(updatedArtifactId);
- }
+ ArtifactDefinition value = handleDelete.left().value();
+ String updatedArtifactId = value.getUniqueId();
+ if (artifactGroupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
+ resource.getDeploymentArtifacts().remove(updatedArtifactId);
+ } else {
+ resource.getArtifacts().remove(updatedArtifactId);
}
}
return result;
@@ -5505,7 +5503,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom(Resource currentResource,
Resource updatedResource, String userId, boolean inTransaction) {
- Either<Operation, ResponseFormat> deleteArtifactByInterface;
if (updatedResource.getDerivedFrom() != null) {
log.debug("Starting derived from update for resource {}", updatedResource.getUniqueId());
log.debug("1. Removing interface artifacts from graph");
@@ -5529,12 +5526,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.debug("Removing interface artifact definition {}, operation {}, interfaceType {}",
uniqueId, operationEntry.getKey(), interfaceType);
// only thing that transacts and locks here
- deleteArtifactByInterface = artifactsBusinessLogic.deleteArtifactByInterface(resourceId,
- userId, uniqueId, true);
+ Either<ArtifactDefinition, ResponseFormat> deleteArtifactByInterface =
+ artifactsBusinessLogic.deleteArtifactByInterface(resourceId, userId, uniqueId, true);
if (deleteArtifactByInterface.isRight()) {
log.debug("Couldn't remove artifact definition with id {}", uniqueId);
if (!inTransaction) {
- janusGraphDao.rollback();
+ janusGraphDao.rollback();
}
return Either.right(deleteArtifactByInterface.right()
.value());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index d50b91fadc..62a30638e6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -28,7 +28,9 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
+import fj.F;
import fj.data.Either;
+import java.util.function.Function;
import org.apache.commons.lang3.StringUtils;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
@@ -1667,5 +1669,7 @@ public class ComponentsUtils {
return uiLeftPaletteComponents;
}
-
+ public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
+ return sos -> getResponseFormat(convertFromStorageResponse(sos));
+ }
}