mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
123260 jkaabimofrad: RA-865: Added "relativePath" multi-part field to upload content API to automatically create sub-folders when it is provided. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126537 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,10 +29,10 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.alfresco.model.ApplicationModel;
|
import org.alfresco.model.ApplicationModel;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -46,6 +46,7 @@ import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
|
|||||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
import org.alfresco.repo.version.VersionModel;
|
import org.alfresco.repo.version.VersionModel;
|
||||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||||
@@ -594,28 +595,16 @@ public class NodesImpl implements Nodes
|
|||||||
|
|
||||||
protected NodeRef resolveNodeByPath(final NodeRef parentNodeRef, String path, boolean checkForCompanyHome)
|
protected NodeRef resolveNodeByPath(final NodeRef parentNodeRef, String path, boolean checkForCompanyHome)
|
||||||
{
|
{
|
||||||
final List<String> pathElements = new ArrayList<>(0);
|
final List<String> pathElements = getPathElements(path);
|
||||||
|
|
||||||
if ((path != null) && (! path.isEmpty()))
|
if (!pathElements.isEmpty() && checkForCompanyHome)
|
||||||
{
|
|
||||||
|
|
||||||
if (path.startsWith("/"))
|
|
||||||
{
|
|
||||||
path = path.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! path.isEmpty())
|
|
||||||
{
|
|
||||||
pathElements.addAll(Arrays.asList(path.split("/")));
|
|
||||||
|
|
||||||
if (checkForCompanyHome)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if (nodeService.getRootNode(parentNodeRef.getStoreRef()).equals(parentNodeRef))
|
if (nodeService.getRootNode(parentNodeRef.getStoreRef()).equals(parentNodeRef))
|
||||||
{
|
{
|
||||||
// special case
|
// special case
|
||||||
NodeRef chNodeRef = repositoryHelper.getCompanyHome();
|
NodeRef chNodeRef = repositoryHelper.getCompanyHome();
|
||||||
String chName = (String)nodeService.getProperty(chNodeRef, ContentModel.PROP_NAME);
|
String chName = (String) nodeService.getProperty(chNodeRef, ContentModel.PROP_NAME);
|
||||||
if (chName.equals(pathElements.get(0)))
|
if (chName.equals(pathElements.get(0)))
|
||||||
{
|
{
|
||||||
pathElements = pathElements.subList(1, pathElements.size());
|
pathElements = pathElements.subList(1, pathElements.size());
|
||||||
@@ -624,13 +613,12 @@ public class NodesImpl implements Nodes
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileInfo fileInfo = null;
|
FileInfo fileInfo = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pathElements.size() != 0)
|
if (!pathElements.isEmpty())
|
||||||
{
|
{
|
||||||
fileInfo = fileFolderService.resolveNamePath(parentNodeRef, pathElements);
|
fileInfo = fileFolderService.resolveNamePath(parentNodeRef, pathElements);
|
||||||
}
|
}
|
||||||
@@ -652,6 +640,66 @@ public class NodesImpl implements Nodes
|
|||||||
return fileInfo.getNodeRef();
|
return fileInfo.getNodeRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getPathElements(String path)
|
||||||
|
{
|
||||||
|
final List<String> pathElements = new ArrayList<>();
|
||||||
|
if (path != null && path.trim().length() > 0)
|
||||||
|
{
|
||||||
|
// There is no need to check for leading and trailing "/"
|
||||||
|
final StringTokenizer tokenizer = new StringTokenizer(path, "/");
|
||||||
|
while (tokenizer.hasMoreTokens())
|
||||||
|
{
|
||||||
|
pathElements.add(tokenizer.nextToken().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pathElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef makeFolders(NodeRef parentNodeRef, List<String> pathElements)
|
||||||
|
{
|
||||||
|
NodeRef currentParentRef = parentNodeRef;
|
||||||
|
// just loop and create if necessary
|
||||||
|
for (final String element : pathElements)
|
||||||
|
{
|
||||||
|
final NodeRef contextNodeRef = currentParentRef;
|
||||||
|
// does it exist?
|
||||||
|
// Navigation should not check permissions
|
||||||
|
NodeRef nodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public NodeRef doWork() throws Exception
|
||||||
|
{
|
||||||
|
return nodeService.getChildByName(contextNodeRef, ContentModel.ASSOC_CONTAINS, element);
|
||||||
|
}
|
||||||
|
}, AuthenticationUtil.getSystemUserName());
|
||||||
|
|
||||||
|
if (nodeRef == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Checks for create permissions as the fileFolderService is a public service.
|
||||||
|
FileInfo createdFileInfo = fileFolderService.create(currentParentRef, element, ContentModel.TYPE_FOLDER);
|
||||||
|
currentParentRef = createdFileInfo.getNodeRef();
|
||||||
|
}
|
||||||
|
catch (AccessDeniedException ade)
|
||||||
|
{
|
||||||
|
throw new PermissionDeniedException(ade.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!isSubClass(nodeRef, ContentModel.TYPE_FOLDER, false))
|
||||||
|
{
|
||||||
|
String parentName = (String) nodeService.getProperty(contextNodeRef, ContentModel.PROP_NAME);
|
||||||
|
throw new ConstraintViolatedException("Name [" + element + "] already exists in the target parent: " + parentName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// it exists
|
||||||
|
currentParentRef = nodeRef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentParentRef;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node getFolderOrDocument(String nodeId, Parameters parameters)
|
public Node getFolderOrDocument(String nodeId, Parameters parameters)
|
||||||
{
|
{
|
||||||
@@ -1675,11 +1723,10 @@ public class NodesImpl implements Nodes
|
|||||||
throw new InvalidArgumentException("The request content-type is not multipart: "+parentFolderNodeId);
|
throw new InvalidArgumentException("The request content-type is not multipart: "+parentFolderNodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||||
|
if (!nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false))
|
||||||
if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false))
|
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("NodeId of folder is expected: "+parentNodeRef.getId());
|
throw new InvalidArgumentException("NodeId of folder is expected: " + parentNodeRef.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = null;
|
String fileName = null;
|
||||||
@@ -1689,6 +1736,7 @@ public class NodesImpl implements Nodes
|
|||||||
boolean overwrite = false; // If a fileName clashes for a versionable file
|
boolean overwrite = false; // If a fileName clashes for a versionable file
|
||||||
Boolean majorVersion = null;
|
Boolean majorVersion = null;
|
||||||
String versionComment = null;
|
String versionComment = null;
|
||||||
|
List<String> pathElements = null;
|
||||||
Map<String, Object> qnameStrProps = new HashMap<>();
|
Map<String, Object> qnameStrProps = new HashMap<>();
|
||||||
Map<QName, Serializable> properties = null;
|
Map<QName, Serializable> properties = null;
|
||||||
|
|
||||||
@@ -1732,6 +1780,10 @@ public class NodesImpl implements Nodes
|
|||||||
versionComment = getStringOrNull(field.getValue());
|
versionComment = getStringOrNull(field.getValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "relativepath":
|
||||||
|
pathElements = getPathElements(getStringOrNull(field.getValue()));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
final String propName = field.getName();
|
final String propName = field.getName();
|
||||||
@@ -1761,6 +1813,13 @@ public class NodesImpl implements Nodes
|
|||||||
throw new InvalidArgumentException("Both 'overwrite' and 'autoRename' should not be true when uploading a file");
|
throw new InvalidArgumentException("Both 'overwrite' and 'autoRename' should not be true when uploading a file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks for the presence of, and creates as necessary,
|
||||||
|
// the folder structure in the provided path elements list.
|
||||||
|
if (pathElements != null && !pathElements.isEmpty())
|
||||||
|
{
|
||||||
|
parentNodeRef = makeFolders(parentNodeRef, pathElements);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Map the given properties, if any.
|
// Map the given properties, if any.
|
||||||
|
Reference in New Issue
Block a user