From f772969ac32331ce847e8193059cd39dd362c7a6 Mon Sep 17 00:00:00 2001 From: franciscovila Date: Thu, 10 Mar 2022 11:55:04 +0000 Subject: Restrict deletion of archived VSPs if used in VF Verify if a VSP is used in a VF in SDC-BE before proceeding with the deletion of a VSP Issue-ID: SDC-3894 Signed-off-by: franciscovila Change-Id: I7c8bdd55516a51cf8693cfdb8c109a7c20e7ea84 --- .../rest/services/VendorSoftwareProductsImpl.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java index 86e676020c..5540e0f315 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java @@ -42,6 +42,7 @@ import javax.ws.rs.core.Response; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.sdc.activitylog.ActivityLogManager; import org.openecomp.sdc.activitylog.ActivityLogManagerFactory; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; @@ -98,6 +99,7 @@ import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspComputeDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDescriptionDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspRequestDto; +import org.openecomp.sdcrests.vsp.rest.CatalogVspClient; import org.openecomp.sdcrests.vsp.rest.VendorSoftwareProducts; import org.openecomp.sdcrests.vsp.rest.mapping.MapComputeEntityToVspComputeDto; import org.openecomp.sdcrests.vsp.rest.mapping.MapItemToVspDetailsDto; @@ -132,6 +134,8 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { private final NotificationPropagationManager notifier; private final UniqueValueUtil uniqueValueUtil; private final ArtifactStorageManager artifactStorageManager; + private final CatalogVspClient catalogVspClient; + public VendorSoftwareProductsImpl() { this.itemManager = AsdcItemManagerFactory.getInstance().createInterface(); @@ -142,6 +146,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { this.notifier = NotificationPropagationManagerFactory.getInstance().createInterface(); this.uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); this.artifactStorageManager = new StorageFactory().createArtifactStorageManager(); + this.catalogVspClient = new CatalogVspClientImpl(); } public VendorSoftwareProductsImpl(AsdcItemManager itemManager, @@ -151,7 +156,8 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { ActivityLogManager activityLogManager, NotificationPropagationManager notifier, UniqueValueUtil uniqueValueUtil, - ArtifactStorageManager artifactStorageManager) { + ArtifactStorageManager artifactStorageManager, + CatalogVspClient catalogVspClient) { this.itemManager = itemManager; this.permissionsManager = permissionsManager; this.versioningManager = versioningManager; @@ -160,6 +166,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { this.notifier = notifier; this.uniqueValueUtil = uniqueValueUtil; this.artifactStorageManager = artifactStorageManager; + this.catalogVspClient = catalogVspClient; } @Override @@ -280,6 +287,17 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { if (!vsp.getType().equals(ItemType.vsp.name())) { throw new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage(String.format("Vsp with id %s does not exist.", vspId)).build())); } + try { + Optional optUsedInVf = catalogVspClient.findNameOfVfUsingVsp(vspId, user); + if (optUsedInVf.isPresent()) { + return Response.status(Response.Status.FORBIDDEN).entity( + new Exception(ErrorMessagesFormatBuilder.getErrorWithParameters(Messages.DELETE_VSP_ERROR_USED_BY_VF.getErrorMessage(), optUsedInVf.get(), optUsedInVf.get())) + ).build(); + } + } catch (Exception e) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage(String.format("Vsp with id %s cannot be deleted due to error %s.", vspId, e.getMessage())).build()))).build(); + } + Integer certifiedVersionsCounter = vsp.getVersionStatusCounters().get(VersionStatus.Certified); if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) { if (artifactStorageManager.isEnabled() && !deleteVspFromStorage(vspId)) { -- cgit 1.2.3-korg