aboutsummaryrefslogtreecommitdiffstats
path: root/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 options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-03-10 11:55:04 +0000
committerfranciscovila <javier.paradela.vila@est.tech>2022-03-29 12:47:29 +0100
commitf772969ac32331ce847e8193059cd39dd362c7a6 (patch)
tree9e4986f2abb174b085f7a83f84bbdf3288e3869b /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
parent28e7f0f13e3d7b75750a449c9bda6c0d4a1986ce (diff)
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 <javier.paradela.vila@est.tech> Change-Id: I7c8bdd55516a51cf8693cfdb8c109a7c20e7ea84
Diffstat (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')
-rw-r--r--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.java20
1 files changed, 19 insertions, 1 deletions
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<String> 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)) {