Search in sources :

Example 1 with Sort

use of com.b2international.snowowl.core.request.SearchResourceRequest.Sort in project snow-owl by b2ihealthcare.

the class AbstractRestService method extractSortFields.

/**
 * Extract {@link SearchResourceRequest.Sort}s from the given list of sortKeys. The returned list maintains the same order as the input sortKey
 * list.
 *
 * @param sortKeys
 * @return
 */
protected final List<Sort> extractSortFields(List<String> sortKeys) {
    if (CompareUtils.isEmpty(sortKeys)) {
        return Collections.emptyList();
    }
    final List<Sort> result = Lists.newArrayList();
    for (String sortKey : sortKeys) {
        Matcher matcher = sortKeyPattern.matcher(sortKey);
        if (matcher.matches()) {
            String field = matcher.group(1);
            String order = matcher.group(2);
            result.add(SearchResourceRequest.SortField.of(field, !"desc".equals(order)));
        } else {
            throw new BadRequestException("Sort key '%s' is not supported, or incorrect sort field pattern.", sortKey);
        }
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Aggregations

BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Sort (com.b2international.snowowl.core.request.SearchResourceRequest.Sort)1 Matcher (java.util.regex.Matcher)1