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());
}
}
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);
}
// 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);
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) {
return Either.left(artifactInfo);
}
-
/**
* updates an artifact on a component by UUID
*
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;
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");
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());
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;
return uiLeftPaletteComponents;
}
-
+ public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
+ return sos -> getResponseFormat(convertFromStorageResponse(sos));
+ }
}
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation;
-import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.openecomp.sdc.be.resources.data.DAOArtifactData;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.RepresentationUtils;
import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
@Test
public void testDeleteComponent_ArtifactNotFound(){
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result;
Resource resource = new Resource();
String uniqueId = "uniqueId";
resource.setUniqueId(uniqueId);
.thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.unlockComponent(uniqueId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
- result = artifactBL.handleDelete("parentId", "artifactId", USER, AuditingActionEnum.ARTIFACT_DELETE,
- ComponentTypeEnum.RESOURCE, resource,
- true, false);
+ Either<ArtifactDefinition, ResponseFormat> result = artifactBL.handleDelete(
+ "parentId", "artifactId", USER,
+ resource, true, false);
assertThat(result.isRight()).isTrue();
}
String parentId = "parentId";
String artifactId = "artifactId";
- AuditingActionEnum auditingAction = AuditingActionEnum.ARTIFACT_DELETE;
ArtifactDefinition artifactDefinition = new ArtifactDefinition();
Resource resource = new Resource();
- ComponentTypeEnum componentType = ComponentTypeEnum.RESOURCE;
- boolean shouldUnlock = true;
- boolean inTransaction = false;
User user = new User();
artifactDefinition.setArtifactName("test.csar");
when(artifactCassandraDao.deleteArtifact(any()))
.thenReturn(CassandraOperationStatus.OK);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result = artifactBL.handleDelete(parentId, artifactId, user, auditingAction, componentType, resource, shouldUnlock, inTransaction);
- Either<ArtifactDefinition, Operation> leftValue = result.left().value();
- Assert.assertEquals(artifactDefinition.getArtifactName(), leftValue.left().value().getArtifactName());
+ Either<ArtifactDefinition, ResponseFormat> result = artifactBL.handleDelete(
+ parentId, artifactId, user, resource, true, false);
+ Assert.assertEquals(artifactDefinition.getArtifactName(), result.left().value().getArtifactName());
}
@Test