Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

121705 jkaabimofrad: RA-751, RA-752: Added "autoRename" query parameter support when creating a folder/empty file.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126414 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 10:50:16 +00:00
parent 5474d0a70f
commit c721bb396e
2 changed files with 46 additions and 0 deletions

View File

@@ -77,6 +77,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileFolderServiceType;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.quickshare.QuickShareService;
@@ -132,6 +133,7 @@ public class NodesImpl implements Nodes
}
private final static String PARAM_RELATIVE_PATH = "relativePath";
private final static String PARAM_AUTO_RENAME = "autoRename";
private final static String PARAM_SELECT_PROPERTIES = "properties";
private final static String PARAM_SELECT_PATH = "path";
@@ -981,6 +983,18 @@ public class NodesImpl implements Nodes
props = mapToNodeProperties(nodeInfo.getProperties());
}
// Existing file/folder name handling
final boolean autoRename = Boolean.valueOf(parameters.getParameter(PARAM_AUTO_RENAME));
if (autoRename && (isContent || FileFolderServiceType.FOLDER.equals(fileFolderService.getType(nodeTypeQName))))
{
NodeRef existingNode = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
if (existingNode != null)
{
// File already exists, find a unique name
nodeName = findUniqueName(parentNodeRef, nodeName);
}
}
// Create the node
NodeRef nodeRef = createNodeImpl(parentNodeRef, nodeName, nodeTypeQName, props);

View File

@@ -1233,6 +1233,19 @@ public class NodeApiTest extends AbstractBaseApiTest
// -ve test - duplicate name
post(postUrl, user1, toJsonAsStringNonNull(f1), 409);
// Create a folder with a duplicate name (f1), but set the autoRename to true
response = post(postUrl, user1, toJsonAsStringNonNull(f1), "?autoRename=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("f1-1", documentResp.getName());
// Create a folder with a duplicate name (f1) again, but set the autoRename to true
response = post(postUrl, user1, toJsonAsStringNonNull(f1), "?autoRename=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("f1-2", documentResp.getName());
// -ve test - create a folder with a duplicate name (f1), but set the autoRename to false
post(postUrl, user1, toJsonAsStringNonNull(f1), "?autoRename=false", 409);
}
/**
@@ -1327,6 +1340,25 @@ public class NodeApiTest extends AbstractBaseApiTest
// -ve test - duplicate name
post(postUrl, user1, toJsonAsStringNonNull(d1), 409);
// Create a file with a duplicate name (d1.txt), but set the autoRename to true
response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?autoRename=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("d1-1.txt", documentResp.getName());
// Create a file with a duplicate name (d1.txt) again, but set the autoRename to true
response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?autoRename=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("d1-2.txt", documentResp.getName());
// Create a file with a duplicate name (d1-2.txt) again, but set the autoRename to true
d1.setName("d1-2.txt");
response = post(postUrl, user1, toJsonAsStringNonNull(d1), "?autoRename=true", 201);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals("d1-2-1.txt", documentResp.getName());
// -ve test - create a file with a duplicate name (d1-2.txt), but set the autoRename to false
post(postUrl, user1, toJsonAsStringNonNull(d1), "?autoRename=false", 409);
}
/**