Search in sources :

Example 1 with Paginated

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);
        }
    }
}
Also used : Paginated(org.n52.web.common.Paginated) OffsetBasedPagination(org.n52.web.common.OffsetBasedPagination)

Example 2 with 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());
}
Also used : Paginated(org.n52.web.common.Paginated) Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) OffsetBasedPagination(org.n52.web.common.OffsetBasedPagination) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OffsetBasedPagination (org.n52.web.common.OffsetBasedPagination)2 Paginated (org.n52.web.common.Paginated)2 IoParameters (org.n52.io.request.IoParameters)1 Stopwatch (org.n52.web.common.Stopwatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1