List of usage examples for org.springframework.data.domain Page getContent
List<T> getContent();
From source file:com.chessix.vas.service.RdbmsStorage.java
@Override public List<Integer> accountValues(final String clasId) { final List<Integer> result = Lists.newLinkedList(); int page = 0; Page<Account> accounts; do {//from w ww . j a v a 2s . c o m accounts = dbService.findAccountsByClas(clasId, new PageRequest(page, PAGE_SIZE)); result.addAll(Lists.transform(accounts.getContent(), new Function<Account, Integer>() { @Override public Integer apply(final Account input) { return input.getBalance(); } })); page += 1; } while (accounts.hasNext()); return result; }
From source file:com.pamarin.income.lazyload.LazyLoad.java
@Override public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { Sort.Direction direction;/*from w w w . ja va2 s . c o m*/ if (sortOrder == SortOrder.ASCENDING) { direction = Sort.Direction.ASC; } else { direction = Sort.Direction.DESC; } if (sortField == null) { sortField = "id"; } Page<T> page = load(new PageRequest(first / pageSize, pageSize, direction, sortField)); if (page != null) { list = page.getContent(); totalElements = page.getTotalElements(); this.setRowCount((int) totalElements); } else { list = null; totalElements = 0L; setRowCount(0); } return list; }
From source file:com.trenako.results.PaginatedListsTests.java
@Test public void shouldReturnEmptyPagesWhenPaginationIsOutOfBound() { Page<String> page = PaginatedLists.paginate(values(47), paging(8, 10)); assertNotNull(page);/*from w ww . j a v a2s . co m*/ assertEquals(0, page.getTotalElements()); assertEquals(0, page.getContent().size()); }
From source file:org.thingsplode.server.repositories.RepositoryTest.java
@Test @Transactional// w w w . j av a2 s. c o m public void test2Events() throws UnknownHostException { String deviceID = "test_device_1"; String serialNumber = "12345"; deviceRepo.save(TestFactory.createDevice(deviceID, serialNumber, "1")); Device d = deviceRepo.findByIdentification(deviceID); Assert.assertTrue("The serial number should match", serialNumber.equalsIgnoreCase(d.getSerialNumber())); Assert.assertTrue("The version should be 1", "1".equalsIgnoreCase(d.getModel().getVersion())); d.getModel().setVersion("2"); deviceRepo.save(d); d = deviceRepo.findByIdentification(deviceID); Assert.assertTrue("The version should be 2", "2".equalsIgnoreCase(d.getModel().getVersion())); Assert.assertNotNull("The device id shall not be null at this stage", d.getId()); for (int i = 1; i <= 100; i++) { Event devt = Event .create("some-special-event", "some-special-event-class", Event.EventType.STATE_UPDATE, Event.Severity.INFO, Calendar.getInstance()) .putComponent(d).putReceiveDate(Calendar.getInstance()) .addIndication("peak", Value.Type.NUMBER, Integer.toString(i)); Event cevt = Event .create("a component event", "comp event class", Event.EventType.STATE_UPDATE, Event.Severity.ERROR, Calendar.getInstance()) .putComponent((Component) d.getComponents().toArray()[0]).putReceiveDate(Calendar.getInstance()) .addIndication("peak", Value.Type.TEXT, "componnent indication"); eventRepo.save(devt); eventRepo.save(cevt); } int evtCount = (int) eventRepo.count(); Assert.assertTrue("There should be 200 device events in the database at this stage, but there were: " + evtCount + ".", evtCount == 200); Page<Event> deviceEvtPage = eventRepo.findByComponent(d, new PageRequest(0, 300)); int deviceEvtCount = deviceEvtPage.getContent().size(); Assert.assertTrue("there should be 100 device events instead of [" + deviceEvtCount + "]", deviceEvtCount == 100); eventRepo.deleteAll(); deviceRepo.delete(d); deviceAssertions(0); }
From source file:example.springdata.jpa.projections.CustomerRepositoryIntegrationTest.java
@Test public void supportsProjectionInCombinationWithPagination() { Page<CustomerProjection> page = customers .findPagedProjectedBy(new PageRequest(0, 1, new Sort(Direction.ASC, "lastname"))); assertThat(page.getContent().get(0).getFirstname(), is("Carter")); }
From source file:com.dm.estore.search.services.impl.CatalogSearchServiceImpl.java
@Override public ProductSearchResultDto findProducts(ProductSearchDto searchRequest) { Sort sort = new Sort(Sort.Direction.fromString(searchRequest.getSortOrder()), searchRequest.getSortColumn()); PageRequest pageRequest = new PageRequest(searchRequest.getPage(), searchRequest.getPageSize(), sort); FacetPage<CatalogItemDto> catalogItems = catalogSearchRepository.searchProducts( searchRequest.getSearchTerms(), searchRequest.getCategory(), searchRequest.getMaterials(), searchRequest.getColors(), pageRequest); ProductSearchResultDto result = new ProductSearchResultDto(); result.setTotalCount(catalogItems.getTotalElements()); for (Page<? extends FacetEntry> page : catalogItems.getAllFacets()) { for (FacetEntry facetEntry : page.getContent()) { String key = String.valueOf(facetEntry.getKey()); String facetCode = facetEntry.getValue(); // name of the category long count = facetEntry.getValueCount(); // number of books in this category if (StringUtils.isEmpty(facetCode)) continue; if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) { result.getCategoriesFacet().put(facetCode, count); } else if (CatalogItemDto.FIELD_VARIANT_GROUP.equalsIgnoreCase(key)) { result.getGroupFacet().put(facetCode, count); } else if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) { result.getSubGroupFacet().put(facetCode, count); }//w w w. ja va 2 s. c o m } } result.setProducts(productConverter.convert(catalogItems.getContent())); result.setTotalCount((int) (catalogItems.getTotalElements())); return result; }
From source file:ru.portal.gwt.gwtportal.server.GWTServiceImpl.java
@Override public PagingLoadResult<Map<String, String>> fetchTableOrViewData(PagingLoadConfig config, String tableOrViewName) { //List<? extends SortInfo> sortList = config.getSortInfo(); //Sort sort = new Sort(Sort.Direction.DESC, "login"); int limit = 50; int page = 0; int offset = 0; if (config != null) { page = (config.getLimit() != 0 && config.getOffset() > 0) ? (config.getOffset() / config.getLimit()) : 0;// ww w . j a v a 2 s . c o m limit = config.getLimit(); offset = config.getOffset(); } Pageable pageable = new PageRequest(page, limit); //TODO sort + page size + ?b Page<HashMap<String, String>> result = tableService.findAll(tableOrViewName, pageable); ArrayList<HashMap<String, String>> res = new ArrayList<>(result.getContent()); return new PagingLoadResultBean(res, (int) result.getTotalElements(), offset); }
From source file:com.bill99.yn.webmgmt.repository.TransactionSummaryDaoTest.java
@Test public void testFindAllByUserId() throws Exception { Date startDateTime = Utils.parseDateTime("2014-02-17 23:57:00"); Date endDateTime = Utils.parseDateTime("2014-02-18 23:57:10"); PageRequest pageRequest = new PageRequest(0, 10); String[] allCustomerNames = new String[2]; allCustomerNames[0] = ""; allCustomerNames[1] = "????"; Page<TransactionSummary> transactionSummarys = transactionSummaryDao .findByCustomerNameInAndSummaryDateBetween(allCustomerNames, startDateTime, endDateTime, pageRequest);/* w w w. j a v a 2 s . c o m*/ for (TransactionSummary t : transactionSummarys.getContent()) { System.out.println(t); } }
From source file:com.dickthedeployer.dick.web.service.BuildService.java
@Transactional public void deleteBuilds(Project project) { PageRequest pageable = new PageRequest(0, 20); Page<Build> page; do {// w ww . j a v a 2 s . c o m page = buildDao.findByProject(project, pageable); page.getContent().stream().forEach(build -> { jobBuildService.deleteJobBuilds(build); buildDao.delete(build); }); } while (page.hasNext()); }
From source file:com.restfiddle.controller.rest.TagController.java
@RequestMapping(value = "/api/workspaces/{workspaceId}/tags/{tagId}/nodes", method = RequestMethod.GET) public @ResponseBody List<NodeDTO> findNodesByTag(@PathVariable("workspaceId") String workspaceId, @PathVariable("tagId") String tagId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "limit", required = false) Integer limit) { logger.debug("Finding nodes by tag id: " + tagId); int pageNo = 0; if (page != null && page > 0) { pageNo = page;//from w w w . jav a 2s . c om } int numberOfRecords = 10; if (limit != null && limit > 0) { numberOfRecords = limit; } Sort sort = new Sort(Direction.DESC, "lastModifiedDate"); Pageable pageable = new PageRequest(pageNo, numberOfRecords, sort); Page<BaseNode> paginatedTaggedNodes = nodeRepository.findTaggedNodes(tagId, pageable); List<BaseNode> taggedNodes = paginatedTaggedNodes.getContent(); List<NodeDTO> response = new ArrayList<NodeDTO>(); for (BaseNode item : taggedNodes) { response.add(EntityToDTO.toDTO(item)); } return response; }