AME
AME

Reputation: 2302

How do I recursively display all files and subfolders?

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

Answers (4)

Oussama Werfelli
Oussama Werfelli

Reputation: 513

To retrieve all documents you can use this service

http://localhost:8080/share/service/components/documentlibrary/data/doclist/all/site/XXXX/documentLibrary?filter=all&noCache=1521477198549

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

Vikash Patel
Vikash Patel

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

Krutik Jayswal
Krutik Jayswal

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

Lista
Lista

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

Related Questions