mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1058 / REPO-1242: REST API - list sites - add option to orderBy (id, title or description)
- initial implementation (note: default remains "id asc") - TODO add tests (see REPO-1244) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130681 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -73,4 +73,8 @@ public interface Sites
|
||||
String PARAM_PERMANENT = "permanent";
|
||||
String PARAM_SKIP_ADDTOFAVORITES = "skipAddToFavorites";
|
||||
String PARAM_SKIP_SURF_CONFIGURATION = "skipConfiguration";
|
||||
|
||||
String PARAM_SITE_ID = "id";
|
||||
String PARAM_SITE_TITLE = "title";
|
||||
String PARAM_SITE_DESCRIPTION = "description";
|
||||
}
|
||||
|
@@ -78,7 +78,6 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.preference.PreferenceService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
@@ -91,7 +90,6 @@ import org.alfresco.service.cmr.view.ImporterProgress;
|
||||
import org.alfresco.service.cmr.view.ImporterService;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ISO9075;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -117,6 +115,17 @@ public class SitesImpl implements Sites
|
||||
|
||||
private static final String SITE_ID_VALID_CHARS_PARTIAL_REGEX = "A-Za-z0-9\\-";
|
||||
|
||||
private final static Map<String,QName> SORT_PARAMS_TO_QNAMES;
|
||||
static
|
||||
{
|
||||
Map<String,QName> aMap = new HashMap<>(3);
|
||||
aMap.put(PARAM_SITE_TITLE, ContentModel.PROP_TITLE);
|
||||
aMap.put(PARAM_SITE_ID, ContentModel.PROP_NAME);
|
||||
aMap.put(PARAM_SITE_DESCRIPTION, ContentModel.PROP_DESCRIPTION);
|
||||
SORT_PARAMS_TO_QNAMES = Collections.unmodifiableMap(aMap);
|
||||
}
|
||||
|
||||
|
||||
protected Nodes nodes;
|
||||
protected People people;
|
||||
protected NodeService nodeService;
|
||||
@@ -647,8 +656,27 @@ public class SitesImpl implements Sites
|
||||
Paging paging = parameters.getPaging();
|
||||
PagingRequest pagingRequest = Util.getPagingRequest(paging);
|
||||
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
|
||||
|
||||
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
|
||||
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, Boolean.TRUE));
|
||||
List<SortColumn> sortCols = parameters.getSorting();
|
||||
if ((sortCols != null) && (sortCols.size() > 0))
|
||||
{
|
||||
for (SortColumn sortCol : sortCols)
|
||||
{
|
||||
QName sortPropQName = SORT_PARAMS_TO_QNAMES.get(sortCol.column);
|
||||
if (sortPropQName == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Invalid sort field: "+sortCol.column);
|
||||
}
|
||||
sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// default sort order
|
||||
sortProps.add(new Pair<>(ContentModel.PROP_NAME, Boolean.TRUE));
|
||||
}
|
||||
|
||||
final PagingResults<SiteInfo> pagingResult = siteService.listSites(null, sortProps, pagingRequest);
|
||||
final List<SiteInfo> sites = pagingResult.getPage();
|
||||
int totalItems = pagingResult.getTotalResultCount().getFirst();
|
||||
|
Reference in New Issue
Block a user