List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.fycoder.ll.service.tls.TlsService.java
/** * ./*ww w . ja va 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 ("tablename".equals(sortType)) { sort = new Sort(Direction.ASC, "tablename"); } return new PageRequest(pageNumber - 1, pagzSize, sort); }
From source file:com.trenako.repositories.mongo.RollingStockQueryBuilderTests.java
private RangeRequest range(Object since, Object max, String sort, Direction dir) { RangeRequest range = new RangeRequest(); range.setMax(max);//from ww w .ja v a2 s . co m range.setSince(since); range.setSize(10); range.setSort(new Sort(dir, sort)); return range; }
From source file:com.capstone.giveout.controllers.GiftsController.java
@PreAuthorize("hasRole(mobile)") @RequestMapping(value = Routes.MY_GIFTS_PATH, method = RequestMethod.GET) public @ResponseBody Collection<Gift> listMine( @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, Principal p) {/*from www . java 2 s . c o m*/ User u = users.findByUsername(p.getName()); PageRequest pageRequest = new PageRequest(page, limit, new Sort(Sort.Direction.DESC, "createdAt")); List<Gift> giftList; if (title == null) { giftList = Lists.newArrayList(gifts.findByUserId(u.getId(), pageRequest)); } else { giftList = Lists .newArrayList(gifts.findByUserIdAndTitleLike(u.getId(), "%" + title + "%", pageRequest)); } for (Gift gift : giftList) { gift.allowAccessToGiftChain = true; } return giftList; }
From source file:cz.jirutka.spring.data.jdbc.sql.DefaultSqlGenerator.java
protected Sort sortById(TableDescription table) { return new Sort(Direction.ASC, table.getPkColumns()); }
From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java
@Test public void testPageableAndOrderedSort() throws Exception { int pn = 1;/*ww w . ja v a2s.c om*/ int pageSize = 10; request.setParameter("page.pn", String.valueOf(pn)); request.setParameter("page.size", String.valueOf(pageSize)); request.setParameter("sort1.baseInfo.realname", "asc"); request.setParameter("sort2.id", "desc"); MethodParameter parameter = new MethodParameter(pageableAndSort, 0); NativeWebRequest webRequest = new ServletWebRequest(request); Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null); //-10 assertEquals(pn - 1, pageable.getPageNumber()); assertEquals(pageSize, pageable.getPageSize()); Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname") .and(new Sort(Sort.Direction.DESC, "id")); assertEquals(expectedSort, pageable.getSort()); }
From source file:com.luna.common.service.UserServiceTest.java
@Test public void testFindAllByPageableAndSortAsc() { int count = 15; User lastUser = null;/*from ww w . j a v a 2s .c o m*/ for (int i = 0; i < count; i++) { lastUser = userService.save(createUser()); } Sort sortAsc = new Sort(Sort.Direction.ASC, "id"); Pageable pageable = new PageRequest(0, 5, sortAsc); Page<User> userPage = userService.findAll(pageable); assertEquals(5, userPage.getNumberOfElements()); assertFalse(userPage.getContent().contains(lastUser)); assertTrue(userPage.getContent().get(0).getId() < userPage.getContent().get(1).getId()); }
From source file:khs.trouble.service.impl.EventService.java
public Iterable<Event> events() { return this.repository.findAll(new Sort(Sort.Direction.ASC, "created")); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.IAViewServiceImpl.java
public Long countUntaggedDocumentsBySeriesMongo(String seriesIaid) { Query query = Query.query(Criteria.where("series").is(seriesIaid).and("categories").size(0)); query.with(new Sort(Sort.Direction.ASC, "_id")); return mongoTemplate.count(query, MongoInformationAssetView.class); }
From source file:org.springside.examples.quickstart.service.ProjectDataService.java
/***/ private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) { Sort sort = null;/*from w w w .j a v a 2 s .c o m*/ if ("auto".equals(sortType)) { sort = new Sort(Direction.DESC, "id"); } else if ("title".equals(sortType)) { sort = new Sort(Direction.ASC, "title"); } else { sort = new Sort(Direction.DESC, "delegateDate", "id"); } return new PageRequest(pageNumber - 1, pagzSize, sort); }
From source file:com.github.camellabs.iot.cloudlet.geofencing.service.DefaultRouteService.java
@Override public int analyzeRoutes(String client) { RouteGpsCoordinates lastRouteCoordinates = findLastRouteCoordinates(client); GpsCoordinates lastCoordinates = null; if (lastRouteCoordinates == null) { LOG.info("No GPS coordinates assigned to routes for client {}", client); } else {/*from w ww .j a v a 2 s . co m*/ lastCoordinates = mongoTemplate.findById(lastRouteCoordinates.getCoordinatesId(), GpsCoordinates.class, GpsCoordinates.class.getSimpleName()); } Query query = new Query(); query.addCriteria(where("client").is(client)); if (lastRouteCoordinates != null) { query.addCriteria(where("_id").gt(new ObjectId(lastRouteCoordinates.getCoordinatesId()))); } query.limit(routeAnalysisBatchSize); query.with(new Sort(ASC, "_id")); List<GpsCoordinates> coordinatesToAnalyze = mongoTemplate.find(query, GpsCoordinates.class, GpsCoordinates.class.getSimpleName()); for (GpsCoordinates coordinates : coordinatesToAnalyze) { String routeId; if (lastCoordinates == null || (TimeUnit.MILLISECONDS.toMinutes( coordinates.getTimestamp().getTime() - lastCoordinates.getTimestamp().getTime()) > 5)) { Route newRoute = createNewRoute(client); routeId = documentDriver.save(collectionName(newRoute.getClass()), pojoToMap(newRoute)); } else { routeId = lastRouteCoordinates.getRouteId(); } lastRouteCoordinates = new RouteGpsCoordinates(null, routeId, coordinates.getId(), client); mongoTemplate.save(lastRouteCoordinates, collectionName(RouteGpsCoordinates.class)); lastCoordinates = coordinates; } return coordinatesToAnalyze.size(); }