List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.oakhole.auth.service.OperationService.java
public Page<Operation> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize, String sortDirection, String sortBy) { Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); Specification<Operation> spec = DynamicSpecifications.bySearchFilter(filters.values(), Operation.class); Sort sort = new Sort("ASC".equals(sortDirection) ? Sort.Direction.ASC : Sort.Direction.DESC, sortBy); PageRequest pageRequest = new PageRequest(pageNumber, pageSize, sort); Page<Operation> operationList = operationDao.findAll(spec, pageRequest); return operationList; }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.impl.IAViewUpdateRepositoryImpl.java
@Override public List<IAViewUpdate> findDocumentsCreatedFromDateAndCreatedBeforeDate(Date gtDate, Date ltDate, Integer limit) {// w w w . ja va 2 s . com List<Criteria> listOfCriterias = new ArrayList<Criteria>(); if (gtDate != null) { listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gte(gtDate)); } if (ltDate != null) { listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).lt(ltDate)); } Query query = new Query(new Criteria().andOperator(listOfCriterias.toArray(new Criteria[0]))); query.limit(limit + 1); query.with(new Sort(new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_CREATIONDATE), new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_DOCREFERENCE))); return mongoTemplate.find(query, IAViewUpdate.class); }
From source file:com.oakhole.syslog.service.SignLogService.java
public Page<SignLog> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize, String sortDirection, String sortBy) { Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); Specification<SignLog> spec = DynamicSpecifications.bySearchFilter(filters.values(), SignLog.class); Sort sort = new Sort("ASC".equals(sortDirection) ? Sort.Direction.ASC : Sort.Direction.DESC, sortBy); PageRequest pageRequest = new PageRequest(pageNumber, pageSize, sort); Page<SignLog> signLogList = signLogDao.findAll(spec, pageRequest); return signLogList; }
From source file:com.trenako.results.SearchRangeTests.java
@Test public void shouldReturnParamsAsMapsOnlyForNotNullValues() { SearchRange range = new SearchRange(20, new Sort(Direction.DESC, "name"), null, null); Map<String, Object> params = range.asMap(); String expected = "{dir=DESC, size=20, sort=name}"; assertNotNull(params);//w w w.ja v a 2 s .c o m assertEquals(3, params.size()); assertEquals(expected, params.toString()); }
From source file:com.oakhole.channel.service.ChannelGroupService.java
public Page<ChannelGroup> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize, String sortDirection, String sortBy) { Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); Specification<ChannelGroup> spec = DynamicSpecifications.bySearchFilter(filters.values(), ChannelGroup.class); Sort sort = new Sort("ASC".equals(sortDirection) ? Sort.Direction.ASC : Sort.Direction.DESC, sortBy); PageRequest pageRequest = new PageRequest(pageNumber, pageSize, sort); Page<ChannelGroup> channelGroupList = channelGroupDao.findAll(spec, pageRequest); return channelGroupList; }
From source file:com.luna.common.repository.PageAndSortUserRepositoryIT.java
@Test public void testFindAllForSort() { for (int i = 0; i < 15; i++) { userRepository.save(createUser()); }/*from ww w. j a v a 2 s . com*/ Sort.Order idAsc = new Sort.Order(Sort.Direction.ASC, "id"); Sort.Order usernameDesc = new Sort.Order(Sort.Direction.DESC, "username"); Sort sort = new Sort(idAsc, usernameDesc); List<User> userList = userRepository.findAll(sort); assertTrue(userList.get(0).getId() < userList.get(1).getId()); }
From source file:no.kantega.kwashc.server.controller.FrontPageController.java
@RequestMapping(value = "/display", method = RequestMethod.GET) public String showDisplayPage(Model model) { Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "score"), new Sort.Order(Sort.Direction.ASC, "completed")); Iterable<Site> sites = siteRepository.findAll(sort); model.addAttribute("sites", sites); model.addAttribute("numberOfTests", TestRepository.getTests().size()); // testname -> number of runs Map<String, Integer> testCloud = new HashMap<String, Integer>(); // create test cloud List<TestRun> testRuns = testRunRepository.findAll(); for (TestRun testRun : testRuns) { String testIdentifikator = testRun.getTestIdentifikator(); if (testCloud.containsKey(testIdentifikator)) { testCloud.put(testIdentifikator, testCloud.get(testIdentifikator) + 1); } else {/*from w w w .j a va 2 s .c om*/ testCloud.put(testIdentifikator, 1); } } model.addAttribute("testCloud", testCloud); return "display"; }
From source file:$.TaskService.java
/** * ./*from ww w . j av a 2 s . c o m*/ */ private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) { Sort sort = null; if ("auto".equals(sortType)) { sort = new Sort(Direction.DESC, "id"); } else if ("title".equals(sortType)) { sort = new Sort(Direction.ASC, "title"); } return new PageRequest(pageNumber - 1, pagzSize, 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;//from w ww . j a v a2 s . co 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:io.github.autsia.crowly.controllers.rest.UsersController.java
@RequestMapping(value = "/users", method = RequestMethod.GET) public List<CrowlyUser> users(@RequestParam int page, @RequestParam int size, @RequestParam(defaultValue = "true") boolean direction, @RequestParam(defaultValue = "email") String sortProperty, HttpServletResponse response) { return userRepository.findAll(new PageRequest(page, size, new Sort(direction ? Sort.Direction.ASC : Sort.Direction.DESC, sortProperty))).getContent(); }