mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-2236: Fixing NPE when no body provided for POST requests. (#840)
This commit is contained in:
@@ -90,7 +90,9 @@ public class ContentStorageInformationImpl implements ContentStorageInformation
|
||||
{
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
final QName propQName = getQName(contentPropName);
|
||||
return contentService.requestSendContentToArchive(nodeRef, propQName, archiveContentRequest.getArchiveParams());
|
||||
final Map<String, Serializable> archiveParams =
|
||||
archiveContentRequest == null ? Collections.emptyMap() : archiveContentRequest.getArchiveParams();
|
||||
return contentService.requestSendContentToArchive(nodeRef, propQName, archiveParams);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,18 +104,19 @@ public class ContentStorageInformationImpl implements ContentStorageInformation
|
||||
{
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
final QName propQName = getQName(contentPropName);
|
||||
final Map<String, Serializable> restoreParams = restoreArchivedContentRequest.getRestorePriority() == null ?
|
||||
Collections.emptyMap() :
|
||||
Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), restoreArchivedContentRequest.getRestorePriority());
|
||||
try
|
||||
final Map<String, Serializable> restoreParams =
|
||||
(restoreArchivedContentRequest == null || restoreArchivedContentRequest.getRestorePriority() == null) ?
|
||||
Collections.emptyMap() :
|
||||
Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), restoreArchivedContentRequest.getRestorePriority());
|
||||
try
|
||||
{
|
||||
return contentService.requestRestoreContentFromArchive(nodeRef, propQName, restoreParams);
|
||||
}
|
||||
catch (org.alfresco.service.cmr.repository.RestoreInProgressException e)
|
||||
}
|
||||
catch (org.alfresco.service.cmr.repository.RestoreInProgressException e)
|
||||
{
|
||||
throw new RestoreInProgressException(e.getMsgId(), e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private QName getQName(final String contentPropName)
|
||||
|
@@ -118,6 +118,21 @@ public class ContentStorageInformationImplTest
|
||||
assertEquals(expectedResult, requestArchiveContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSucceedOnArchiveContentWhenNoRequestBody()
|
||||
{
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
|
||||
final Map<String, Serializable> archiveProps = Collections.emptyMap();
|
||||
final boolean expectedResult = true;
|
||||
|
||||
when(contentService.requestSendContentToArchive(eq(nodeRef), any(QName.class), eq(archiveProps))).thenReturn(expectedResult);
|
||||
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
|
||||
final boolean requestArchiveContent = objectUnderTest.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, null);
|
||||
|
||||
assertEquals(expectedResult, requestArchiveContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotSucceedOnArchiveContent()
|
||||
{
|
||||
@@ -167,6 +182,21 @@ public class ContentStorageInformationImplTest
|
||||
assertEquals(expectedResult, requestArchiveContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSucceedOnRestoreContentFromArchiveWhenNoRequestBody()
|
||||
{
|
||||
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
|
||||
final boolean expectedResult = true;
|
||||
|
||||
when(contentService.requestRestoreContentFromArchive(eq(nodeRef), any(QName.class), eq(Collections.emptyMap())))
|
||||
.thenReturn(expectedResult);
|
||||
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
|
||||
final boolean requestArchiveContent = objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, null);
|
||||
|
||||
assertEquals(expectedResult, requestArchiveContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotSucceedOnRestoreContentFromArchive()
|
||||
{
|
||||
@@ -191,7 +221,6 @@ public class ContentStorageInformationImplTest
|
||||
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), STANDARD_PRIORITY);
|
||||
final RestoreArchivedContentRequest restoreArchivedContentRequest = new RestoreArchivedContentRequest();
|
||||
restoreArchivedContentRequest.setRestorePriority(STANDARD_PRIORITY);
|
||||
final boolean expectedResult = false;
|
||||
|
||||
when(contentService.requestRestoreContentFromArchive(eq(nodeRef), any(QName.class), eq(restoreParams))).thenCallRealMethod();
|
||||
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
|
||||
|
Reference in New Issue
Block a user