mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126376 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 119921 jkaabimofrad: Finished the requirements in RA-637. Added nodeType form data, the client provided content-type will be used if it is not null, and also support for model properties in the form data. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126722 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -554,6 +554,9 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
ContentInfo contentInfo = document.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType());
|
||||
// Check there is no path info returned.
|
||||
// The path info should only be returned when it is requested via a select statement.
|
||||
assertNull(document.getPath());
|
||||
|
||||
// Retrieve the uploaded file
|
||||
response = getSingle(NodesEntityResource.class, user1, document.getId(), null, 200);
|
||||
@@ -587,11 +590,12 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
// Check the upload response
|
||||
assertEquals("quick-1.pdf", document.getName());
|
||||
|
||||
// upload the same file again
|
||||
response = post(getChildrenUrl(Nodes.PATH_MY), user1, new String(reqBody.getBody()), null, reqBody.getContentType(), 201);
|
||||
// upload the same file again, and request the path info to be present in the response
|
||||
response = post(getChildrenUrl(Nodes.PATH_MY), user1, new String(reqBody.getBody()), "?select=path", reqBody.getContentType(), 201);
|
||||
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals("quick-2.pdf", document.getName());
|
||||
assertNotNull(document.getPath());
|
||||
|
||||
response = getAll(getChildrenUrl(Nodes.PATH_MY), user1, paging, 200);
|
||||
pagingResult = parsePaging(response.getJsonResponse());
|
||||
@@ -619,6 +623,15 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
// Try to upload a file without defining the required formData
|
||||
reqBody = MultiPartBuilder.create().setAutoRename(true).build();
|
||||
post(getChildrenUrl(Nodes.PATH_MY), user1, new String(reqBody.getBody()), null, reqBody.getContentType(), 400);
|
||||
|
||||
// Test unsupported node type
|
||||
reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName2, file2, null))
|
||||
.setAutoRename(true)
|
||||
.setNodeType("cm:link")
|
||||
.build();
|
||||
post(getChildrenUrl(user1Home.getId()), user1, new String(reqBody.getBody()), null, reqBody.getContentType(), 400);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -643,7 +656,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
final int numOfNodes = pagingResult.getCount().intValue();
|
||||
|
||||
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_TEXT_PLAIN));
|
||||
.setFileData(new FileData(fileName, file, null));
|
||||
MultiPartRequest reqBody = multiPartBuilder.build();
|
||||
// Try to upload
|
||||
response = post(getChildrenUrl(folderA_Ref), userOneN1.getId(), new String(reqBody.getBody()), null, reqBody.getContentType(), 201);
|
||||
@@ -652,6 +665,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(fileName, document.getName());
|
||||
ContentInfo contentInfo = document.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
// As the client didn't set the mimeType, the API must guess it.
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
|
||||
// Retrieve the uploaded file
|
||||
@@ -683,6 +697,51 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.build();
|
||||
// userTwoN1 tries to upload a new file into the folderA of userOneN1
|
||||
post(getChildrenUrl(folderA_Ref), userTwoN1.getId(), new String(reqBody.getBody()), null, reqBody.getContentType(), 403);
|
||||
|
||||
// Test upload with properties
|
||||
response = post(getChildrenUrl(folderA_Ref), userOneN1.getId(), new String(reqBody.getBody()), null, reqBody.getContentType(), 201);
|
||||
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals(fileName2, document.getName());
|
||||
contentInfo = document.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
assertNotNull(document.getProperties());
|
||||
assertNull(document.getProperties().get("cm:title"));
|
||||
assertNull(document.getProperties().get("cm:description"));
|
||||
|
||||
// upload a file with properties. Also, set autoRename=true
|
||||
Map<String, String> props = new HashMap<>(2);
|
||||
props.put("cm:title", "test title");
|
||||
props.put("cm:description", "test description");
|
||||
reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName2, file2, MimetypeMap.MIMETYPE_TEXT_PLAIN))
|
||||
.setAutoRename(true)
|
||||
.setProperties(props)
|
||||
.build();
|
||||
|
||||
response = post(getChildrenUrl(folderA_Ref), userOneN1.getId(), new String(reqBody.getBody()), null, reqBody.getContentType(), 201);
|
||||
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
// "quick-2-1.txt" => fileName2 + autoRename
|
||||
assertEquals("quick-2-1.txt", document.getName());
|
||||
contentInfo = document.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
assertNotNull(document.getProperties());
|
||||
assertEquals("test title", document.getProperties().get("cm:title"));
|
||||
assertEquals("test description", document.getProperties().get("cm:description"));
|
||||
|
||||
// Test unknown property name
|
||||
props = new HashMap<>(1);
|
||||
props.put("unknownPrefix" + System.currentTimeMillis() + ":description", "test description");
|
||||
reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName2, file2, MimetypeMap.MIMETYPE_TEXT_PLAIN))
|
||||
.setAutoRename(true)
|
||||
.setProperties(props)
|
||||
.build();
|
||||
// Prop prefix is unknown
|
||||
post(getChildrenUrl(folderA_Ref), userOneN1.getId(), new String(reqBody.getBody()), null, reqBody.getContentType(), 400);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -37,7 +37,11 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* <i><b>multipart/form-data</b></i> builder.
|
||||
@@ -54,10 +58,12 @@ public class MultiPartBuilder
|
||||
private String updateNodeRef;
|
||||
private String description;
|
||||
private String contentTypeQNameStr;
|
||||
private List<String> aspects;
|
||||
private List<String> aspects = Collections.emptyList();
|
||||
private Boolean majorVersion;
|
||||
private Boolean overwrite;
|
||||
private Boolean autoRename;
|
||||
private String nodeType;
|
||||
private Map<String, String> properties = Collections.emptyMap();
|
||||
|
||||
private MultiPartBuilder()
|
||||
{
|
||||
@@ -73,10 +79,12 @@ public class MultiPartBuilder
|
||||
this.updateNodeRef = that.updateNodeRef;
|
||||
this.description = that.description;
|
||||
this.contentTypeQNameStr = that.contentTypeQNameStr;
|
||||
this.aspects = that.aspects;
|
||||
this.aspects = new ArrayList<>(that.aspects);
|
||||
this.majorVersion = that.majorVersion;
|
||||
this.overwrite = that.overwrite;
|
||||
this.autoRename = that.autoRename;
|
||||
this.nodeType = that.nodeType;
|
||||
this.properties = new HashMap<>(that.properties);
|
||||
}
|
||||
|
||||
public static MultiPartBuilder create()
|
||||
@@ -161,9 +169,21 @@ public class MultiPartBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiPartBuilder setNodeType(String nodeType)
|
||||
{
|
||||
this.nodeType = nodeType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiPartBuilder setProperties(Map<String, String> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
private String getAspects(List<String> aspects)
|
||||
{
|
||||
if (aspects != null)
|
||||
if (!aspects.isEmpty())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(aspects.size() * 2);
|
||||
for (String str : aspects)
|
||||
@@ -243,7 +263,11 @@ public class MultiPartBuilder
|
||||
|
||||
if (fileData != null)
|
||||
{
|
||||
parts.add(new FilePart("filedata", fileData.getFileName(), fileData.getFile(), fileData.getMimetype(), null));
|
||||
FilePart fp = new FilePart("filedata", fileData.getFileName(), fileData.getFile(), fileData.getMimetype(), null);
|
||||
// Get rid of the default values added upon FilePart instantiation
|
||||
fp.setCharSet(null);
|
||||
fp.setContentType(fileData.getMimetype());
|
||||
parts.add(fp);
|
||||
addPartIfNotNull(parts, "filename", fileData.getFileName());
|
||||
}
|
||||
addPartIfNotNull(parts, "siteid", siteId);
|
||||
@@ -257,6 +281,15 @@ public class MultiPartBuilder
|
||||
addPartIfNotNull(parts, "majorversion", majorVersion);
|
||||
addPartIfNotNull(parts, "overwrite", overwrite);
|
||||
addPartIfNotNull(parts, "autoRename", autoRename);
|
||||
addPartIfNotNull(parts, "nodeType", nodeType);
|
||||
|
||||
if (!properties.isEmpty())
|
||||
{
|
||||
for (Entry<String, String> prop : properties.entrySet())
|
||||
{
|
||||
parts.add(new StringPart(prop.getKey(), prop.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
MultipartRequestEntity req = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), new HttpMethodParams());
|
||||
|
||||
|
Reference in New Issue
Block a user