Search in sources :

Example 1 with PageImplRepresentation

use of org.openlmis.stockmanagement.util.PageImplRepresentation in project openlmis-stockmanagement by OpenLMIS.

the class BaseCommunicationService method doPageRequest.

private <E> ResponseEntity<PageImplRepresentation<E>> doPageRequest(String url, RequestParameters parameters, Object payload, HttpMethod method, Class<E> type) {
    HttpEntity<Object> entity = createEntity(payload);
    ParameterizedTypeReference<PageImplRepresentation<E>> parameterizedType = new DynamicPageTypeReference<>(type);
    List<PageImplRepresentation<E>> pages = new ArrayList<>();
    for (URI uri : RequestHelper.splitRequest(url, parameters, maxUrlLength)) {
        pages.add(restTemplate.exchange(uri, method, entity, parameterizedType).getBody());
    }
    PageImplRepresentation<E> body = Merger.ofPages(pages).withDefaultValue(PageImplRepresentation::new).merge();
    return new ResponseEntity<>(body, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageImplRepresentation(org.openlmis.stockmanagement.util.PageImplRepresentation) ArrayList(java.util.ArrayList) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 DynamicPageTypeReference (org.openlmis.stockmanagement.util.DynamicPageTypeReference)1 PageImplRepresentation (org.openlmis.stockmanagement.util.PageImplRepresentation)1 ResponseEntity (org.springframework.http.ResponseEntity)1