Support deletion of archived VLMs in onboarding 74/128574/6
authorstasys10 <stasys.jurgaitis@est.tech>
Wed, 13 Apr 2022 13:50:12 +0000 (14:50 +0100)
committerMichael Morris <michael.morris@est.tech>
Thu, 21 Apr 2022 09:48:22 +0000 (09:48 +0000)
Issue-ID: SDC-3968
Signed-off-by: stasys10 <stasys.jurgaitis@est.tech>
Change-Id: I3f8a77e2ab40f7607920a781ac7ad2bb3c56741d

openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/exception/VendorLicenseModelExceptionSupplier.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/test/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImplTest.java
openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/errors/VendorLicenseErrorCodes.java

index 3d2a481..37e692d 100644 (file)
@@ -20,7 +20,7 @@
   "PACKAGE_INVALID": "BAD_REQUEST",
   "VENDOR_LICENSE_MODEL_NOT_FOUND": "NOT_FOUND",
   "VLM_IS_IN_USE_DELETE_ERROR": "FORBIDDEN",
-  "VLM_IS_CERTIFIED_DELETE_ERROR": "FORBIDDEN",
+  "VLM_IS_CERTIFIED_AND_NOT_ARCHIVED_DELETE_ERROR": "FORBIDDEN",
   "VENDOR_LICENSE_ENTITY_NOT_FOUND": "NOT_FOUND",
   "VERSIONABLE_SUB_ENTITY_NOT_FOUND": "NOT_FOUND",
   "FEATURE_GROUP_NOT_EXIST_FOR_VSP": "NOT_FOUND",
index 330a2dd..d996e23 100644 (file)
@@ -21,9 +21,6 @@
 
 package org.openecomp.sdcrests.vendorlicense.rest.exception;
 
-import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_CERTIFIED_DELETE_ERROR;
-import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_IN_USE_DELETE_ERROR;
-
 import java.util.List;
 import java.util.function.Supplier;
 import lombok.AccessLevel;
@@ -33,6 +30,8 @@ import org.openecomp.sdc.common.errors.ErrorCode;
 import org.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder;
 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
 
+import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_CERTIFIED_AND_NOT_ARCHIVED_DELETE_ERROR;
+import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_IN_USE_DELETE_ERROR;
 /**
  * Supplies exceptions happened for a Vendor License Model operation .
  */
@@ -70,15 +69,15 @@ public class VendorLicenseModelExceptionSupplier {
     }
 
     /**
-     * Provides a cannot delete certified Vendor License Model exception.
+     * Provides a cannot delete certified and not archived Vendor License Model exception.
      *
      * @param vmlId the Vendor License Model id
      * @return a Supplier for the exception
      */
-    public static Supplier<CoreException> cantDeleteCertifiedVlm(final String vmlId) {
-        final String errorMsg = String.format("Vendor License Model '%s' has been certified and cannot be deleted.", vmlId);
+    public static Supplier<CoreException> cantDeleteCertifiedAndNotArchivedVlm(final String vmlId) {
+        final String errorMsg = String.format("Vendor License Model '%s' has been certified and must be archived before deleting.", vmlId);
         final ErrorCode errorCode = new ErrorCodeBuilder()
-            .withId(VLM_IS_CERTIFIED_DELETE_ERROR)
+            .withId(VLM_IS_CERTIFIED_AND_NOT_ARCHIVED_DELETE_ERROR)
             .withMessage(errorMsg)
             .build();
         return () -> new CoreException((errorCode));
index f4e638c..ac722a5 100644 (file)
  */
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
-import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
-import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
-import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
 import org.openecomp.core.dao.UniqueValueDaoFactory;
 import org.openecomp.core.util.UniqueValueUtil;
 import org.openecomp.sdc.activitylog.ActivityLogManager;
@@ -81,6 +65,23 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
+import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
+import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
+
 @Named
 @Service("vendorLicenseModels")
 @Scope(value = "prototype")
@@ -217,8 +218,8 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
 
         final Integer certifiedVersionsCounter = vlm.getVersionStatusCounters().get(VersionStatus.Certified);
         final boolean wasVlmAtLeastOnceCertified = certifiedVersionsCounter != null && certifiedVersionsCounter > 0;
-        if (wasVlmAtLeastOnceCertified) {
-            throw VendorLicenseModelExceptionSupplier.cantDeleteCertifiedVlm(vlmId).get();
+        if (wasVlmAtLeastOnceCertified && !ItemStatus.ARCHIVED.equals(vlm.getStatus())) {
+            throw VendorLicenseModelExceptionSupplier.cantDeleteCertifiedAndNotArchivedVlm(vlmId).get();
         }
 
         asdcItemManager.delete(vlm);
index 48cb42d..1728823 100644 (file)
 package org.openecomp.sdcrests.vendorlicense.rest.services;
 
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.InjectMocks;
@@ -55,8 +42,23 @@ import org.openecomp.sdc.versioning.AsdcItemManager;
 import org.openecomp.sdc.versioning.VersioningManager;
 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.ItemStatus;
 import org.openecomp.sdcrests.vendorlicense.rest.exception.VendorLicenseModelExceptionSupplier;
 
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.never;
+
 class VendorLicenseModelsImplTest {
 
     @Mock
@@ -151,7 +153,7 @@ class VendorLicenseModelsImplTest {
     }
 
     @Test
-    void deleteLicenseModel_cantDeleteCertifiedTest() {
+    void deleteLicenseModel_cantDeleteCertifiedAndNotArchivedTest() {
         //given
         final String vlmId = "vlmId";
         final String vlmName = "vlmName";
@@ -162,13 +164,14 @@ class VendorLicenseModelsImplTest {
         vlmItem.setType(ItemType.vlm.getName());
         vlmItem.setName(vlmName);
         vlmItem.setVersionStatusCounters(Map.of(VersionStatus.Certified, 1));
+        vlmItem.setStatus(ItemStatus.ACTIVE);
         when(asdcItemManager.get(vlmId)).thenReturn(vlmItem);
         when(vendorSoftwareProductInfoDao.list(null)).thenReturn(Collections.emptyList());
 
         //when
         final CoreException actualException = assertThrows(CoreException.class, () -> vendorLicenseModels.deleteLicenseModel(vlmId, userId));
         //then
-        final CoreException expectedException = VendorLicenseModelExceptionSupplier.cantDeleteCertifiedVlm(vlmId).get();
+        final CoreException expectedException = VendorLicenseModelExceptionSupplier.cantDeleteCertifiedAndNotArchivedVlm(vlmId).get();
         assertEquals(expectedException.code().id(), actualException.code().id());
         assertEquals(expectedException.code().message(), actualException.code().message());
         assertEquals(expectedException.code().category(), actualException.code().category());
@@ -196,4 +199,25 @@ class VendorLicenseModelsImplTest {
         assertEquals(expectedException.code().message(), actualException.code().message());
     }
 
+    @Test
+    void deleteLicenseModel_CertifiedAndArchivedTest() {
+        //given
+        final String vlmId = "vlmId";
+        final String userId = "userId";
+        final Item vlmItem = new Item();
+        vlmItem.setId(vlmId);
+        vlmItem.setType(ItemType.vlm.getName());
+        vlmItem.setStatus(ItemStatus.ARCHIVED);
+        vlmItem.addVersionStatus(VersionStatus.Certified);
+        when(asdcItemManager.get(vlmId)).thenReturn(vlmItem);
+
+        //when
+        final Response response = vendorLicenseModels.deleteLicenseModel(vlmId, userId);
+        //then
+        assertEquals(Status.OK.getStatusCode(), response.getStatus());
+        verify(asdcItemManager).delete(vlmItem);
+        verify(permissionsManager).deleteItemPermissions(vlmItem.getId());
+        verify(uniqueValueUtil).deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlmItem.getName());
+        verify(notifier).notifySubscribers(any(Event.class), eq(userId));
+    }
 }
\ No newline at end of file
index eecb597..02a9022 100644 (file)
@@ -35,5 +35,5 @@ public class VendorLicenseErrorCodes {
     public static final String DUPLICATE_LIMIT_NAME_NOT_ALLOWED = "DUPLICATE_LIMIT_NAME_NOT_ALLOWED";
     public static final String DATE_RANGE_INVALID = "DATE_RANGE_INVALID";
     public static final String VLM_IS_IN_USE_DELETE_ERROR = "VLM_IS_IN_USE_DELETE_ERROR";
-    public static final String VLM_IS_CERTIFIED_DELETE_ERROR = "VLM_IS_CERTIFIED_DELETE_ERROR";
+    public static final String VLM_IS_CERTIFIED_AND_NOT_ARCHIVED_DELETE_ERROR = "VLM_IS_CERTIFIED_AND_NOT_ARCHIVED_DELETE_ERROR";
 }