mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126414 jkaabimofrad: 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/BRANCHES/DEV/5.2.N/root@126760 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -84,6 +84,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;
|
||||
@@ -139,6 +140,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";
|
||||
@@ -988,6 +990,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);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user