use of org.n52.web.common.Paginated in project series-rest-api by 52North.
the class ParameterController method preparePagingHeaders.
private void preparePagingHeaders(IoParameters parameters, HttpServletResponse response) {
if (parameters.containsParameter(Parameters.LIMIT) || parameters.containsParameter(Parameters.OFFSET)) {
Long elementcount = this.getElementCount(parameters.removeAllOf(Parameters.LIMIT).removeAllOf(Parameters.OFFSET));
if (elementcount > 0) {
int limit = parameters.getLimit();
int offset = parameters.getOffset();
OffsetBasedPagination obp = new OffsetBasedPagination(offset, limit);
Paginated paginated = new Paginated(obp, elementcount);
PageLinkUtil.addPagingHeaders(createCollectionUrl(getCollectionName()), response, paginated);
}
}
}
use of org.n52.web.common.Paginated in project series-rest-api by 52North.
the class StationsParameterController method getCollection.
@Override
@RequestMapping(method = RequestMethod.GET)
public ModelAndView getCollection(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) {
IoParameters map = createParameters(query, httpLocale, response).respectBackwardsCompatibility();
OutputCollection<?> result;
if (map.isExpanded()) {
Stopwatch stopwatch = Stopwatch.startStopwatch();
result = parameterService.getExpandedParameters(map);
logRequestTime(stopwatch);
} else {
Stopwatch stopwatch = Stopwatch.startStopwatch();
result = parameterService.getCondensedParameters(map);
logRequestTime(stopwatch);
}
// XXX refactor (is redundant here)
if (map.containsParameter("limit") || map.containsParameter("offset")) {
Long elementcount = this.counter.getStationCount();
if (elementcount != -1) {
OffsetBasedPagination obp = new OffsetBasedPagination(map.getOffset(), map.getLimit());
Paginated paginated = new Paginated(obp, elementcount);
String collectionHref = createCollectionUrl(getCollectionName());
PageLinkUtil.addPagingHeaders(collectionHref, response, paginated);
}
}
return new ModelAndView().addObject(result.getItems());
}
Aggregations