aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-05-27 12:16:57 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-05-27 11:41:23 +0000
commit83815a0e0fbfefd5ac9922f7b58d584e16339a4b (patch)
treedab79829d662a72a78aeb1dc429457b410d65fcb /openecomp-be/api
parent577c692dc7a78d19c5bcecdf0387bbabc1dadcd6 (diff)
Fix 'VLM restore bug'
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Ie89c9ce40f3ca841e27584d65fb0637e15be82c2 Issue-ID: SDC-4027
Diffstat (limited to 'openecomp-be/api')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java28
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java2
2 files changed, 16 insertions, 14 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
index c184eca3c1..9fb6ebd8b8 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
@@ -38,7 +38,6 @@ import javax.inject.Named;
import javax.ws.rs.core.Response;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.activitylog.dao.type.ActivityType;
-import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
import org.openecomp.sdc.be.csar.storage.StorageFactory;
import org.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder;
import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
@@ -55,7 +54,6 @@ import org.openecomp.sdc.versioning.types.NotificationEventTypes;
import org.openecomp.sdcrests.item.rest.Items;
import org.openecomp.sdcrests.item.rest.mapping.MapItemToDto;
import org.openecomp.sdcrests.item.rest.models.SyncEvent;
-import org.openecomp.sdcrests.item.rest.services.catalog.notification.Notifier;
import org.openecomp.sdcrests.item.rest.services.catalog.notification.NotifierFactory;
import org.openecomp.sdcrests.item.types.ItemAction;
import org.openecomp.sdcrests.item.types.ItemActionRequestDto;
@@ -83,31 +81,33 @@ public class ItemsImpl implements Items {
}
@Override
- public Response actOn(ItemActionRequestDto request, String itemId, String user) {
- Item item = getManagersProvider().getItemManager().get(itemId);
+ public Response actOn(final ItemActionRequestDto request, final String itemId, final String user) {
+ final var item = getManagersProvider().getItemManager().get(itemId);
if (item == null) {
return Response.status(NOT_FOUND).entity(new Exception("Item does not exist.")).build();
}
- switch (request.getAction()) {
+ final var action = request.getAction();
+ switch (action) {
case ARCHIVE:
getManagersProvider().getItemManager().archive(item);
break;
case RESTORE:
- final var artifactStorageManager = new StorageFactory().createArtifactStorageManager();
- if (artifactStorageManager.isEnabled() && !artifactStorageManager.exists(itemId)) {
- LOGGER.error("Unable to restore partially deleted item '{}'", itemId);
- final var errorCode =
- new ErrorCodeBuilder().withId(INTERNAL_SERVER_ERROR.name()).withMessage("Unable to restore partially deleted VSP, re-try VSP deletion").build();
- return Response.status(INTERNAL_SERVER_ERROR).entity(new ErrorCodeAndMessage(INTERNAL_SERVER_ERROR, errorCode)).build();
+ if (ItemType.vsp.getName().equalsIgnoreCase(item.getType())) {
+ final var artifactStorageManager = new StorageFactory().createArtifactStorageManager();
+ if (artifactStorageManager.isEnabled() && !artifactStorageManager.exists(itemId)) {
+ LOGGER.error("Unable to restore partially deleted item '{}'", itemId);
+ final var errorCode =
+ new ErrorCodeBuilder().withId(INTERNAL_SERVER_ERROR.name()).withMessage("Unable to restore partially deleted VSP, re-try VSP deletion").build();
+ return Response.status(INTERNAL_SERVER_ERROR).entity(new ErrorCodeAndMessage(INTERNAL_SERVER_ERROR, errorCode)).build();
+ }
}
getManagersProvider().getItemManager().restore(item);
break;
default:
}
- actionSideAffectsMap.get(request.getAction()).execute(item, user);
+ actionSideAffectsMap.get(action).execute(item, user);
try {
- Notifier catalogNotifier = NotifierFactory.getInstance();
- catalogNotifier.execute(Collections.singleton(itemId), request.getAction());
+ NotifierFactory.getInstance().execute(Collections.singleton(itemId), action);
} catch (Exception e) {
LOGGER.error("Failed to send catalog notification on item {}", itemId, e);
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java
index 12056ad4db..25de08304b 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java
@@ -53,6 +53,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.activitylog.ActivityLogManager;
import org.openecomp.sdc.common.CommonConfigurationManager;
import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
+import org.openecomp.sdc.datatypes.model.ItemType;
import org.openecomp.sdc.versioning.ItemManager;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
@@ -147,6 +148,7 @@ class ItemsImplTest {
items.initActionSideAffectsMap();
items.setManagersProvider(managersProvider);
when(itemManager.get(any())).thenReturn(item);
+ when(item.getType()).thenReturn(ItemType.vsp.getName());
when(request.getAction()).thenReturn(RESTORE);
when(managersProvider.getItemManager()).thenReturn(itemManager);
try (MockedStatic<CommonConfigurationManager> utilities = Mockito.mockStatic(CommonConfigurationManager.class)) {