From cd7e2a6e052a4b90587c470994e52c8ceb5ebbb6 Mon Sep 17 00:00:00 2001 From: David Edwards Date: Fri, 10 Dec 2021 16:41:07 +0000 Subject: [PATCH] ACS-2331 handle RestoreInProgressException (#839) --- .../api/impl/ContentStorageInformationImpl.java | 11 ++++++++++- .../impl/ContentStorageInformationImplTest.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/ContentStorageInformationImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/ContentStorageInformationImpl.java index c3faabe29d..976fd87148 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/ContentStorageInformationImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/ContentStorageInformationImpl.java @@ -31,6 +31,7 @@ import org.alfresco.rest.api.ContentStorageInformation; import org.alfresco.rest.api.model.ArchiveContentRequest; import org.alfresco.rest.api.model.ContentStorageInfo; import org.alfresco.rest.api.model.RestoreArchivedContentRequest; +import org.alfresco.rest.framework.core.exceptions.RestoreInProgressException; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.service.Experimental; import org.alfresco.service.cmr.repository.ContentService; @@ -104,7 +105,15 @@ public class ContentStorageInformationImpl implements ContentStorageInformation final Map restoreParams = restoreArchivedContentRequest.getRestorePriority() == null ? Collections.emptyMap() : Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), restoreArchivedContentRequest.getRestorePriority()); - return contentService.requestRestoreContentFromArchive(nodeRef, propQName, restoreParams); + try + { + return contentService.requestRestoreContentFromArchive(nodeRef, propQName, restoreParams); + } + catch (org.alfresco.service.cmr.repository.RestoreInProgressException e) + { + throw new RestoreInProgressException(e.getMsgId(), e); + } + } private QName getQName(final String contentPropName) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/ContentStorageInformationImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/ContentStorageInformationImplTest.java index 47d67aa3be..554f2ee99b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/ContentStorageInformationImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/ContentStorageInformationImplTest.java @@ -30,6 +30,7 @@ import org.alfresco.repo.content.ContentRestoreParams; import org.alfresco.rest.api.model.ArchiveContentRequest; import org.alfresco.rest.api.model.ContentStorageInfo; import org.alfresco.rest.api.model.RestoreArchivedContentRequest; +import org.alfresco.rest.framework.core.exceptions.RestoreInProgressException; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; @@ -198,4 +199,19 @@ public class ContentStorageInformationImplTest assertThrows(UnsupportedOperationException.class, () -> objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest)); } + + @Test + public void shouldThrowRestoreInProgressExceptionRestoreContentFromArchive() + { + final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID); + final Map restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), STANDARD_PRIORITY); + final RestoreArchivedContentRequest restoreArchivedContentRequest = new RestoreArchivedContentRequest(); + restoreArchivedContentRequest.setRestorePriority(STANDARD_PRIORITY); + + when(contentService.requestRestoreContentFromArchive(eq(nodeRef), any(QName.class), eq(restoreParams))).thenThrow(new org.alfresco.service.cmr.repository.RestoreInProgressException("Error")); + when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI); + + assertThrows(RestoreInProgressException.class, + () -> objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest)); + } }