AnsweredAssumed Answered

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

Question asked by hutago on Jan 24, 2014
Latest reply on Jan 27, 2014 by hutago
Hello,

I am using the FileFolderService <a href="http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/model/FileFolderService.html#list(org.alfresco.service.cmr.repository.NodeRef,%20boolean,%20boolean,%20java.util.Set,%20java.util.List,%20org.alfresco.query.PagingRequest)">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.

Outcomes