mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129159 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 128442 jvonka: V1 REST API: Update binary content - add optional name param (to allow rename on upload of a new version) - api implementation + api sanity tests (+ve/-ve) REPO-518 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129333 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -153,6 +153,7 @@
|
|||||||
<entry key="org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_METHOD_NOT_ALLOWED}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_METHOD_NOT_ALLOWED}" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||||
<entry key="org.alfresco.service.cmr.lock.NodeLockedException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
<entry key="org.alfresco.service.cmr.lock.NodeLockedException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||||
|
<entry key="org.alfresco.service.cmr.repository.DuplicateChildNodeNameException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.StaleEntityException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.StaleEntityException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_REQUEST_ENTITY_TOO_LARGE}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_REQUEST_ENTITY_TOO_LARGE}" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.DisabledServiceException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_NOT_IMPLEMENTED}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.DisabledServiceException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_NOT_IMPLEMENTED}" />
|
||||||
|
@@ -2254,7 +2254,17 @@ public class NodesImpl implements Nodes
|
|||||||
}
|
}
|
||||||
String versionComment = parameters.getParameter(PARAM_VERSION_COMMENT);
|
String versionComment = parameters.getParameter(PARAM_VERSION_COMMENT);
|
||||||
|
|
||||||
final String fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
String fileName = parameters.getParameter(PARAM_NAME);
|
||||||
|
if (fileName != null)
|
||||||
|
{
|
||||||
|
// optionally rename, before updating the content
|
||||||
|
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
return updateExistingFile(null, nodeRef, fileName, contentInfo, stream, parameters, versionMajor, versionComment);
|
return updateExistingFile(null, nodeRef, fileName, contentInfo, stream, parameters, versionMajor, versionComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -87,6 +87,14 @@ public class NodesEntityResource implements
|
|||||||
return nodes.getFolderOrDocument(nodeId, parameters);
|
return nodes.getFolderOrDocument(nodeId, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download content
|
||||||
|
*
|
||||||
|
* @param fileNodeId
|
||||||
|
* @param parameters {@link Parameters}
|
||||||
|
* @return
|
||||||
|
* @throws EntityNotFoundException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@WebApiDescription(title = "Download content", description = "Download content")
|
@WebApiDescription(title = "Download content", description = "Download content")
|
||||||
@BinaryProperties({"content"})
|
@BinaryProperties({"content"})
|
||||||
@@ -95,6 +103,19 @@ public class NodesEntityResource implements
|
|||||||
return nodes.getContent(fileNodeId, parameters, true);
|
return nodes.getContent(fileNodeId, parameters, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new version of content
|
||||||
|
*
|
||||||
|
* This allow binary content update of an existing file/content node.
|
||||||
|
*
|
||||||
|
* Note: alternatively, can upload via POST (multipart/form-data) with existing file name and form "overwrite=true".
|
||||||
|
*
|
||||||
|
* @param fileNodeId
|
||||||
|
* @param contentInfo Basic information about the content stream
|
||||||
|
* @param stream An inputstream
|
||||||
|
* @param parameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@WebApiDescription(title = "Upload content", description = "Upload content")
|
@WebApiDescription(title = "Upload content", description = "Upload content")
|
||||||
@BinaryProperties({"content"})
|
@BinaryProperties({"content"})
|
||||||
|
@@ -2962,15 +2962,12 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
|
|
||||||
String myNodeId = getMyNodeId(user1);
|
String myNodeId = getMyNodeId(user1);
|
||||||
|
|
||||||
Folder f1 = new Folder();
|
String folderName = "f1 "+System.currentTimeMillis();
|
||||||
f1.setName("F1");
|
Folder folderResp = createFolder(user1, myNodeId, folderName);
|
||||||
f1.setNodeType(TYPE_CM_FOLDER);
|
String f1_nodeId = folderResp.getId();
|
||||||
|
|
||||||
HttpResponse response = post(getNodeChildrenUrl(myNodeId), user1, toJsonAsStringNonNull(f1), 201);
|
String anoNodeName = "another";
|
||||||
Folder folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
createFolder(user1, f1_nodeId, anoNodeName);
|
||||||
assertEquals(f1.getName(), folderResp.getName());
|
|
||||||
final String f1_nodeId = folderResp.getId();
|
|
||||||
assertNotNull(f1_nodeId);
|
|
||||||
|
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
final String docName = "testdoc.txt";
|
final String docName = "testdoc.txt";
|
||||||
@@ -2981,7 +2978,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
doc.setContent(contentInfo);
|
doc.setContent(contentInfo);
|
||||||
|
|
||||||
// create an empty file within F1 folder
|
// create an empty file within F1 folder
|
||||||
response = post(getNodeChildrenUrl(f1_nodeId), user1, toJsonAsStringNonNull(doc), 201);
|
HttpResponse response = post(getNodeChildrenUrl(f1_nodeId), user1, toJsonAsStringNonNull(doc), 201);
|
||||||
Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||||
|
|
||||||
assertEquals(docName, docResp.getName());
|
assertEquals(docName, docResp.getName());
|
||||||
@@ -3056,11 +3053,40 @@ public class NodeApiTest extends AbstractBaseApiTest
|
|||||||
assertNotNull(pathElements);
|
assertNotNull(pathElements);
|
||||||
assertTrue(pathElements.size() > 0);
|
assertTrue(pathElements.size() > 0);
|
||||||
// check the last element is F1
|
// check the last element is F1
|
||||||
assertEquals(f1.getName(), pathElements.get(pathElements.size() - 1).getName());
|
assertEquals(folderResp.getName(), pathElements.get(pathElements.size() - 1).getName());
|
||||||
|
|
||||||
// Download the file
|
// Download the file
|
||||||
response = getSingle(url, user1, null, 200);
|
response = getSingle(url, user1, null, 200);
|
||||||
assertNotNull(content, response.getResponse());
|
assertEquals(content, response.getResponse());
|
||||||
|
|
||||||
|
// Update the node's content again. Also rename the file !
|
||||||
|
content = "The quick brown fox jumps over the lazy dog updated again !";
|
||||||
|
inputStream = new ByteArrayInputStream(content.getBytes());
|
||||||
|
txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
|
||||||
|
payload = new BinaryPayload(txtFile);
|
||||||
|
|
||||||
|
String docName2 = "hello-world.txt";
|
||||||
|
Map params = new HashMap<>();
|
||||||
|
params.put(Nodes.PARAM_NAME, docName2);
|
||||||
|
response = putBinary(url, user1, payload, null, params, 200);
|
||||||
|
docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||||
|
assertEquals(docName2, docResp.getName());
|
||||||
|
|
||||||
|
// Download the file
|
||||||
|
response = getSingle(url, user1, null, 200);
|
||||||
|
assertEquals(content, response.getResponse());
|
||||||
|
|
||||||
|
// -ve - optional "name" is invalid
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put(Nodes.PARAM_NAME, "hello/world.txt");
|
||||||
|
payload = new BinaryPayload(txtFile);
|
||||||
|
putBinary(url, user1, payload, null, params, 422);
|
||||||
|
|
||||||
|
// -ve - optional "name" already exists ...
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put(Nodes.PARAM_NAME, anoNodeName);
|
||||||
|
payload = new BinaryPayload(txtFile);
|
||||||
|
putBinary(url, user1, payload, null, params, 409);
|
||||||
|
|
||||||
// -ve - try to update content using multi-part form data
|
// -ve - try to update content using multi-part form data
|
||||||
payload = new BinaryPayload(txtFile, "multipart/form-data", null);
|
payload = new BinaryPayload(txtFile, "multipart/form-data", null);
|
||||||
|
Reference in New Issue
Block a user