}
@Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException {
PageRequest p = null;
MultivaluedMap<String, String> params = request.getUri().getQueryParameters();
String page = params.getFirst(PageRequest.PAGE_PARAM);
String perPage = params.getFirst(PageRequest.PER_PAGE_PARAM);
String order = params.getFirst(PageRequest.ORDER_PARAM);
String sortBy = params.getFirst(PageRequest.SORT_BY_PARAM);
if (page != null || perPage != null || order != null || sortBy != null) {
p = new PageRequest();
if (order == null) {
p.setOrder(PageRequest.DEFAULT_ORDER);
}
else {
p.setOrder(readOrder(order));
}
/* We'll leave it to the curator layer to figure out what to sort by if
* sortBy is null. */
p.setSortBy(sortBy);
try {
if (page == null && perPage != null) {
p.setPage(PageRequest.DEFAULT_PAGE);
p.setPerPage(readInteger(perPage));
}
else if (page != null && perPage == null) {
p.setPage(readInteger(page));
p.setPerPage(PageRequest.DEFAULT_PER_PAGE);
}
else {
p.setPage(readInteger(page));
p.setPerPage(readInteger(perPage));
}
}
catch (NumberFormatException nfe) {
throw new BadRequestException(i18n.tr("offset and limit parameters" +
" must be positive integers"), nfe);