Search in sources :

Example 1 with SortDefinition

use of org.alfresco.service.cmr.search.SearchParameters.SortDefinition in project alfresco-remote-api by Alfresco.

the class SearchMapper method fromSort.

/**
 * SearchParameters from List<SortDef>
 * @param sp SearchParameters
 * @param sort List<SortDef>
 */
public void fromSort(SearchParameters sp, List<SortDef> sort) {
    if (sort != null && !sort.isEmpty()) {
        if (LANGUAGE_CMIS_ALFRESCO.equals(sp.getLanguage())) {
            throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": sort {} not allowed with cmis language" });
        }
        for (SortDef sortDef : sort) {
            try {
                SortType sortType = SortType.valueOf(sortDef.getType());
                String field = sortDef.getField();
                sp.addSort(new SortDefinition(sortType, field, sortDef.isAscending()));
            } catch (IllegalArgumentException e) {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { sortDef.getType() });
            }
        }
    }
}
Also used : SortType(org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortDef(org.alfresco.rest.api.search.model.SortDef) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition)

Aggregations

SortDef (org.alfresco.rest.api.search.model.SortDef)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 SortDefinition (org.alfresco.service.cmr.search.SearchParameters.SortDefinition)1 SortType (org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType)1