@Test public void given_view_result_size_is_equal_to_page_size_plus_one_then_next_link_should_exist() throws Exception { handler = new PageResponseHandler<TestDoc>(PageRequest.firstPage(4), TestDoc.class, new ObjectMapper()); Page<TestDoc> page = handler.success(ResponseOnFileStub.newInstance(200, "offset_view_result.json")); assertEquals(4, page.size()); assertTrue(page.isHasNext()); assertEquals("dcdaf08242a4be7da1a36e25f4f0b022", page.getNextPageRequest().getStartKeyDocId()); }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") public Page<T> success(HttpResponse hr) throws Exception { parser.parseResult(hr.getContent()); List<T> rows = parser.getRows(); int rowsSize = rows.size(); LOG.debug("got {} rows", rowsSize); if (pageRequest.isBack()) { Collections.reverse(rows); } int offset = pageRequest.isBack() ? 1 : 1; String nextId = parser.getLastId(); JsonNode nextKey = parser.getLastKey(); PageRequest.Builder b = pageRequest.nextRequest(nextKey, nextId); int currentPage = b.getPageNo(); PageRequest nextRequest = b.page(currentPage + 1).build(); PageRequest previousRequest = currentPage == 1 ? PageRequest.firstPage(pageRequest.getPageSize()) : b.back(true).page(currentPage - 1).build(); boolean hasMore = rowsSize == pageRequest.getPageSize() + offset; if (hasMore) { rows.remove(rows.size() - 1); } else if (!pageRequest.isBack()) { nextRequest = null; } if (currentPage == 0) { previousRequest = null; } return new Page<T>(rows, parser.getTotalRows(), pageRequest.getPageSize(), previousRequest, nextRequest); }
PageResponseHandler extends StdResponseHandler<Page<T>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") public Page<T> success(HttpResponse hr) throws Exception { parser.parseResult(hr.getContent()); List<T> rows = parser.getRows(); int rowsSize = rows.size(); LOG.debug("got {} rows", rowsSize); if (pageRequest.isBack()) { Collections.reverse(rows); } int offset = pageRequest.isBack() ? 1 : 1; String nextId = parser.getLastId(); JsonNode nextKey = parser.getLastKey(); PageRequest.Builder b = pageRequest.nextRequest(nextKey, nextId); int currentPage = b.getPageNo(); PageRequest nextRequest = b.page(currentPage + 1).build(); PageRequest previousRequest = currentPage == 1 ? PageRequest.firstPage(pageRequest.getPageSize()) : b.back(true).page(currentPage - 1).build(); boolean hasMore = rowsSize == pageRequest.getPageSize() + offset; if (hasMore) { rows.remove(rows.size() - 1); } else if (!pageRequest.isBack()) { nextRequest = null; } if (currentPage == 0) { previousRequest = null; } return new Page<T>(rows, parser.getTotalRows(), pageRequest.getPageSize(), previousRequest, nextRequest); } }
PageResponseHandler extends StdResponseHandler<Page<T>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") public Page<T> success(HttpResponse hr) throws Exception { parser.parseResult(hr.getContent()); List<T> rows = parser.getRows(); int rowsSize = rows.size(); LOG.debug("got {} rows", rowsSize); if (pageRequest.isBack()) { Collections.reverse(rows); } int offset = pageRequest.isBack() ? 1 : 1; String nextId = parser.getLastId(); JsonNode nextKey = parser.getLastKey(); PageRequest.Builder b = pageRequest.nextRequest(nextKey, nextId); int currentPage = b.getPageNo(); PageRequest nextRequest = b.page(currentPage + 1).build(); PageRequest previousRequest = currentPage == 1 ? PageRequest.firstPage(pageRequest.getPageSize()) : b.back(true).page(currentPage - 1).build(); boolean hasMore = rowsSize == pageRequest.getPageSize() + offset; if (hasMore) { rows.remove(rows.size() - 1); } else if (!pageRequest.isBack()) { nextRequest = null; } if (currentPage == 0) { previousRequest = null; } return new Page<T>(rows, parser.getTotalRows(), pageRequest.getPageSize(), previousRequest, nextRequest); } PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om);  PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om,
			boolean ignoreNotFound); }
PageResponseHandler extends StdResponseHandler<Page<T>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") public Page<T> success(HttpResponse hr) throws Exception { parser.parseResult(hr.getContent()); List<T> rows = parser.getRows(); int rowsSize = rows.size(); LOG.debug("got {} rows", rowsSize); if (pageRequest.isBack()) { Collections.reverse(rows); } int offset = pageRequest.isBack() ? 1 : 1; String nextId = parser.getLastId(); JsonNode nextKey = parser.getLastKey(); PageRequest.Builder b = pageRequest.nextRequest(nextKey, nextId); int currentPage = b.getPageNo(); PageRequest nextRequest = b.page(currentPage + 1).build(); PageRequest previousRequest = currentPage == 1 ? PageRequest.firstPage(pageRequest.getPageSize()) : b.back(true).page(currentPage - 1).build(); boolean hasMore = rowsSize == pageRequest.getPageSize() + offset; if (hasMore) { rows.remove(rows.size() - 1); } else if (!pageRequest.isBack()) { nextRequest = null; } if (currentPage == 0) { previousRequest = null; } return new Page<T>(rows, parser.getTotalRows(), pageRequest.getPageSize(), previousRequest, nextRequest); } PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om);  PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om,
			boolean ignoreNotFound); @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") Page<T> success(HttpResponse hr); }
PageResponseHandler extends StdResponseHandler<Page<T>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") public Page<T> success(HttpResponse hr) throws Exception { parser.parseResult(hr.getContent()); List<T> rows = parser.getRows(); int rowsSize = rows.size(); LOG.debug("got {} rows", rowsSize); if (pageRequest.isBack()) { Collections.reverse(rows); } int offset = pageRequest.isBack() ? 1 : 1; String nextId = parser.getLastId(); JsonNode nextKey = parser.getLastKey(); PageRequest.Builder b = pageRequest.nextRequest(nextKey, nextId); int currentPage = b.getPageNo(); PageRequest nextRequest = b.page(currentPage + 1).build(); PageRequest previousRequest = currentPage == 1 ? PageRequest.firstPage(pageRequest.getPageSize()) : b.back(true).page(currentPage - 1).build(); boolean hasMore = rowsSize == pageRequest.getPageSize() + offset; if (hasMore) { rows.remove(rows.size() - 1); } else if (!pageRequest.isBack()) { nextRequest = null; } if (currentPage == 0) { previousRequest = null; } return new Page<T>(rows, parser.getTotalRows(), pageRequest.getPageSize(), previousRequest, nextRequest); } PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om);  PageResponseHandler(PageRequest pr, Class<T> docType, ObjectMapper om,
			boolean ignoreNotFound); @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DB_DUPLICATE_BRANCHES") Page<T> success(HttpResponse hr);  }