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)
126542 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 123495 jvonka: Nodes (FileFolder) API - add optional relativePath (to make folders) when creating a folder, empty file or other custom node RA-703 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126887 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1285,7 +1285,7 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
// check that requested parent node exists and it's type is a (sub-)type of folder
|
||||
final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
|
||||
if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false))
|
||||
{
|
||||
@@ -1323,7 +1323,7 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
// Existing file/folder name handling
|
||||
final boolean autoRename = Boolean.valueOf(parameters.getParameter(PARAM_AUTO_RENAME));
|
||||
boolean autoRename = Boolean.valueOf(parameters.getParameter(PARAM_AUTO_RENAME));
|
||||
if (autoRename && (isContent || isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER)))
|
||||
{
|
||||
NodeRef existingNode = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
|
||||
@@ -1334,6 +1334,9 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
}
|
||||
|
||||
String relativePath = nodeInfo.getRelativePath();
|
||||
parentNodeRef = getOrCreatePath(parentNodeRef, relativePath);
|
||||
|
||||
// Create the node
|
||||
NodeRef nodeRef = createNodeImpl(parentNodeRef, nodeName, nodeTypeQName, props);
|
||||
|
||||
@@ -1364,6 +1367,23 @@ public class NodesImpl implements Nodes
|
||||
return getFolderOrDocument(nodeRef.getId(), parameters);
|
||||
}
|
||||
|
||||
private NodeRef getOrCreatePath(NodeRef parentNodeRef, String relativePath)
|
||||
{
|
||||
if (relativePath != null)
|
||||
{
|
||||
List<String> pathElements = getPathElements(relativePath);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
return parentNodeRef;
|
||||
}
|
||||
|
||||
private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props)
|
||||
{
|
||||
if (props == null)
|
||||
@@ -1842,7 +1862,7 @@ public class NodesImpl implements Nodes
|
||||
boolean overwrite = false; // If a fileName clashes for a versionable file
|
||||
Boolean majorVersion = null;
|
||||
String versionComment = null;
|
||||
List<String> pathElements = null;
|
||||
String relativePath = null;
|
||||
Map<String, Object> qnameStrProps = new HashMap<>();
|
||||
Map<QName, Serializable> properties = null;
|
||||
|
||||
@@ -1887,7 +1907,7 @@ public class NodesImpl implements Nodes
|
||||
break;
|
||||
|
||||
case "relativepath":
|
||||
pathElements = getPathElements(getStringOrNull(field.getValue()));
|
||||
relativePath = getStringOrNull(field.getValue());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1919,12 +1939,8 @@ public class NodesImpl implements Nodes
|
||||
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);
|
||||
}
|
||||
// if requested, make (get or create) path
|
||||
parentNodeRef = getOrCreatePath(parentNodeRef, relativePath);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1945,6 +1961,8 @@ public class NodesImpl implements Nodes
|
||||
{
|
||||
// attempt to find a unique name
|
||||
fileName = findUniqueName(parentNodeRef, fileName);
|
||||
|
||||
// drop-through !
|
||||
}
|
||||
else if (overwrite && nodeService.hasAspect(existingFile, ContentModel.ASPECT_VERSIONABLE))
|
||||
{
|
||||
@@ -1994,9 +2012,6 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create a new node and writes its content to the repository.
|
||||
*/
|
||||
private Node createNewFile(NodeRef parentNodeRef, String fileName, QName nodeType, Content content, Map<QName, Serializable> props, Parameters params)
|
||||
{
|
||||
if (nodeType == null)
|
||||
|
@@ -71,6 +71,9 @@ public class Node implements Comparable<Node>
|
||||
protected PathInfo pathInfo;
|
||||
protected String prefixTypeQName;
|
||||
|
||||
// note: currently only used for create request
|
||||
protected String relativePath;
|
||||
|
||||
protected List<String> aspectNames;
|
||||
protected Map<String, Object> properties;
|
||||
|
||||
@@ -297,6 +300,16 @@ public class Node implements Comparable<Node>
|
||||
this.allowableOperations = allowableOperations;
|
||||
}
|
||||
|
||||
public String getRelativePath()
|
||||
{
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
public void setRelativePath(String relativePath)
|
||||
{
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if(this == other)
|
||||
@@ -329,16 +342,38 @@ public class Node implements Comparable<Node>
|
||||
sb.append(", name=").append(getName());
|
||||
sb.append(", isFolder=").append(getIsFolder());
|
||||
sb.append(", isFile=").append(getIsFile());
|
||||
sb.append(", isLink=").append(getIsLink()); // note: symbolic link (not shared link)
|
||||
sb.append(", modifiedAt=").append(getModifiedAt());
|
||||
sb.append(", modifiedByUser=").append(getModifiedByUser());
|
||||
sb.append(", createdAt=").append(getCreatedAt());
|
||||
sb.append(", createdByUser=").append(getCreatedByUser());
|
||||
sb.append(", path=").append(getPath());
|
||||
sb.append(", content=").append(getContent());
|
||||
sb.append(", aspectNames=").append(getAspectNames());
|
||||
//sb.append(", properties=").append(getProperties());
|
||||
sb.append(", allowableOperations=").append(getAllowableOperations());
|
||||
if (getIsLink() != null)
|
||||
{
|
||||
sb.append(", isLink=").append(getIsLink()); // note: symbolic link (not shared link)
|
||||
}
|
||||
if (getPath() != null)
|
||||
{
|
||||
sb.append(", path=").append(getPath());
|
||||
}
|
||||
if (getContent() != null)
|
||||
{
|
||||
sb.append(", content=").append(getContent());
|
||||
}
|
||||
if (getAspectNames() != null)
|
||||
{
|
||||
sb.append(", aspectNames=").append(getAspectNames());
|
||||
}
|
||||
if (getProperties() != null)
|
||||
{
|
||||
//sb.append(", properties=").append(getProperties());
|
||||
}
|
||||
if (getRelativePath() != null)
|
||||
{
|
||||
sb.append(", relativePath=").append(getRelativePath());
|
||||
}
|
||||
if (getAllowableOperations() != null)
|
||||
{
|
||||
sb.append(", allowableOperations=").append(getAllowableOperations());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user