mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
MNT-22696 Replace Rendition REST API (#880)
Code to reject zero byte renditions Addition of: DELETE /nodes/{nodeId}/renditions/{renditionId} DELETE /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId} end points Co-authored-by: kmagdziarz <Kacper.Magdziarz@hyland.com>
This commit is contained in:
@@ -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
|
||||
@@ -147,6 +147,25 @@ public interface Renditions
|
||||
void createRenditions(NodeRef nodeRef, String versionId, List<Rendition> renditions, Parameters parameters)
|
||||
throws NotFoundException, ConstraintViolatedException;
|
||||
|
||||
/**
|
||||
* Delete the rendition node.
|
||||
*
|
||||
* @param nodeRef the source nodeRef, ie. live node
|
||||
* @param renditionId the rendition id
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
*/
|
||||
void deleteRendition(NodeRef nodeRef, String renditionId, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Delete the rendition node.
|
||||
*
|
||||
* @param nodeRef the source nodeRef, ie. live node
|
||||
* @param versionId the version id (aka version label)
|
||||
* @param renditionId the rendition id
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
*/
|
||||
void deleteRendition(NodeRef nodeRef, String versionId, String renditionId, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Downloads rendition.
|
||||
*
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software LimitedP
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software LimitedP
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -444,6 +444,31 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRendition(NodeRef nodeRef, String renditionId, Parameters parameters)
|
||||
{
|
||||
deleteRendition(nodeRef, null, renditionId, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRendition(NodeRef nodeRef, String versionId, String renditionId, Parameters parameters)
|
||||
{
|
||||
if (!renditionService2.isEnabled())
|
||||
{
|
||||
throw new DisabledServiceException("Rendition generation has been disabled.");
|
||||
}
|
||||
|
||||
final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionId, parameters);
|
||||
NodeRef renditionNodeRef = getRenditionByName(validatedNodeRef, renditionId, parameters);
|
||||
|
||||
if (renditionNodeRef == null)
|
||||
{
|
||||
throw new NotFoundException(renditionId + " is not registered.");
|
||||
}
|
||||
|
||||
renditionService2.clearRenditionContentDataInTransaction(renditionNodeRef);
|
||||
}
|
||||
|
||||
private String getName(Rendition rendition)
|
||||
{
|
||||
String renditionName = rendition.getId();
|
||||
|
@@ -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
|
||||
@@ -65,6 +65,7 @@ public class NodeRenditionsRelation implements RelationshipResourceAction.Read<R
|
||||
RelationshipResourceAction.ReadById<Rendition>,
|
||||
RelationshipResourceAction.Create<Rendition>,
|
||||
RelationshipResourceBinaryAction.Read,
|
||||
RelationshipResourceAction.Delete,
|
||||
InitializingBean
|
||||
{
|
||||
|
||||
@@ -110,6 +111,14 @@ public class NodeRenditionsRelation implements RelationshipResourceAction.Read<R
|
||||
return null;
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "Delete rendition")
|
||||
@Override
|
||||
public void delete(String nodeId, String renditionId, Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
renditions.deleteRendition(nodeRef, renditionId, parameters);
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "Download rendition", description = "Download rendition")
|
||||
@BinaryProperties({ "content" })
|
||||
@Override
|
||||
|
@@ -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
|
||||
@@ -48,10 +48,11 @@ import org.springframework.extensions.webscripts.Status;
|
||||
*
|
||||
* Node version renditions
|
||||
*
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions
|
||||
* - POST /nodes/{nodeId}/versions/{versionId}/renditions
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions
|
||||
* - POST /nodes/{nodeId}/versions/{versionId}/renditions
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}
|
||||
* - DELETE /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}
|
||||
* - GET /nodes/{nodeId}/versions/{versionId}/renditions/{renditionId}/content
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
@@ -59,6 +60,7 @@ import org.springframework.extensions.webscripts.Status;
|
||||
public class NodeVersionRenditionsRelation implements RelationshipResourceAction.Read<Rendition>,
|
||||
RelationshipResourceAction.ReadById<Rendition>,
|
||||
RelationshipResourceAction.Create<Rendition>,
|
||||
RelationshipResourceAction.Delete,
|
||||
RelationshipResourceBinaryAction.Read,
|
||||
InitializingBean
|
||||
{
|
||||
@@ -115,4 +117,13 @@ public class NodeVersionRenditionsRelation implements RelationshipResourceAction
|
||||
return renditions.getContent(nodeRef, versionId, renditionId, parameters);
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "Delete rendition")
|
||||
@Override
|
||||
public void delete(String nodeId, String versionId, Parameters parameters)
|
||||
{
|
||||
String renditionId = parameters.getRelationship2Id();
|
||||
|
||||
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
renditions.deleteRendition(nodeRef, versionId, renditionId, parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -188,6 +188,8 @@ public class Params implements Parameters
|
||||
builder.append(this.entityId);
|
||||
builder.append(", relationshipId=");
|
||||
builder.append(this.relationshipId);
|
||||
builder.append(", relationship2Id=");
|
||||
builder.append(this.relationship2Id);
|
||||
builder.append(", passedIn=");
|
||||
builder.append(this.passedIn);
|
||||
builder.append(", paging=");
|
||||
|
@@ -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
|
||||
@@ -68,6 +68,7 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
||||
final Map<String, String> resourceVars = locator.parseTemplateVars(req.getServiceMatch().getTemplateVars());
|
||||
final String entityId = resourceVars.get(ResourceLocator.ENTITY_ID);
|
||||
final String relationshipId = resourceVars.get(ResourceLocator.RELATIONSHIP_ID);
|
||||
final String relationship2Id = resourceVars.get(ResourceLocator.RELATIONSHIP2_ID);
|
||||
|
||||
final Params.RecognizedParams params = getRecognizedParams(req);
|
||||
|
||||
@@ -78,7 +79,15 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
||||
return Params.valueOf(params, entityId, relationshipId, req);
|
||||
case RELATIONSHIP:
|
||||
// note: relationshipId can be null - when deleting a related set/collection
|
||||
return Params.valueOf(params, entityId, relationshipId, req);
|
||||
if (StringUtils.isNotBlank(relationship2Id))
|
||||
{
|
||||
return Params.valueOf(false, entityId, relationshipId, relationship2Id,
|
||||
null, null, null, params, null, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Params.valueOf(params, entityId, relationshipId, req);
|
||||
}
|
||||
case PROPERTY:
|
||||
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
|
||||
|
@@ -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
|
||||
@@ -1035,6 +1035,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_RENDITIONS;
|
||||
}
|
||||
|
||||
protected String getNodeRenditionIdUrl(String nodeId, String renditionID)
|
||||
{
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_RENDITIONS + "/" + renditionID;
|
||||
}
|
||||
|
||||
protected String getNodeVersionRenditionIdUrl(String nodeId, String versionId, String renditionID)
|
||||
{
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_VERSIONS + "/" + versionId + "/" + URL_RENDITIONS + "/" + renditionID;
|
||||
}
|
||||
|
||||
protected String getNodeVersionsUrl(String nodeId)
|
||||
{
|
||||
return URL_NODES + "/" + nodeId + "/" + URL_VERSIONS;
|
||||
|
@@ -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
|
||||
@@ -6366,5 +6366,92 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
|
||||
HttpResponse dauResponse = post(getRequestContentDirectUrl(contentNodeId), null, null, null, null, 501);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestDeleteRendition() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
String myNodeId = getMyNodeId();
|
||||
|
||||
// Create multipart request - txt file
|
||||
String renditionName = "pdf";
|
||||
String fileName = "quick-1.txt";
|
||||
File file = getResourceFile(fileName);
|
||||
MultiPartRequest reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName, file))
|
||||
.setRenditions(Collections.singletonList(renditionName))
|
||||
.build();
|
||||
|
||||
//Upload file to user home node
|
||||
HttpResponse response = post(getNodeChildrenUrl(myNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
String contentNodeId = document.getId();
|
||||
|
||||
// wait and check that rendition is created ...
|
||||
Rendition rendition = waitAndGetRendition(contentNodeId, null, renditionName);
|
||||
assertNotNull(rendition);
|
||||
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
|
||||
|
||||
//clean rendition
|
||||
delete(getNodeRenditionIdUrl(contentNodeId, renditionName), null, null, null, null, 204);
|
||||
//retry to double-check deletion
|
||||
delete(getNodeRenditionIdUrl(contentNodeId, renditionName), null, null, null, null, 404);
|
||||
|
||||
//check if rendition was cleaned
|
||||
HttpResponse getResponse = getSingle(getNodeRenditionIdUrl(contentNodeId, renditionName), null, 200);
|
||||
Rendition renditionDeleted = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), Rendition.class);
|
||||
assertNotNull(renditionDeleted);
|
||||
assertEquals(Rendition.RenditionStatus.NOT_CREATED, renditionDeleted.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestVersionDeleteRendition() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
String myNodeId = getMyNodeId();
|
||||
|
||||
// Create multipart request - txt file
|
||||
String renditionName = "pdf";
|
||||
String fileName = "quick-1.txt";
|
||||
File file = getResourceFile(fileName);
|
||||
MultiPartRequest reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName, file))
|
||||
.setRenditions(Collections.singletonList(renditionName))
|
||||
.build();
|
||||
|
||||
//Upload file to user home node
|
||||
HttpResponse response = post(getNodeChildrenUrl(myNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
String contentNodeId = document.getId();
|
||||
|
||||
//Update file to newer version
|
||||
String content = "The quick brown fox jumps over the lazy dog\n the lazy dog jumps over the quick brown fox";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("comment", "my version ");
|
||||
|
||||
document = updateTextFile(contentNodeId, content, params);
|
||||
assertTrue(document.getAspectNames().contains("cm:versionable"));
|
||||
assertNotNull(document.getProperties());
|
||||
assertEquals("1.1", document.getProperties().get("cm:versionLabel"));
|
||||
|
||||
// create rendition for old version and check that rendition is created ...
|
||||
Rendition renditionUpdated = createAndGetRendition(contentNodeId, "1.0", renditionName);
|
||||
assertNotNull(renditionUpdated);
|
||||
assertEquals(Rendition.RenditionStatus.CREATED, renditionUpdated.getStatus());
|
||||
|
||||
//clean rendition
|
||||
delete(getNodeVersionRenditionIdUrl(contentNodeId, "1.0", renditionName), null, null, null, null, 204);
|
||||
//retry to double-check deletion
|
||||
delete(getNodeVersionRenditionIdUrl(contentNodeId, "1.0", renditionName), null, null, null, null, 404);
|
||||
|
||||
//check if rendition was cleaned
|
||||
HttpResponse getResponse = getSingle(getNodeVersionRenditionIdUrl(contentNodeId, "1.0", renditionName), null, 200);
|
||||
Rendition renditionDeleted = RestApiUtil.parseRestApiEntry(getResponse.getJsonResponse(), Rendition.class);
|
||||
assertNotNull(renditionDeleted);
|
||||
assertEquals(Rendition.RenditionStatus.NOT_CREATED, renditionDeleted.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user