cancel
Showing results for 
Search instead for 
Did you mean: 

FileFolderService.list(): sort by folder, then by file

hutago
Champ in-the-making
Champ in-the-making
Hello,

I am using the FileFolderService <a href="http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/model/FileFolderServi...">list</a> method to list files and folders in a custom web script, but I cannot figure out how to sort by file/folder type.

I see that the list method takes a List<Pair<QName, Boolean>> as the sortProps parameters. So if I wanted to sort first by creator and then by name, I would create a List like so:


import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;


List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_CREATOR, true));
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true));


But I do not see any property that I could use to sort by type to group the folders together and the files together. It would be nice if I could create a sortProps to sort on FileFolderServiceType first, and then the name property like so:


List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
sortProps.add(new Pair<QName, Boolean>(ContentModel.FILE_FOLDER_TYPE, true));
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true));


Of course there is no QName ContentModel.FILE_FOLDER_TYPE, but is there anything like this that I can use?

My desire is to create a view to use my web script which would (by default) sort by title - folders first followed by files. If the user wishes to sort by something else, the folders and files may be mixed in together. The view will be paged, using something like <a href="http://www.infinite-scroll.com/">infinite-scroll</a>

I see there was an issue created in Jira for Share which may be similar: https://issues.alfresco.com/jira/browse/MNT-2275. I am not using Share for this, but I was wondering if its fix can fix my problem.

I am developing for Alfresco v4.1.2.
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
You can try to use following properties which are defined in org.alfresco.repo.node.getchildren.GetChildrenCannedQuery

    public static final QName SORT_QNAME_NODE_TYPE = QName.createQName("", "TYPE");
    public static final QName SORT_QNAME_NODE_IS_FOLDER = QName.createQName("", "IS_FOLDER");

hutago
Champ in-the-making
Champ in-the-making
Thank you, kaynezhang. The
SORT_QNAME_NODE_TYPE
was exactly what I was looking for. It worked splendidly!