summaryrefslogtreecommitdiffstats
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:
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)) {