REPO-1058 / REPO-1242: REST API - list sites that person is member of - fix orderBy (id, title or role)

- fix orderBy validation as per existing capabilities
- TODO add tests (see REPO-1244)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130774 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-09-19 10:56:09 +00:00
parent 18f3a6b7b3
commit 660d46a829
2 changed files with 26 additions and 18 deletions

View File

@@ -77,4 +77,6 @@ public interface Sites
String PARAM_SITE_ID = "id";
String PARAM_SITE_TITLE = "title";
String PARAM_SITE_DESCRIPTION = "description";
String PARAM_SITE_ROLE = "role";
}

View File

@@ -125,6 +125,16 @@ public class SitesImpl implements Sites
SORT_PARAMS_TO_QNAMES = Collections.unmodifiableMap(aMap);
}
private final static Map<String,SiteService.SortFields> SORT_SITE_MEMBERSHIP;
static
{
Map<String,SiteService.SortFields> aMap = new HashMap<>(3);
aMap.put(PARAM_SITE_TITLE, SiteService.SortFields.SiteTitle);
aMap.put(PARAM_SITE_ID, SiteService.SortFields.SiteShortName);
aMap.put(PARAM_SITE_ROLE, SiteService.SortFields.Role);
SORT_SITE_MEMBERSHIP = Collections.unmodifiableMap(aMap);
}
protected Nodes nodes;
protected People people;
@@ -500,28 +510,24 @@ public class SitesImpl implements Sites
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// get the sorting options
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(parameters.getSorting().size());
for (SortColumn sortColumn : parameters.getSorting())
{
SiteService.SortFields sortField;
try
{
sortField= SiteService.SortFields.valueOf(sortColumn.column);
}
catch (IllegalArgumentException ex)
{
// invalid sort field
continue;
}
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<>(parameters.getSorting().size());
sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(
sortField,
(sortColumn.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
}
// if no sorting options were specify, sort by title
if(sortPairs.size() == 0)
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0))
{
for (SortColumn sortCol : sortCols)
{
SiteService.SortFields sortProp = SORT_SITE_MEMBERSHIP.get(sortCol.column);
if (sortProp == null)
{
throw new InvalidArgumentException("Invalid sort field: "+sortCol.column);
}
sortPairs.add(new Pair<>(sortProp, (sortCol.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
}
}
else
{
// default sort order
sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(
SiteService.SortFields.SiteTitle,
SortOrder.ASCENDING ));