List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java
@Test public void testMethodDefaultPageable() throws Exception { MethodParameter parameter = new MethodParameter(methodDefaultPageable, 0); NativeWebRequest webRequest = new ServletWebRequest(request); Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);/*from w w w. j a v a 2 s . c om*/ assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber()); assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize()); Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name")); assertEquals(expectedSort, pageable.getSort()); }
From source file:example.springdata.jpa.simple.SimpleUserRepositoryTests.java
@Test public void findTop2ByWithSort() { User user0 = new User(); user0.setLastname("lastname-0"); User user1 = new User(); user1.setLastname("lastname-1"); User user2 = new User(); user2.setLastname("lastname-2"); // we deliberately save the items in reverse repository.save(Arrays.asList(user2, user1, user0)); List<User> resultAsc = repository.findTop2By(new Sort(ASC, "lastname")); assertThat(resultAsc.size(), is(2)); assertThat(resultAsc, hasItems(user0, user1)); List<User> resultDesc = repository.findTop2By(new Sort(DESC, "lastname")); assertThat(resultDesc.size(), is(2)); assertThat(resultDesc, hasItems(user1, user2)); }
From source file:com.dm.estore.search.services.impl.CatalogSearchServiceImpl.java
@Override public ProductSearchResultDto findProducts(ProductSearchDto searchRequest) { Sort sort = new Sort(Sort.Direction.fromString(searchRequest.getSortOrder()), searchRequest.getSortColumn()); PageRequest pageRequest = new PageRequest(searchRequest.getPage(), searchRequest.getPageSize(), sort); FacetPage<CatalogItemDto> catalogItems = catalogSearchRepository.searchProducts( searchRequest.getSearchTerms(), searchRequest.getCategory(), searchRequest.getMaterials(), searchRequest.getColors(), pageRequest); ProductSearchResultDto result = new ProductSearchResultDto(); result.setTotalCount(catalogItems.getTotalElements()); for (Page<? extends FacetEntry> page : catalogItems.getAllFacets()) { for (FacetEntry facetEntry : page.getContent()) { String key = String.valueOf(facetEntry.getKey()); String facetCode = facetEntry.getValue(); // name of the category long count = facetEntry.getValueCount(); // number of books in this category if (StringUtils.isEmpty(facetCode)) continue; if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) { result.getCategoriesFacet().put(facetCode, count); } else if (CatalogItemDto.FIELD_VARIANT_GROUP.equalsIgnoreCase(key)) { result.getGroupFacet().put(facetCode, count); } else if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) { result.getSubGroupFacet().put(facetCode, count); }//from ww w . ja v a2 s .c o m } } result.setProducts(productConverter.convert(catalogItems.getContent())); result.setTotalCount((int) (catalogItems.getTotalElements())); return result; }
From source file:com.bgh.myopeninvoice.jsf.jsfbeans.InvoiceBean.java
private void refreshReports() { Predicate predicateReports = null; if (selectedInvoiceEntity != null) { predicateReports = QReportsEntity.reportsEntity.invoiceByInvoiceId.invoiceId .eq(selectedInvoiceEntity.getInvoiceId()); }/*from www . ja v a 2s.c o m*/ reportsEntityCollection = Lists.newArrayList(invoiceDAO.getReportsRepository().findAll(predicateReports, new Sort(Sort.Direction.DESC, "dateCreated"))); }
From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java
public Sort sortByIdDesc() { return new Sort(Sort.Direction.DESC, Product.ID_FIELD); }
From source file:org.ng200.openolympus.controller.user.SolutionListController.java
@RequestMapping(value = "/admin/solutions", method = RequestMethod.GET) public String showAllSolutions(@RequestParam(value = "page", defaultValue = "1") final Integer pageNumber, final Model model) { final List<SolutionDTO> lst = new ArrayList<SolutionDTO>(); final Sort sort = new Sort(Direction.DESC, "timeAdded"); final PageRequest pageRequest = new PageRequest(pageNumber - 1, 10, sort); for (final Solution solution : this.solutionRepository.findAll(pageRequest)) { lst.add(new SolutionDTO(MessageFormat.format("/solution?id={0}", Long.toString(solution.getId())), solution.getUser().getUsername(), this.solutionService.getSolutionScore(solution), this.solutionService.getSolutionMaximumScore(solution), solution.getTask().getName(), MessageFormat.format("/task/{0}", Long.toString(solution.getTask().getId())), solution.getTimeAdded())); }/*from w w w . j a va 2 s . c o m*/ model.addAttribute("solutions", lst); model.addAttribute("numberOfPages", Math.max((this.solutionRepository.count() + 9) / 10, 1)); model.addAttribute("currentPage", pageNumber); model.addAttribute("pagePrefix", "/admin/solutions?page="); return "tasks/solutions"; }
From source file:com.comcast.video.dawg.controller.park.ParkController.java
@SuppressWarnings("unchecked") @RequestMapping("/{token}*") public String userFront(@PathVariable String token, @RequestParam(required = false) String tag, @RequestParam(required = false) String q, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size, @RequestParam(required = false) Boolean asc, @RequestParam(required = false) String[] sort, Model model, HttpSession session) throws CerealException { StringBuilder builder = new StringBuilder(); builder.append("Request=").append("token=").append(token).append(",q=").append(q).append(",tag=") .append(tag).append(",page=").append(page).append(",size=").append(size).append(",asc=").append(asc) .append(",sort=").append(sort); logger.info(builder.toString());/*w ww . j a v a2 s . co m*/ if (isValid(token)) { token = clean(token); Map<String, Object>[] stbs = null; Map<String, Object>[] allDevices = null; Pageable pageable = null; if (null != sort) { if (0 == size) { size = 100; } Direction direction = asc ? Direction.ASC : Direction.DESC; Sort sorting = new Sort(direction, sort); pageable = new PageRequest(page, size, sorting); } if (null != tag) { if (null != q) { model.addAttribute("search", q); } stbs = service.findByCriteria(new TagCondition(tag, q).toCriteria(), pageable); } else if ((null != q) && (!q.trim().isEmpty())) { String[] keys = getKeys(q); stbs = service.findByKeys(keys, pageable); model.addAttribute("search", q); } else { Condition condition = (Condition) session.getAttribute("condition"); if (condition != null) { stbs = service.findByCriteria(condition.toCriteria(), pageable); session.removeAttribute("condition"); } else { stbs = service.findAll(pageable); model.addAttribute("search", ""); allDevices = stbs; } } Map<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("tag", tag); requestParams.put("q", q); requestParams.put("page", page); requestParams.put("size", size); requestParams.put("asc", asc); requestParams.put("sort", sort); String requestParamsJson = engine.writeToString(requestParams, Map.class); model.addAttribute("requestParams", requestParamsJson); Map<String, Object> devices = new HashMap<String, Object>(); Map<String, List<String>> deviceTags = new HashMap<String, List<String>>(); Object tagData = null; boolean anyReserved = false; for (Map<String, Object> stb : stbs) { if (stb.containsKey(MetaStb.MACADDRESS)) { String id = (String) stb.get(MetaStb.ID); devices.put(id, stb); tagData = stb.get(MetaStb.TAGS); if (tagData != null && (tagData instanceof List)) { deviceTags.put(id, (List<String>) tagData); } else { deviceTags.put(id, null); } String reserver = (String) stb.get(PersistableDevice.RESERVER); if ((token != null) && token.equals(reserver)) { anyReserved = true; } } } String deviceData = engine.writeToString(devices, Map.class); /** Get all the tags from other devices */ allDevices = allDevices == null ? service.findAll() : allDevices; Collection<String> otherTags = new HashSet<String>(); for (Map<String, Object> device : allDevices) { String id = (String) device.get(MetaStb.ID); if (!deviceTags.containsKey(id)) { tagData = device.get(MetaStb.TAGS); if (tagData != null && (tagData instanceof List)) { otherTags.addAll((List<String>) tagData); } } } model.addAttribute(LATEST_SEARCH_CONDITION_MODEL_ATTRIBUTE_NAME, returnAndRemoveLatestSearchCondition(session)); model.addAttribute(SEARCH_CONDITIONS_MODEL_ATTRIBUTE_NAME, getSearchConditions(session)); model.addAttribute("token", token); model.addAttribute("deviceData", deviceData); model.addAttribute("deviceTags", engine.writeToString(deviceTags)); model.addAttribute("otherTags", engine.writeToString(new ArrayList<String>(otherTags))); model.addAttribute("data", devices.values()); model.addAttribute("dawgShowUrl", config.getDawgShowUrl()); model.addAttribute("dawgPoundUrl", config.getDawgPoundUrl()); model.addAttribute("anyReserved", anyReserved); model.addAttribute("filterFields", SearchableField.values()); model.addAttribute("operators", Operator.values()); return "index"; } else { /** User login token is invalid, so redirects to login page */ return "login"; } }
From source file:org.ngrinder.perftest.controller.PerfTestController.java
/** * Get the perf test lists.//from www .j ava 2s. com * * @param user user * @param query query string to search the perf test * @param tag tag * @param queryFilter "F" means get only finished, "S" means get only scheduled tests. * @param pageable page * @param model modelMap * @return perftest/list */ @RequestMapping({ "/list", "/", "" }) public String getAll(User user, @RequestParam(required = false) String query, @RequestParam(required = false) String tag, @RequestParam(required = false) String queryFilter, @PageableDefaults Pageable pageable, ModelMap model) { pageable = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), defaultIfNull(pageable.getSort(), new Sort(Direction.DESC, "lastModifiedDate"))); Page<PerfTest> tests = perfTestService.getPagedAll(user, query, tag, queryFilter, pageable); annotateDateMarker(tests); model.addAttribute("tag", tag); model.addAttribute("availTags", tagService.getAllTagStrings(user, StringUtils.EMPTY)); model.addAttribute("testListPage", tests); model.addAttribute("queryFilter", queryFilter); model.addAttribute("query", query); putPageIntoModelMap(model, pageable); return "perftest/list"; }
From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java
@Test public void testParameterDefaultPageable() throws Exception { MethodParameter parameter = new MethodParameter(parameterDefaultPageable, 0); NativeWebRequest webRequest = new ServletWebRequest(request); Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);//from ww w .j a v a2s .c o m assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber()); assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize()); Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name")); assertEquals(expectedSort, pageable.getSort()); }
From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java
@Test public void findAllInRepositorySortedOrder() { checkOrder(Sort.by("lastname"), new String[] { "Ktifa", "One", "Toussaint" }); checkOrder(new Sort(Sort.Direction.DESC, "lastname"), new String[] { "Toussaint", "One", "Ktifa" }); checkOrder(new Sort(Sort.Direction.DESC, "age", "lastname"), new String[] { "Toussaint", "One", "Ktifa" }); checkOrder(new Sort(Sort.Direction.DESC, "age").and(Sort.by("lastname")), new String[] { "Toussaint", "Ktifa", "One" }); }