Get all Childs of a Node

cancel
Showing results for 
Search instead for 
Did you mean: 
brucezhou
Active Member

Get all Childs of a Node

How can i get all childs of a node?
Must i do a Recursive call to .getChildAssocs(nodeRef)  ?

I want the deep listing!
For example i have a folder who have 5 sub-folders and some files. That 5 sub-folders have sub-folders, and files; and so on!
NodeService dont have methods who give the deep listing, for what i could see in the Api.

Thanks in advance

6 Replies
mehe
Senior Member II

Re: Get all Childs of a Node

you could use a path query ( PATH:"yourPath//." )   the //. searches recursive for all nodes, including yourPath.  //* would search recursively excluding yourPath.

But the path has to be a qName (app:company_home/....)

Second possibility: recurse through the path with javascript .getChildAsssocs or .children - could take long and is resource hungry.

afaust
Master

Re: Get all Childs of a Node

Yes, a PATH query with the double forward slash + asterisk will give you any children in any depth. But it will not be transactionally consistent as it relies on the search index which is asynchronously updated after changes occur. Also, a PATH query is traditionally one of the less performant selectors. An alternative is to use the ANCESTOR selector, which only requires the NodeRef of the folder for which you want to get all descendants. E.g. ANCESTOR:"workspace://SpacesStore/12345678". This avoids having to construct the path in the first place (which can be somewhat expensive depending on the depth of the root Folder, and avoid the reevaluation of the path by the index (path is fragmented and evaluated in various ways - front-to-back and back-to-front).

brucezhou
Active Member

Re: Get all Childs of a Node

Thanks for your reply,I want to know how to implement it by rest api?can you give me the code example?and the search is with the user permission?

afaust
Master

Re: Get all Childs of a Node

For examples about the ReST APIs please look at Alfresco 5.2. REST APIs. All operations will include permission checks as long as you do not explicitly disable them. ReST APIs typically do not support disabling permission checks via their parameters (unless you implement a custom API endpoint yourself with that feature).

mehe
Senior Member II

Re: Get all Childs of a Node

You can use Alfresco Content Services REST API Explorer to experiment with the REST apis.

mehe
Senior Member II

Re: Get all Childs of a Node

I totally forgot about GitHub - ciber/alfresco-js-batch-executer: Alfresco easy bulk processing with JavaScript 

this gives you a new root scope object which enables you to write a serverside JavaScript that iterates over the elements without the common problems like runtime, memory consumption, transaction size...

See the example from batch-executers page:

batchExecuter.processFolderRecursively({
    root: companyhome,
    onNode: function(node) {
        if (node.isDocument) {
            node.properties['cm:author'] = "Ciber NL";
            node.save();
        }
    }
});