List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.sap.csc.poc.ems.service.admin.entitlement.EntitlementServiceImpl.java
@Override @RequestMapping(value = "entitlements/search", method = RequestMethod.GET) public ResponseEntity<Page<EntitlementInfo>> search( // Keyword @RequestParam(value = "keyword", required = false) String keyword, // Page//from w ww .j a v a 2 s .c o m @RequestParam(value = "page", required = false, defaultValue = PageConstant.DEFAULT_PAGE_INDEX) Integer page, // Size @RequestParam(value = "size", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SIZE) Integer size, // Sort @RequestParam(value = "sort", required = false, defaultValue = PageConstant.DEFAULT_SORT) String sort) { Page<EntitlementInfo> entitlementPage = entitlementHeaderRepository .search(keyword, new PageRequest(page, size, StringUtils.isBlank(sort) // Search with default sort ? new Sort(Direction.DESC, EntitlementHeader_.updateOn.getName()) // Search with custom sort : new Sort(Arrays.asList(sort.split(",")).stream().map(order -> order.split(" ")) .map(order -> new Order(Direction.fromString(order[1]), order[0])) .collect(Collectors.toList())))) // Convert to dto .map(entitlement -> new EntitlementInfo(entitlement)); if (entitlementPage.hasContent()) { return new ResponseEntity<>(entitlementPage, HttpStatus.OK); } else { return new ResponseEntity<>(entitlementPage, HttpStatus.NO_CONTENT); } }
From source file:com.trenako.services.FormValuesServiceTests.java
@Test public void shouldReturnTheRailwaysList() { Sort sort = new Sort(Direction.ASC, "name"); when(railwaysRepo.findAll(eq(sort))).thenReturn(Arrays.asList(new Railway(), new Railway())); Iterable<Railway> railways = service.railways(); assertNotNull(railways);/* w ww .ja va 2 s.c o m*/ verify(railwaysRepo, times(1)).findAll(eq(sort)); }
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;//w ww . j ava 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:strat.mining.multipool.stats.persistence.dao.coinshift.impl.GlobalStatsDAOMongo.java
@Override public GlobalStats getGlobalStats(Date time) { Query query = new Query(Criteria.where("refreshTime").is(time)); query.with(new Sort(Sort.Direction.ASC, "refreshTime")); return mongoOperation.findOne(query, GlobalStats.class); }
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 ww w.j ava 2 s.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"; }
From source file:org.openmhealth.shimmer.common.controller.LegacyDataPointSearchController.java
/** * Endpoint for retrieving data from shims. * * @param username User ID record for which to retrieve data, if not approved this will throw ShimException. * <p>//from w w w.j a v a 2 s . c o m * TODO: finish javadoc! * @return The shim data response wrapper with data from the shim. */ @RequestMapping(value = "/data/{shim}/{dataType}", produces = APPLICATION_JSON_VALUE) public ShimDataResponse data(@RequestParam(value = "username") String username, @PathVariable("shim") String shim, @PathVariable("dataType") String dataTypeKey, @RequestParam(value = "normalize", defaultValue = "true") boolean normalize, @RequestParam(value = "dateStart", defaultValue = "") String dateStart, @RequestParam(value = "dateEnd", defaultValue = "") String dateEnd) throws ShimException { setPassThroughAuthentication(username, shim); ShimDataRequest shimDataRequest = new ShimDataRequest(); shimDataRequest.setDataTypeKey(dataTypeKey); shimDataRequest.setNormalize(normalize); if (!dateStart.isEmpty()) { shimDataRequest.setStartDateTime(LocalDate.parse(dateStart).atStartOfDay().atOffset(UTC)); } if (!dateEnd.isEmpty()) { shimDataRequest.setEndDateTime(LocalDate.parse(dateEnd).atStartOfDay().atOffset(UTC)); } AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(username, shim, new Sort(Sort.Direction.DESC, "dateCreated")); if (accessParameters == null) { throw new ShimException("User '" + username + "' has not authorized shim: '" + shim + "'"); } shimDataRequest.setAccessParameters(accessParameters); return shimRegistry.getShim(shim).getData(shimDataRequest); }
From source file:com.trenako.web.tags.PagerTagsTests.java
@Test public void shouldRenderPagersWithBothNextAndPrevious() throws JspException, UnsupportedEncodingException { SearchRange range = new SearchRange(20, new Sort(Direction.ASC, "name"), SINCE, MAX); RollingStockResults results = mock(RollingStockResults.class); when(results.isEmpty()).thenReturn(false); when(results.hasPreviousPage()).thenReturn(true); when(results.hasNextPage()).thenReturn(true); when(results.getRange()).thenReturn(range); tag.setResults(results);/*w w w. ja v a 2 s . c o m*/ int rv = tag.doStartTag(); assertEquals(TagSupport.SKIP_BODY, rv); HtmlTag html = ul( li(a("← Older").href("/trenako-web?dir=ASC&max=5011996c575e5447d5375afb&size=20&sort=name")) .cssClass("previous"), li(a("Newer →").href("/trenako-web?dir=ASC&since=5011996c575e5447d5375afa&size=20&sort=name")) .cssClass("next")).cssClass("pager"); String output = renderTag(); assertEquals(html.build(), output); }
From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.AddressStatsDAOMongo.java
@Override public AddressStats getLastAddressStats(Integer addressId) { Query query = new Query(Criteria.where("addressId").is(addressId)); query.with(new Sort(Sort.Direction.DESC, "refreshTime")); return mongoOperation.findOne(query, AddressStats.class); }
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:com.luna.common.service.UserServiceTest.java
@Test public void testFindAllBySort() { int count = 15; User user = null;/*from ww w . j ava 2s . c om*/ for (int i = 0; i < count; i++) { user = userService.save(createUser()); } Sort sortDesc = new Sort(Sort.Direction.DESC, "id"); Sort sortAsc = new Sort(Sort.Direction.ASC, "id"); List<User> userDescList = userService.findAll(sortDesc); List<User> userAscList = userService.findAll(sortAsc); assertEquals(count, userDescList.size()); assertEquals(count, userAscList.size()); assertTrue(userDescList.contains(user)); assertTrue(userAscList.contains(user)); assertTrue(userAscList.get(0).getId() < userAscList.get(1).getId()); assertTrue(userDescList.get(0).getId() > userDescList.get(1).getId()); }