List of usage examples for org.springframework.data.domain PageRequest PageRequest
protected PageRequest(int page, int size, Sort sort)
From source file:edu.swau.softball.web.BaseController.java
protected Map<String, Object> buildPagination(Integer page, String sort, String direction, String filter) { Map<String, Object> params = new HashMap<>(); String oposite;/* w w w.j a v a 2 s .c o m*/ if (page == null) { page = 0; } if (StringUtils.isBlank(sort)) { sort = "lastUpdated"; direction = "desc"; } if (StringUtils.isBlank(direction)) { direction = "asc"; } Sort s; switch (direction) { case "desc": s = new Sort(Sort.Direction.DESC, sort); oposite = "asc"; break; default: s = new Sort(Sort.Direction.ASC, sort); oposite = "desc"; } params.put(Constants.PAGE, page); params.put(Constants.SORT, sort); log.debug("{} : {}", direction, oposite); params.put(Constants.DIRECTION, direction); params.put(Constants.OPOSITE_DIRECTION, oposite); params.put(Constants.FILTER, filter); PageRequest pageRequest = new PageRequest(page, 20, s); params.put(Constants.PAGE_REQUEST, pageRequest); return params; }
From source file:com.capstone.giveout.controllers.GiftsController.java
@RequestMapping(value = Routes.GIFTS_PATH, method = RequestMethod.GET) public @ResponseBody Collection<Gift> list( @RequestParam(value = Routes.TITLE_PARAMETER, required = false) String title, @RequestParam(value = Routes.PAGE_PARAMETER, required = false, defaultValue = "0") int page, @RequestParam(value = Routes.LIMIT_PARAMETER, required = false, defaultValue = Constants.DEFAULT_PAGE_SIZE) int limit, @RequestParam(value = Routes.NOT_FLAGGED_BY_USER_ID_PARAMETER, required = false) Long notFlaggedByUserId) { PageRequest pageRequest = new PageRequest(page, limit, new Sort(Sort.Direction.DESC, "createdAt")); Page<Gift> giftsPage;//from w ww.ja v a 2 s. co m if (title == null) { giftsPage = notFlaggedByUserId == null ? gifts.findByGiftChainIsNotNull(pageRequest) : gifts.findByGiftChainIsNotNullAndUserNotFlagAsInappropriate(notFlaggedByUserId, pageRequest); } else { giftsPage = notFlaggedByUserId == null ? gifts.findByGiftChainIsNotNullAndTitleLike("%" + title + "%", pageRequest) : gifts.findByGiftChainIsNotNullAndTitleLikeAndUserNotFlagAsInappropriate("%" + title + "%", notFlaggedByUserId, pageRequest); } List<Gift> giftList = Lists.newArrayList(giftsPage); for (Gift gift : giftList) { gift.allowAccessToGiftChain = true; } return giftList; }
From source file:org.devgateway.toolkit.forms.wicket.providers.SortableJpaRepositoryDataProvider.java
/** * @see SortableDataProvider#iterator(long, long) *//*from w ww .ja v a2s.c om*/ @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.oakhole.auth.service.UserService.java
public Page<User> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize, String sortDirection, String sortBy) {//w ww .j a v a 2s . c o m Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); Specification<User> spec = DynamicSpecifications.bySearchFilter(filters.values(), User.class); Sort sort = new Sort("ASC".equals(sortDirection) ? Sort.Direction.ASC : Sort.Direction.DESC, sortBy); PageRequest pageRequest = new PageRequest(pageNumber, pageSize, sort); Page<User> userList = userDao.findAll(spec, pageRequest); return userList; }
From source file:cn.edu.zjnu.acm.judge.problem.ProblemStatusController.java
@GetMapping("/problemstatus") @SuppressWarnings("AssignmentToMethodParameter") public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Authentication authentication) { log.debug("{}", pageable); if (pageable.getPageSize() > 500) { pageable = new PageRequest(pageable.getPageNumber(), 500, pageable.getSort()); }/*from ww w. j a va 2 s. c om*/ Problem problem = problemMapper.findOneNoI18n(id); if (problem == null) { throw new MessageException("No such problem", HttpStatus.NOT_FOUND); } final Long contestId = problem.getContest(); request.setAttribute("contestId", contestId); List<ScoreCount> list = problemMapper.groupByScore(id); ArrayList<String> scores = new ArrayList<>(list.size()); ArrayList<Long> counts = new ArrayList<>(list.size()); ArrayList<String> urls = new ArrayList<>(list.size()); for (ScoreCount scoreCount : list) { int score = scoreCount.getScore(); scores.add(ResultType.getShowsourceString(score)); counts.add(scoreCount.getCount()); urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score); } List<Submission> bestSubmissions = submissionMapper.bestSubmission(id, pageable); long total = pageable.getOffset() + bestSubmissions.size() + (pageable.getPageSize() == bestSubmissions.size() ? 1 : 0); PageImpl<Submission> page = new PageImpl<>(bestSubmissions, pageable, total); boolean isAdmin = UserDetailService.isAdminLoginned(request); boolean isSourceBrowser = UserDetailService.isSourceBrowser(request); boolean canView = isAdmin || isSourceBrowser; request.setAttribute("page", page); request.setAttribute("sa", Arrays.asList(counts, scores, urls)); request.setAttribute("problem", problem); request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString()); request.setAttribute("contestId", contestId); request.setAttribute("canView", canView); request.setAttribute("authentication", authentication); return "problems/status"; }
From source file:org.openlmis.fulfillment.service.PageDto.java
@Override public Pageable nextPageable() { return hasNext() ? new PageRequest(number + 1, size, sort) : null; }
From source file:org.davidmendoza.esu.web.BaseController.java
protected Map<String, Object> preparaPaginacion(Integer pagina, String ordena, String direccion, String filtro) {/*from ww w . j a v a 2 s . c o m*/ Map<String, Object> params = new HashMap<>(); String direccionContraria; if (pagina == null) { pagina = 0; } if (StringUtils.isBlank(ordena)) { ordena = "lastUpdated"; direccion = "desc"; } if (StringUtils.isBlank(direccion)) { direccion = "asc"; } Sort sort; switch (direccion) { case "desc": sort = new Sort(Sort.Direction.DESC, ordena); direccionContraria = "asc"; break; default: sort = new Sort(Sort.Direction.ASC, ordena); direccionContraria = "desc"; } params.put(Constants.PAGINA, pagina); params.put(Constants.ORDENA, ordena); params.put(Constants.DIRECCION, direccion); params.put(Constants.DIRECCION_CONTRARIA, direccionContraria); params.put(Constants.FILTRO, filtro); PageRequest pageRequest = new PageRequest(pagina, 20, sort); params.put(Constants.PAGE_REQUEST, pageRequest); return params; }
From source file:fr.treeptik.cloudunit.service.impl.MessageServiceImpl.java
@Override public List<Message> listByApp(User user, String applicationName, int nbMessages) throws ServiceException { try {/*from ww w . java 2 s. c om*/ Pageable pageable = new PageRequest(0, nbMessages, sortByLastNameAsc()); Page<Message> requestedPage = messageDAO.listByApp(user, applicationName, pageable); return requestedPage.getContent(); } catch (PersistenceException e) { throw new ServiceException(e.getLocalizedMessage(), e); } }
From source file:io.github.microcks.web.TestController.java
@RequestMapping(value = "/tests/service/{serviceId}", method = RequestMethod.GET) public List<TestResult> listTestsByService(@PathVariable("serviceId") String serviceId, @RequestParam(value = "page", required = false, defaultValue = "0") int page, @RequestParam(value = "size", required = false, defaultValue = "20") int size) { log.debug("Getting tests list for service {}, page {} and size {}", serviceId, page, size); return testResultRepository.findByServiceId(serviceId, new PageRequest(page, size, new Sort(Sort.Direction.DESC, "testNumber"))); }
From source file:org.jblogcms.core.blog.controller.BlogController.java
/** * Shows all the blogs meeting the paging restriction provided in the {@code Pageable} object. * * @param pageable the {@code Pageable} object * @param model the {@code Model} object * @return logical String-based view name *//*from w ww .j av a 2s .c om*/ @RequestMapping(value = "/blogs", method = RequestMethod.GET) public String showBlogs(@PageableDefault(sort = { "name" }, value = 10, page = 0) Pageable pageable, Model model) { Long currentAccountId = securityService.getCurrentAccountId(); Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageableLastPosts = new PageRequest(0, 10, sort); Page<Blog> blogs = blogService.findBlogs(pageable, currentAccountId); model.addAttribute("blogs", blogs); model.addAttribute("lastPosts", postService.findLastPosts(pageableLastPosts, currentAccountId).getContent()); model.addAttribute("pageable", pageable); model.addAttribute("currentUrl", "/blogs"); return "user/blogs"; }