ACS-2391: StorageObjectProps - add version content specific endpoints (#863)

* ACS-2391: StorageObjectProps - add version content specific endpoints

- GET /nodes/{nodeId}/versions/{versionId}/storage-info/{contentPropQName}
- POST /nodes/{nodeId}/versions/{versionId}/storage-info/{contentPropQName}/archive
- POST /nodes/{nodeId}/versions/{versionId}/storage-info/{contentPropQName}/archive-restore

- since versioned content nodes are not in default workspace://SpaceStore ...
- updated existing ContentStorageInfomation (and related tests) to handle nodeRef instead of nodeId
- also fixed REST framework for operation/property for 2nd-level relationship (inc extra fix, eg. for "revert" version regression)

- update based on PR feedback (thanks SA) - also update lic header to 2022 for new/changed Java files

- update based on PR feedback (thanks MP) - minor: rename local variable (and similarly across codebase)
This commit is contained in:
montgolfiere
2022-01-04 16:23:13 +00:00
committed by GitHub
parent cb0b77bd08
commit 53979f3357
12 changed files with 268 additions and 106 deletions

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -31,6 +31,7 @@ import org.alfresco.rest.api.model.ContentStorageInfo;
import org.alfresco.rest.api.model.RestoreArchivedContentRequest;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.Experimental;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Storage information for content API.
@@ -44,34 +45,34 @@ public interface ContentStorageInformation
/**
* Note: Currently marked as experimental and subject to change.
*
* @param nodeId Identifier of the node
* @param nodeRef Node reference
* @param contentPropName Qualified name of content property (e.g. 'cm_content')
* @param parameters {@link Parameters} object to get the parameters passed into the request
* @return {@link ContentStorageInfo} object consisting of qualified name of content property and a map of storage properties
*/
@Experimental
ContentStorageInfo getStorageInfo(String nodeId, String contentPropName, Parameters parameters);
ContentStorageInfo getStorageInfo(NodeRef nodeRef, String contentPropName, Parameters parameters);
/**
* Note: Currently marked as experimental and subject to change.
*
* @param nodeId Identifier of the node
* @param nodeRef Node reference
* @param contentPropName Qualified name of content property (e.g. 'cm_content')
* @param archiveContentRequest {@link ArchiveContentRequest} object holding parameters for archive content request
* @return true when request successful, false when unsuccessful
*/
@Experimental
boolean requestArchiveContent(String nodeId, String contentPropName, ArchiveContentRequest archiveContentRequest);
boolean requestArchiveContent(NodeRef nodeRef, String contentPropName, ArchiveContentRequest archiveContentRequest);
/**
* Note: Currently marked as experimental and subject to change.
*
* @param nodeId Identifier of the node
* @param nodeRef Node reference
* @param contentPropName Qualified name of content property (e.g. 'cm_content')
* @param restoreArchivedContentRequest {@link RestoreArchivedContentRequest} object holding parameters for restore from archive request
* @return true when request successful, false when unsuccessful
*/
@Experimental
boolean requestRestoreContentFromArchive(String nodeId, String contentPropName,
boolean requestRestoreContentFromArchive(NodeRef nodeRef, String contentPropName,
RestoreArchivedContentRequest restoreArchivedContentRequest);
}

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -36,7 +36,6 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.Experimental;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -70,9 +69,8 @@ public class ContentStorageInformationImpl implements ContentStorageInformation
*/
@Override
@Experimental
public ContentStorageInfo getStorageInfo(String nodeId, String contentPropName, Parameters parameters)
public ContentStorageInfo getStorageInfo(NodeRef nodeRef, String contentPropName, Parameters parameters)
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
final QName propQName = getQName(contentPropName);
final Map<String, String> storageProperties = contentService.getStorageProperties(nodeRef, propQName);
final ContentStorageInfo storageInfo = new ContentStorageInfo();
@@ -85,10 +83,9 @@ public class ContentStorageInformationImpl implements ContentStorageInformation
* {@inheritDoc}
*/
@Override
public boolean requestArchiveContent(String nodeId, String contentPropName,
public boolean requestArchiveContent(NodeRef nodeRef, String contentPropName,
ArchiveContentRequest archiveContentRequest)
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
final QName propQName = getQName(contentPropName);
final Map<String, Serializable> archiveParams =
archiveContentRequest == null ? Collections.emptyMap() : archiveContentRequest.getArchiveParams();
@@ -99,10 +96,9 @@ public class ContentStorageInformationImpl implements ContentStorageInformation
* {@inheritDoc}
*/
@Override
public boolean requestRestoreContentFromArchive(String nodeId, String contentPropName,
public boolean requestRestoreContentFromArchive(NodeRef nodeRef, String contentPropName,
RestoreArchivedContentRequest restoreArchivedContentRequest)
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
final QName propQName = getQName(contentPropName);
final Map<String, Serializable> restoreParams =
(restoreArchivedContentRequest == null || restoreArchivedContentRequest.getRestorePriority() == null) ?

View File

@@ -676,8 +676,8 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
{
try
{
Version v = vh.getVersion(versionLabelId);
nodeRef = VersionUtil.convertNodeRef(v.getFrozenStateNodeRef());
Version version = vh.getVersion(versionLabelId);
nodeRef = VersionUtil.convertNodeRef(version.getFrozenStateNodeRef());
}
catch (VersionDoesNotExistException vdne)
{

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -40,6 +40,8 @@ import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResou
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.service.Experimental;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.PropertyCheck;
import org.springframework.beans.factory.InitializingBean;
@@ -63,6 +65,12 @@ public class NodeStorageInfoRelation implements RelationshipResourceAction.ReadB
this.storageInformation = storageInformation;
}
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "storageInformation", storageInformation);
}
@WebApiDescription(title = "Get storage properties",
description = "Retrieves storage properties for given node's content",
successStatus = HttpServletResponse.SC_OK)
@@ -70,13 +78,8 @@ public class NodeStorageInfoRelation implements RelationshipResourceAction.ReadB
public ContentStorageInfo readById(String nodeId, String contentPropName, Parameters parameters)
throws RelationshipResourceNotFoundException
{
return storageInformation.getStorageInfo(nodeId, contentPropName, parameters);
}
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "storageInformation", storageInformation);
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
return storageInformation.getStorageInfo(nodeRef, contentPropName, parameters);
}
@Experimental
@@ -89,7 +92,8 @@ public class NodeStorageInfoRelation implements RelationshipResourceAction.ReadB
public void requestArchiveContent(String nodeId, String contentPropName, ArchiveContentRequest archiveContentRequest, Parameters parameters,
WithResponse withResponse)
{
final boolean result = storageInformation.requestArchiveContent(nodeId, contentPropName, archiveContentRequest);
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
final boolean result = storageInformation.requestArchiveContent(nodeRef, contentPropName, archiveContentRequest);
if (result)
{
withResponse.setStatus(HttpServletResponse.SC_OK);
@@ -109,11 +113,13 @@ public class NodeStorageInfoRelation implements RelationshipResourceAction.ReadB
public void requestRestoreContentFromArchive(String nodeId, String contentPropName, RestoreArchivedContentRequest restoreArchivedContentRequest,
Parameters parameters, WithResponse withResponse)
{
final boolean result = storageInformation.requestRestoreContentFromArchive(nodeId, contentPropName, restoreArchivedContentRequest);
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
final boolean result = storageInformation.requestRestoreContentFromArchive(nodeRef, contentPropName, restoreArchivedContentRequest);
if (result)
{
withResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
} else
}
else
{
withResponse.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
}

View File

@@ -166,12 +166,12 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
@WebApiDescription(title="Get version node info", description = "Return metadata for a specific version node")
public Node readById(String nodeId, String versionId, Parameters parameters)
{
Version v = findVersion(nodeId, versionId);
Version version = findVersion(nodeId, versionId);
if (v != null)
if (version != null)
{
Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(v, node);
Node node = nodes.getFolderOrDocumentFullInfo(version.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(version, node);
return node;
}
@@ -183,11 +183,11 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
@Override
public BinaryResource readProperty(String nodeId, String versionId, Parameters parameters)
{
Version v = findVersion(nodeId, versionId);
Version version = findVersion(nodeId, versionId);
if (v != null)
if (version != null)
{
NodeRef versionNodeRef = v.getFrozenStateNodeRef();
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
return nodes.getContent(versionNodeRef, parameters, true); // TODO should we record version downloads ?
}
@@ -200,13 +200,13 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse)
{
Version v = findVersion(nodeId, versionId);
Version version = findVersion(nodeId, versionId);
if (v != null)
if (version != null)
{
CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
NodeRef nodeRef = v.getVersionedNodeRef();
NodeRef nodeRef = version.getVersionedNodeRef();
String versionComment = versionOptions.getComment();
@@ -231,17 +231,17 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
}
// TODO review default for deep and/or whether we should make it an option
versionService.revert(nodeRef, v, false);
versionService.revert(nodeRef, version, false);
// Checkout/Checkin the node - to store the new version in version history
NodeRef wcNodeRef = cociService.checkout(nodeRef);
cociService.checkin(wcNodeRef, versionProperties);
// get latest version
v = versionService.getVersionHistory(nodeRef).getHeadVersion();
version = versionService.getVersionHistory(nodeRef).getHeadVersion();
Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(v, node);
Node node = nodes.getFolderOrDocumentFullInfo(version.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(version, node);
return node;
}
@@ -252,17 +252,17 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters)
{
Version v = findVersion(nodeId, versionId);
Version version = findVersion(nodeId, versionId);
// live (aka versioned) nodeRef
NodeRef nodeRef = v.getVersionedNodeRef();
NodeRef nodeRef = version.getVersionedNodeRef();
if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED)
{
throw new PermissionDeniedException("Cannot delete version");
}
versionService.deleteVersion(nodeRef, v);
versionService.deleteVersion(nodeRef, version);
Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
if (props.get(ContentModel.PROP_VERSION_LABEL) == null)

View File

@@ -0,0 +1,161 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.nodes;
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.Operation;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.WebApiParam;
import org.alfresco.rest.framework.core.ResourceParameter;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.service.Experimental;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.util.PropertyCheck;
import org.springframework.beans.factory.InitializingBean;
import javax.servlet.http.HttpServletResponse;
/**
* Node Versions storage information.
*
* - GET /nodes/{nodeId}/versions/{versionId}/storage-info/{contentPropQNameId}
*
* Note: Currently marked as experimental and subject to change.
*
* @author janv
*/
@Experimental
@RelationshipResource(name = "storage-info", entityResource = NodeVersionsRelation.class, title = "Node Version's content storage information")
public class NodeVersionsStorageInfoRelation implements RelationshipResourceAction.ReadById<ContentStorageInfo>, InitializingBean
{
private final ContentStorageInformation storageInformation;
private NodeVersionsRelation nodeVersions;
public NodeVersionsStorageInfoRelation(ContentStorageInformation storageInformation, NodeVersionsRelation nodeVersions)
{
this.storageInformation = storageInformation;
this.nodeVersions = nodeVersions;
}
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "storageInformation", storageInformation);
PropertyCheck.mandatory(this, "nodeVersions", nodeVersions);
}
@WebApiDescription(title = "Get storage properties",
description = "Retrieves storage properties for given node version content",
successStatus = HttpServletResponse.SC_OK)
@Override
public ContentStorageInfo readById(String nodeId, String versionId, Parameters parameters)
throws RelationshipResourceNotFoundException
{
String contentPropQNameId = parameters.getRelationship2Id();
Version version = nodeVersions.findVersion(nodeId, versionId);
if (version != null)
{
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
return storageInformation.getStorageInfo(versionNodeRef, contentPropQNameId, parameters);
}
throw new EntityNotFoundException(nodeId+"-"+versionId);
}
@Experimental
@Operation("archive")
@WebApiParam(name = "archiveContentRequest", title = "Request for archive version content",
description = "Optional parameters for archive version content", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT)
@WebApiDescription(title = "Request send version content to archive",
description = "Submits a request to send version content to archive",
successStatus = HttpServletResponse.SC_OK)
public void requestArchiveContent(String nodeId, String versionId, ArchiveContentRequest archiveContentRequest, Parameters parameters,
WithResponse withResponse)
{
String contentPropQNameId = parameters.getRelationship2Id();
Version version = nodeVersions.findVersion(nodeId, versionId);
if (version != null)
{
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
final boolean result = storageInformation.requestArchiveContent(versionNodeRef, contentPropQNameId, archiveContentRequest);
if (result)
{
withResponse.setStatus(HttpServletResponse.SC_OK);
}
else
{
withResponse.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
}
}
throw new EntityNotFoundException(nodeId+"-"+versionId);
}
@Experimental
@Operation("archive-restore")
@WebApiParam(name = "restoreArchivedContentRequest", title = "Request for restore version content from archive",
description = "Optional parameters for restore version content from archive", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT)
@WebApiDescription(title = "Request restore version content from archive",
description = "Submits a request to restore version content from archive",
successStatus = HttpServletResponse.SC_ACCEPTED)
public void requestRestoreContentFromArchive(String nodeId, String versionId, RestoreArchivedContentRequest restoreArchivedContentRequest,
Parameters parameters, WithResponse withResponse)
{
String contentPropQNameId = parameters.getRelationship2Id();
Version version = nodeVersions.findVersion(nodeId, versionId);
if (version != null)
{
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
final boolean result = storageInformation.requestRestoreContentFromArchive(versionNodeRef, contentPropQNameId, restoreArchivedContentRequest);
if (result)
{
withResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
}
else
{
withResponse.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
}
}
throw new EntityNotFoundException(nodeId+"-"+versionId);
}
}

View File

@@ -227,13 +227,13 @@ public class ResultMapper
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
Version v = null;
Version version = null;
try
{
if (frozenNodeRef != null && versionLabelId != null)
{
v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
version = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
aNode = nodes.getFolderOrDocument(version.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
}
}
catch (EntityNotFoundException | InvalidNodeRefException e)
@@ -243,9 +243,9 @@ public class ResultMapper
+ " this is probably because the original node has been deleted.");
}
if (v != null && aNode != null)
if (version != null && aNode != null)
{
nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
nodeVersions.mapVersionInfo(version, aNode, aRow.getNodeRef());
aNode.setNodeId(frozenNodeRef.getId());
aNode.setVersionLabel(versionLabelId);
}

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -57,7 +57,7 @@ import org.springframework.http.HttpMethod;
/**
* Handles the HTTP POST for a Resource, equivalent to CRUD Create
*
* @author Gethin James
* @author Gethin James, janv
*/
public class ResourceWebScriptPost extends AbstractResourceWebScript implements ParamsExtractor,
RecognizedParamsExtractor, RequestReader
@@ -79,6 +79,7 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
final String operationName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
final String relationship2Id = resourceVars.get(ResourceLocator.RELATIONSHIP2_ID);
final RecognizedParams params = getRecognizedParams(req);
final ResourceOperation operation = resourceMeta.getOperation(HttpMethod.POST);
@@ -116,10 +117,10 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(operationName))
{
Object postedObj = processRequest(resourceMeta, operation, req);
if (StringUtils.isNotBlank(propertyName))
{
return Params.valueOf(entityId, relationshipId, params, postedObj, req);
return Params.valueOf(false, entityId, relationshipId, relationship2Id, postedObj, null, propertyName, params, null, req);
}
else
{

View File

@@ -993,6 +993,11 @@
<constructor-arg name="storageInformation" ref="ContentStorageInformation" />
</bean>
<bean class="org.alfresco.rest.api.nodes.NodeVersionsStorageInfoRelation">
<constructor-arg name="storageInformation" ref="ContentStorageInformation" />
<constructor-arg name="nodeVersions" ref="nodeVersionsRelation" />
</bean>
<bean class="org.alfresco.rest.api.nodes.NodeSecondaryChildrenRelation" parent="baseNodeRelation"/>
<bean class="org.alfresco.rest.api.nodes.NodeParentsRelation" parent="baseNodeRelation"/>

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -60,6 +60,8 @@ public class ContentStorageInformationImplTest
private static final String CONTENT_PROP_NAME = "cm:content";
private static final String STANDARD_PRIORITY = "Standard";
private static final NodeRef DUMMY_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
@Mock
private ContentService contentService;
@Mock
@@ -71,15 +73,13 @@ public class ContentStorageInformationImplTest
@Test
public void shouldReturnStorageInfoResponseWithNonEmptyStorageProps()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, String> storageProps = Map.of("x-amz-storage-class", "INTELLIGENT_TIERING", "x-alf-archived", "false");
when(contentService.getStorageProperties(eq(nodeRef), any())).thenReturn(storageProps);
when(contentService.getStorageProperties(eq(DUMMY_NODE_REF), any())).thenReturn(storageProps);
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
when(namespaceService.getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI))
.thenReturn(List.of(NamespaceService.CONTENT_MODEL_PREFIX));
final ContentStorageInfo storageInfo = objectUnderTest.getStorageInfo(DUMMY_NODE_ID, CONTENT_PROP_NAME, null);
final ContentStorageInfo storageInfo = objectUnderTest.getStorageInfo(DUMMY_NODE_REF, CONTENT_PROP_NAME, null);
assertEquals(storageProps, storageInfo.getStorageProperties());
assertEquals(CONTENT_PROP_NAME, storageInfo.getId());
@@ -88,14 +88,12 @@ public class ContentStorageInformationImplTest
@Test
public void shouldReturnStorageInfoResponseWithEmptyStorageProps()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
when(contentService.getStorageProperties(eq(nodeRef), any())).thenCallRealMethod();
when(contentService.getStorageProperties(eq(DUMMY_NODE_REF), any())).thenCallRealMethod();
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
when(namespaceService.getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI))
.thenReturn(List.of(NamespaceService.CONTENT_MODEL_PREFIX));
final ContentStorageInfo storageInfo = objectUnderTest.getStorageInfo(DUMMY_NODE_ID, CONTENT_PROP_NAME, null);
final ContentStorageInfo storageInfo = objectUnderTest.getStorageInfo(DUMMY_NODE_REF, CONTENT_PROP_NAME, null);
assertEquals(Collections.emptyMap(), storageInfo.getStorageProperties());
assertEquals(CONTENT_PROP_NAME, storageInfo.getId());
@@ -104,16 +102,15 @@ public class ContentStorageInformationImplTest
@Test
public void shouldSucceedOnArchiveContent()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, Serializable> archiveProps = Collections.emptyMap();
final ArchiveContentRequest archiveParamsRequest = new ArchiveContentRequest();
archiveParamsRequest.setArchiveParams(archiveProps);
final boolean expectedResult = true;
when(contentService.requestSendContentToArchive(eq(nodeRef), any(QName.class), eq(archiveProps))).thenReturn(expectedResult);
when(contentService.requestSendContentToArchive(eq(DUMMY_NODE_REF), 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, archiveParamsRequest);
final boolean requestArchiveContent = objectUnderTest.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveParamsRequest);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -121,14 +118,13 @@ public class ContentStorageInformationImplTest
@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(contentService.requestSendContentToArchive(eq(DUMMY_NODE_REF), 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);
final boolean requestArchiveContent = objectUnderTest.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, null);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -136,16 +132,15 @@ public class ContentStorageInformationImplTest
@Test
public void shouldNotSucceedOnArchiveContent()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, Serializable> archiveProps = Collections.emptyMap();
final ArchiveContentRequest archiveParamsRequest = new ArchiveContentRequest();
archiveParamsRequest.setArchiveParams(archiveProps);
final boolean expectedResult = false;
when(contentService.requestSendContentToArchive(eq(nodeRef), any(QName.class), eq(archiveProps))).thenReturn(expectedResult);
when(contentService.requestSendContentToArchive(eq(DUMMY_NODE_REF), 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, archiveParamsRequest);
final boolean requestArchiveContent = objectUnderTest.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveParamsRequest);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -153,31 +148,29 @@ public class ContentStorageInformationImplTest
@Test
public void shouldThrowExceptionOnArchiveContent()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, Serializable> archiveProps = Collections.emptyMap();
final ArchiveContentRequest archiveParamsRequest = new ArchiveContentRequest();
archiveParamsRequest.setArchiveParams(archiveProps);
when(contentService.requestSendContentToArchive(eq(nodeRef), any(QName.class), eq(archiveProps))).thenCallRealMethod();
when(contentService.requestSendContentToArchive(eq(DUMMY_NODE_REF), any(QName.class), eq(archiveProps))).thenCallRealMethod();
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
assertThrows(UnsupportedOperationException.class,
() -> objectUnderTest.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveParamsRequest));
() -> objectUnderTest.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveParamsRequest));
}
@Test
public void shouldSucceedOnRestoreContentFromArchive()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
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 = true;
when(contentService.requestRestoreContentFromArchive(eq(nodeRef), any(QName.class), eq(restoreParams))).thenReturn(expectedResult);
when(contentService.requestRestoreContentFromArchive(eq(DUMMY_NODE_REF), any(QName.class), eq(restoreParams))).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, restoreArchivedContentRequest);
final boolean requestArchiveContent = objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -185,14 +178,13 @@ public class ContentStorageInformationImplTest
@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())))
when(contentService.requestRestoreContentFromArchive(eq(DUMMY_NODE_REF), 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);
final boolean requestArchiveContent = objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, null);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -200,16 +192,15 @@ public class ContentStorageInformationImplTest
@Test
public void shouldNotSucceedOnRestoreContentFromArchive()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
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))).thenReturn(expectedResult);
when(contentService.requestRestoreContentFromArchive(eq(DUMMY_NODE_REF), any(QName.class), eq(restoreParams))).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, restoreArchivedContentRequest);
final boolean requestArchiveContent = objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest);
assertEquals(expectedResult, requestArchiveContent);
}
@@ -217,30 +208,28 @@ public class ContentStorageInformationImplTest
@Test
public void shouldThrowExceptionRestoreContentFromArchive()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, Serializable> 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))).thenCallRealMethod();
when(contentService.requestRestoreContentFromArchive(eq(DUMMY_NODE_REF), any(QName.class), eq(restoreParams))).thenCallRealMethod();
when(namespaceService.getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX)).thenReturn(NamespaceService.CONTENT_MODEL_1_0_URI);
assertThrows(UnsupportedOperationException.class,
() -> objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest));
() -> objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest));
}
@Test
public void shouldThrowRestoreInProgressExceptionRestoreContentFromArchive()
{
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
final Map<String, Serializable> 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(contentService.requestRestoreContentFromArchive(eq(DUMMY_NODE_REF), 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));
() -> objectUnderTest.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest));
}
}

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -33,6 +33,8 @@ import org.alfresco.rest.api.model.ContentStorageInfo;
import org.alfresco.rest.api.model.RestoreArchivedContentRequest;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,6 +56,7 @@ public class NodeStorageInfoRelationTest extends TestCase
{
private static final String DUMMY_NODE_ID = "dummy-node-id";
private static final String CONTENT_PROP_NAME = "cm:content";
private static final NodeRef DUMMY_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, DUMMY_NODE_ID);
@Mock
private ContentStorageInformation storageInformation;
@@ -74,7 +77,7 @@ public class NodeStorageInfoRelationTest extends TestCase
expectedStorageInfo.setStorageProperties(storageProps);
expectedStorageInfo.setId(CONTENT_PROP_NAME);
when(storageInformation.getStorageInfo(DUMMY_NODE_ID, CONTENT_PROP_NAME, params)).thenReturn(expectedStorageInfo);
when(storageInformation.getStorageInfo(DUMMY_NODE_REF, CONTENT_PROP_NAME, params)).thenReturn(expectedStorageInfo);
final ContentStorageInfo storageInfo = objectUnderTest.readById(DUMMY_NODE_ID, CONTENT_PROP_NAME, params);
@@ -86,7 +89,7 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldProperlyRequestArchiveContent()
{
final ArchiveContentRequest archiveContentRequest = new ArchiveContentRequest();
when(storageInformation.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveContentRequest)).thenReturn(true);
when(storageInformation.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveContentRequest)).thenReturn(true);
objectUnderTest.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveContentRequest, params, withResponse);
@@ -97,7 +100,7 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldFailsOnRequestArchiveContent()
{
final ArchiveContentRequest archiveContentRequest = new ArchiveContentRequest();
when(storageInformation.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveContentRequest)).thenReturn(false);
when(storageInformation.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveContentRequest)).thenReturn(false);
objectUnderTest.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveContentRequest, params, withResponse);
@@ -108,7 +111,7 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldThrowExceptionOnRequestArchiveContent()
{
final ArchiveContentRequest archiveContentRequest = new ArchiveContentRequest();
when(storageInformation.requestArchiveContent(DUMMY_NODE_ID, CONTENT_PROP_NAME, archiveContentRequest))
when(storageInformation.requestArchiveContent(DUMMY_NODE_REF, CONTENT_PROP_NAME, archiveContentRequest))
.thenThrow(UnsupportedOperationException.class);
assertThrows(UnsupportedOperationException.class,
@@ -121,11 +124,11 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldProperlyRequestRestoreContentFromArchive()
{
final RestoreArchivedContentRequest restoreArchivedContentRequest = new RestoreArchivedContentRequest();
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest))
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest))
.thenReturn(true);
objectUnderTest
.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest, params, withResponse);
.requestRestoreContentFromArchive(DUMMY_NODE_REF.getId(), CONTENT_PROP_NAME, restoreArchivedContentRequest, params, withResponse);
verify(withResponse, times(1)).setStatus(HttpServletResponse.SC_ACCEPTED);
}
@@ -134,11 +137,11 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldFailsOnRequestRestoreContentFromArchive()
{
final RestoreArchivedContentRequest restoreArchivedContentRequest = new RestoreArchivedContentRequest();
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest))
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest))
.thenReturn(false);
objectUnderTest
.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest, params, withResponse);
.requestRestoreContentFromArchive(DUMMY_NODE_REF.getId(), CONTENT_PROP_NAME, restoreArchivedContentRequest, params, withResponse);
verify(withResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
}
@@ -147,7 +150,7 @@ public class NodeStorageInfoRelationTest extends TestCase
public void shouldThrowExceptionOnRequestRestoreContentFromArchive()
{
final RestoreArchivedContentRequest restoreArchivedContentRequest = new RestoreArchivedContentRequest();
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_ID, CONTENT_PROP_NAME, restoreArchivedContentRequest))
when(storageInformation.requestRestoreContentFromArchive(DUMMY_NODE_REF, CONTENT_PROP_NAME, restoreArchivedContentRequest))
.thenThrow(UnsupportedOperationException.class);
assertThrows(UnsupportedOperationException.class, () -> objectUnderTest

View File

@@ -2231,9 +2231,9 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
VersionHistory versionHistory = versionService.getVersionHistory(versionableNode);
Version[] versions = versionHistory.getAllVersions().toArray(new Version[3]);
Version v = versions[1];
assertEquals("1.1", v.getVersionLabel());
versionService.deleteVersion(versionableNode, v);
Version version = versions[1];
assertEquals("1.1", version.getVersionLabel());
versionService.deleteVersion(versionableNode, version);
return null;
}
});
@@ -2258,9 +2258,9 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
{
public Object execute() throws Exception
{
Version v = versionService.getCurrentVersion(versionableNode);
assertEquals("1.2", v.getVersionLabel());
versionService.deleteVersion(versionableNode, v);
Version version = versionService.getCurrentVersion(versionableNode);
assertEquals("1.2", version.getVersionLabel());
versionService.deleteVersion(versionableNode, version);
return null;
}
});