RemoteProcessDocumentsServiceImpl implements ProcessDocumentsService { @Override public PageResponse<DocumentSummary> getData(QueryFilter filter) { PageResponse<DocumentSummary> response = new PageResponse<DocumentSummary>(); List<DocumentSummary> documents = getDocuments(filter); response.setStartRowIndex(filter.getOffset()); response.setTotalRowSizeExact(true); response.setTotalRowSize(documents.size()); if (!documents.isEmpty()) { if (documents.size() > (filter.getCount() + filter.getOffset())) { response.setPageRowList(new ArrayList<DocumentSummary>(documents.subList(filter.getOffset(), filter.getOffset() + filter.getCount()))); response.setLastPage(false); } else { response.setPageRowList(new ArrayList<DocumentSummary>(documents.subList(filter.getOffset(), documents.size()))); response.setLastPage(true); } } else { response.setPageRowList(new ArrayList<DocumentSummary>(documents)); response.setLastPage(true); } return response; }  @Override PageResponse<DocumentSummary> getData(QueryFilter filter);  }
@Test public void testGetData() { when(processVariablesService.getProcessVariables(any())).thenReturn(singletonList(newDocumentVariable())); QueryFilter queryFilter = new PortableQueryFilter(0, 10, false, "", "", true); queryFilter.getParams().put(serverTemplateId, serverTemplateId); final PageResponse<DocumentSummary> response = processDocumentsService.getData(queryFilter); assertEquals(1, response.getTotalRowSize()); assertEquals(0, response.getStartRowIndex()); assertTrue(response.isTotalRowSizeExact()); assertTrue(response.isFirstPage()); assertTrue(response.isLastPage()); }
@Test public void testGetDataPaginated() { int totalItems = 12; List<ProcessVariableSummary> processVariableSummaries = new ArrayList<>(); IntStream.range(0, totalItems).forEach(i -> processVariableSummaries.add(newDocumentVariable())); processVariableSummaries.add(new ProcessVariableSummary("", "", 9L, "", "test", 0l, "test")); when(processVariablesService.getProcessVariables(any())).thenReturn(processVariableSummaries); QueryFilter queryFilter = new PortableQueryFilter(0, 10, false, "", "", true); queryFilter.getParams().put(serverTemplateId, serverTemplateId); final PageResponse<DocumentSummary> response = processDocumentsService.getData(queryFilter); assertEquals(13, processVariableSummaries.size()); assertEquals(10, response.getPageRowList().size()); assertEquals(totalItems, response.getTotalRowSize()); assertEquals(0, response.getStartRowIndex()); assertTrue(response.isTotalRowSizeExact()); assertTrue(response.isFirstPage()); assertFalse(response.isLastPage()); }