Reputation: 2302
I'm using the Alfresco Rest Api but I can't find any option that would return the whole tree with all sub-folders.
I want to go down to the last file even if it's 'wrapped' in 3 sub folders.
Any ideas ?
Upvotes: 0
Views: 1310
Reputation: 513
To retrieve all documents you can use this service
Or you can create your custom webscript and get nodes recursively like that for example:
/**
*
* @param type
* @param nodeRef
* @return true if node type equals or inherit from type <code>type</code>
*/
protected boolean hasSubType(QName type, NodeRef nodeRef) {
List<QName> subTypes = new ArrayList<>();
subTypes.addAll(dictionaryService.getSubTypes(type, true));
QName nodeType = nodeService.getType(nodeRef);
return nodeType.equals(type) || subTypes.contains(nodeType);
}
private void getNodesRecursive(NodeRef node, List<NodeRef> documents) {
if (hasSubType(ContentModel.TYPE_FOLDER, node)) {
List<ChildAssociationRef> children = nodeService.getChildAssocs(node, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef child : children) {
NodeRef childNode = child.getChildRef();
if (hasSubType(ContentModel.TYPE_CONTENT, node)) {
documents.add(childNode);
} else if (hasSubType(ContentModel.TYPE_FOLDER, node)) {
// documents.add(childNode);
getNodesRecursive(childNode, documents);
}
}
} else {
documents.add(node);
}
}
Upvotes: 0
Reputation: 1348
Please refer categoryService
to list all files in any nested sub folders. Here
nodeRef
is parent folder's noderef
Using categoryService it is also possible to list all the children of a folder.
Collection<ChildAssociationRef> children = categoryService.getChildren(new NodeRef(nodeRef), CategoryService.Mode.ALL, CategoryService.Depth.ANY);
Upvotes: 2
Reputation: 3175
Create a java baked webscript which will return the node of below object.
public class ReportNode {
private NodeRef currentNode;
private List<ReportNode> children;
private Map<String, String> properties = new HashMap<>();
private boolean isFolder;
private String name;
private String type;
private List<String> aspects;
//Getter Setters
}
In above structure
currentNode represents the current nodered in list
children represents the children of a node
Other things are well understood.
Fill up the data in above linked list structure by node crawling.
For displaying the crawled data.You can use the below freemarker template.
<#macro recurse_macro nodeRef>
<ul>
<li>
<@print_properties reportNode=nodeRef/>
</li>
</ul>
</#macro>
<#macro print_properties reportNode>
<ul>
<li>
<a>Properties</a>
<ul>
<#list reportNode.properties?keys as key>
<li>${key} : ${reportNode.properties[key]}
</#list>
</ul>
</li>
</ul>
</#macro>
<@recurse_macro nodeRef=nodeRef/>
where noderef is root node of the linked list which is created by crawling the nodes.
Upvotes: 1
Reputation: 2246
I don't think you can.
You could execute a PATH query though, since it can be written in a way to return all children, too.
For example:
var folder = search.luceneSearch("+PATH:\"/app:company_home/cm:Test_x0020_Folder//*\" AND (TYPE:\"cm:content\" OR TYPE:\"cm:folder\")");
Upvotes: 1