diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2022-05-26 10:23:13 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-05-31 14:27:16 +0000 |
commit | ccd6a2c2037610d13769e2759ea5653babf5cacb (patch) | |
tree | 04f7105c492a44a845e2c1531ebb911ba301fc69 /openecomp-be/api | |
parent | b43eb22f91ffdc1e2ba5d82b3dc1a2c4250d06e0 (diff) |
Delete VSP - Ensure complete deletion of VSP from DB
Delete data from tables still containing the
deleted VSP id
Issue-ID: SDC-4023
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I0b389d22ccba1b888005a5bf3f1af000867e32c1
Diffstat (limited to 'openecomp-be/api')
2 files changed, 32 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 6431db3354..b424db9b42 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 @@ -27,12 +27,16 @@ import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERS import java.io.File; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.Collection; import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.ArrayList; import java.util.Map; +import java.util.Set; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -370,13 +374,36 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { } private void deleteVsp(final String vspId, final String user, final Item vsp) { + updatePackageDetails(vspId); versioningManager.list(vspId).forEach(version -> vendorSoftwareProductManager.deleteVsp(vspId, version)); itemManager.delete(vsp); + deleteUserPermissions(vspId); permissionsManager.deleteItemPermissions(vspId); uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName()); notifyUsers(vspId, vsp.getName(), null, null, user, NotificationEventTypes.DELETE); } + private void updatePackageDetails(final String vspId) { + final List<VspDetails> listVsp = new ArrayList<>(); + versioningManager.list(vspId).forEach(version -> listVsp.add(vendorSoftwareProductManager.getVsp(vspId, version))); + listVsp.forEach(vspDetail -> + vendorSoftwareProductManager.listPackages(vspDetail.getCategory(), vspDetail.getSubCategory()) + .stream().filter(packageInfo -> packageInfo.getVspId().equals(vspId)).collect(Collectors.toList()) + .forEach(packInfo -> { + packInfo.setTranslatedFile(ByteBuffer.wrap(new byte[0])); + vendorSoftwareProductManager.updatePackage(packInfo); + }) + ); + } + + private void deleteUserPermissions(String vspId) { + permissionsManager.listItemPermissions(vspId).forEach(itemPermissionsEntity -> { + Set<String> usersToDelete = new HashSet<>(); + usersToDelete.add(itemPermissionsEntity.getUserId()); + permissionsManager.updateItemPermissions(vspId, itemPermissionsEntity.getPermission(), new HashSet<>(), usersToDelete); + }); + } + @Override public Response actOnVendorSoftwareProduct(VersionSoftwareProductActionRequestDto request, String vspId, String versionId, String user) throws IOException { diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java index 76e4910a66..9653012789 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImplTest.java @@ -63,6 +63,7 @@ import org.openecomp.sdc.datatypes.model.ItemType; import org.openecomp.sdc.itempermissions.PermissionsManager; import org.openecomp.sdc.notification.services.NotificationPropagationManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.versioning.AsdcItemManager; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; @@ -199,7 +200,10 @@ class VendorSoftwareProductsImplTest { final Version version2 = new Version("version2Id"); final List<Version> versionList = List.of(version1, version2); when(versioningManager.list(vspId)).thenReturn(versionList); - + VspDetails vspDetails = new VspDetails(); + vspDetails.setCategory("cat"); + vspDetails.setSubCategory("sub"); + when(vendorSoftwareProductManager.getVsp(vspId, version1)).thenReturn(vspDetails); when(itemManager.list(any())).thenReturn(List.of(item)); Response rsp = vendorSoftwareProducts.deleteVsp(vspId, user); assertEquals(HttpStatus.SC_OK, rsp.getStatus()); |