List of usage examples for org.springframework.data.domain Page iterator
Iterator<T> iterator();
From source file:com.javiermoreno.springboot.mvc.users.UserManagementServiceImpl.java
@Override @Transactional// w ww .ja v a 2 s . co m public Pair<List<DailyUser>, Long> retrieveAllUsers(@Min(0) int pageNumber, int amount, Sort.Direction direction, String sortingProperty) { PageRequest pr; if (direction != null && sortingProperty != null) { pr = new PageRequest(pageNumber, amount, direction, sortingProperty); } else { pr = new PageRequest(pageNumber, amount); } Page page = userRepository.findAll(pr); return new ImmutablePair(Lists.newArrayList(page.iterator()), page.getTotalElements()); }
From source file:com.venilnoronha.dzone.feed.fetcher.LinksFetcher.java
private Date findLastDumpedLink() { Date lastDumpedDate = null;//from w w w . jav a 2 s .c om Pageable page = new PageRequest(0, 1, Direction.DESC, "linkDate"); Page<Link> links = linksRepository.findAll(page); Iterator<Link> linksIter = links.iterator(); if (linksIter.hasNext()) { Link lastDumpedLink = linksIter.next(); lastDumpedDate = lastDumpedLink.getLinkDate(); } return lastDumpedDate; }
From source file:org.devgateway.toolkit.forms.wicket.providers.SortableJpaRepositoryDataProvider.java
/** * @see SortableDataProvider#iterator(long, long) */// w w w. j a v a 2 s.c o m @Override public Iterator<? extends T> iterator(final long first, final long count) { int page = (int) ((double) first / WebConstants.PAGE_SIZE); Page<T> findAll = jpaRepository.findAll(filterState.getSpecification(), new PageRequest(page, WebConstants.PAGE_SIZE, translateSort())); return findAll.iterator(); }
From source file:com.venilnoronha.dzone.feed.fetcher.ArticlesFetcher.java
private Date findLastDumpedArticle(String category) { Date lastDumpedDate = null;/*from w w w .j a v a 2 s . c om*/ Pageable page = new PageRequest(0, 1, Direction.DESC, "articleDate"); Page<Article> articles = articlesRepository.findByCategory(category, page); Iterator<Article> articlesIter = articles.iterator(); if (articlesIter.hasNext()) { Article lastDumpedArticle = articlesIter.next(); lastDumpedDate = lastDumpedArticle.getArticleDate(); } return lastDumpedDate; }
From source file:sk.lazyman.gizmo.data.provider.BasicDataProvider.java
@Override public Iterator<? extends T> iterator(long first, long count) { int pageIndex = (int) Math.ceil((double) first / (double) itemsPerPage); LOG.debug("Setting page request: page {}, size {}", pageIndex, itemsPerPage); Predicate predicate = getPredicate(); PageRequest page = new PageRequest(pageIndex, itemsPerPage, sort); Page<T> found; if (predicate == null) { found = repository.findAll(page); } else {/*from ww w.j a v a 2 s. c om*/ QueryDslPredicateExecutor executor = (QueryDslPredicateExecutor) repository; found = executor.findAll(predicate, page); } if (found != null) { return found.iterator(); } return new ArrayList<T>().iterator(); }
From source file:com.epam.ta.reportportal.core.launch.impl.GetLaunchHandler.java
@Override public LaunchResource getLaunchByName(String project, Pageable pageable, Filter filter, String username) { filter.addCondition(new FilterCondition(EQUALS, false, project, Launch.PROJECT)); Page<Launch> launches = launchRepository.findByFilter(filter, pageable); expect(launches, notNull()).verify(LAUNCH_NOT_FOUND); return launchResourceAssember.toResource(launches.iterator().next()); }
From source file:com.venilnoronha.dzone.feed.web.LinksRSSController.java
@RequestMapping(value = "/rss/links", method = RequestMethod.GET) public ModelAndView linksRssByLastModified(HttpEntity<byte[]> requestEntity, HttpServletRequest request, HttpServletResponse response) throws ParseException { HttpUtils.logUserIP("LinksRSS", request); String lastModified = requestEntity.getHeaders().getFirst("If-Modified-Since"); if (lastModified == null) { lastModified = requestEntity.getHeaders().getFirst("If-None-Match"); }/*w w w. java2s . c o m*/ PageRequest page = new PageRequest(0, feedSize, Direction.DESC, "linkDate"); Page<Link> linkPage; if (lastModified != null) { Date lastModifiedDt = HTTP_FORMAT.parse(lastModified); linkPage = linksRepository.findByLinkDateBetween(lastModifiedDt, new Date(), page); } else { linkPage = linksRepository.findAll(page); } Iterator<Link> linksIter = linkPage.iterator(); List<Link> links = new ArrayList<>(); Date newLastModified = null; while (linksIter.hasNext()) { Link link = linksIter.next(); Date linkDate = link.getLinkDate(); if (newLastModified == null || newLastModified.before(linkDate)) { newLastModified = linkDate; } links.add(link); } if (links.isEmpty() && lastModified != null) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return null; } else { response.setHeader("ETag", HTTP_FORMAT.format(newLastModified)); response.setHeader("Last-Modified", HTTP_FORMAT.format(newLastModified)); ModelAndView mav = new ModelAndView(); mav.setView(new LinksRSSView(links)); return mav; } }
From source file:com.venilnoronha.dzone.feed.web.ArticlesRSSController.java
@RequestMapping(value = "/rss/articles", method = RequestMethod.GET) public ModelAndView articlesRssByLastModified(HttpEntity<byte[]> requestEntity, HttpServletRequest request, HttpServletResponse response) throws ParseException { HttpUtils.logUserIP("ArticlesRSS", request); String lastModified = requestEntity.getHeaders().getFirst("If-Modified-Since"); if (lastModified == null) { lastModified = requestEntity.getHeaders().getFirst("If-None-Match"); }//from w w w . ja v a 2 s .c o m PageRequest page = new PageRequest(0, feedSize, Direction.DESC, "articleDate"); Page<Article> articlePage; if (lastModified != null) { Date lastModifiedDt = HTTP_FORMAT.parse(lastModified); articlePage = articlesRepository.findByArticleDateBetween(lastModifiedDt, new Date(), page); } else { articlePage = articlesRepository.findAll(page); } Iterator<Article> articlesIter = articlePage.iterator(); List<Article> articles = new ArrayList<>(); Date newLastModified = null; while (articlesIter.hasNext()) { Article article = articlesIter.next(); Date articleDate = article.getArticleDate(); if (newLastModified == null || newLastModified.before(articleDate)) { newLastModified = articleDate; } articles.add(article); } if (articles.isEmpty() && lastModified != null) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return null; } else { response.setHeader("ETag", HTTP_FORMAT.format(newLastModified)); response.setHeader("Last-Modified", HTTP_FORMAT.format(newLastModified)); ModelAndView mav = new ModelAndView(); mav.setView(new ArticlesRSSView(articles)); return mav; } }
From source file:com.contact.ContactController.java
@ResponseBody @RequestMapping(value = "/listgrid", method = RequestMethod.GET, produces = "application/json") public ContactGrid listGrid(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "rows", required = false) Integer rows, @RequestParam(value = "sidx", required = false) String sortBy, @RequestParam(value = "sord", required = false) String order) { logger.info("Listing contacts for grid with page: {}, rows: {}", page, rows); logger.info("Listing contacts for grid with sort: {}, order: {}", sortBy, order); // Process order by Sort sort = null;/*from w ww . j ava2s . c om*/ String orderBy = sortBy; if (orderBy != null && orderBy.equals("birthDateString")) orderBy = "birthDate"; if (orderBy != null && order != null) { if (order.equals("desc")) { sort = new Sort(Sort.Direction.DESC, orderBy); } else sort = new Sort(Sort.Direction.ASC, orderBy); } // Constructs page request for current page // Note: page number for Spring Data JPA starts with 0, while jqGrid starts with 1 PageRequest pageRequest = null; if (sort != null) { pageRequest = new PageRequest(page - 1, rows, sort); } else { pageRequest = new PageRequest(page - 1, rows); } Page<Contact> contactPage = contactService.findAllByPage(pageRequest); // Construct the grid data that will return as JSON data ContactGrid contactGrid = new ContactGrid(); contactGrid.setCurrentPage(contactPage.getNumber() + 1); contactGrid.setTotalPages(contactPage.getTotalPages()); contactGrid.setTotalRecords(contactPage.getTotalElements()); contactGrid.setContactData(Lists.newArrayList(contactPage.iterator())); return contactGrid; }
From source file:org.springframework.data.elasticsearch.core.query.CriteriaQueryTests.java
@Test public void shouldPerformIsNotOperation() { // given//from w w w .j a v a2s . c o m List<IndexQuery> indexQueries = new ArrayList<IndexQuery>(); // first document String documentId = randomNumeric(5); SampleEntity sampleEntity1 = new SampleEntity(); sampleEntity1.setId(documentId); sampleEntity1.setMessage("bar"); sampleEntity1.setVersion(System.currentTimeMillis()); IndexQuery indexQuery1 = new IndexQuery(); indexQuery1.setId(documentId); indexQuery1.setObject(sampleEntity1); indexQueries.add(indexQuery1); // second document String documentId2 = randomNumeric(5); SampleEntity sampleEntity2 = new SampleEntity(); sampleEntity2.setId(documentId2); sampleEntity2.setMessage("foo"); sampleEntity2.setVersion(System.currentTimeMillis()); IndexQuery indexQuery2 = new IndexQuery(); indexQuery2.setId(documentId2); indexQuery2.setObject(sampleEntity2); indexQueries.add(indexQuery2); elasticsearchTemplate.bulkIndex(indexQueries); elasticsearchTemplate.refresh(SampleEntity.class, true); CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("foo").not()); // when Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class); // then assertTrue(criteriaQuery.getCriteria().isNegating()); assertThat(page, is(notNullValue())); assertFalse(page.iterator().next().getMessage().contains("foo")); }