Example usage for org.springframework.data.domain Sort Sort

List of usage examples for org.springframework.data.domain Sort Sort

Introduction

In this page you can find the example usage for org.springframework.data.domain Sort Sort.

Prototype

private Sort(Direction direction, List<String> properties) 

Source Link

Document

Creates a new Sort instance.

Usage

From source file:com.luna.common.repository.RepositoryHelperIT.java

@Test
public void testFindAllWithPageAndSort() {

    repositoryHelper.batchUpdate("delete from User");

    User user1 = createUser();//from w  w  w.  j av a  2 s . co m
    User user2 = createUser();
    User user3 = createUser();
    User user4 = createUser();
    repositoryHelper.getEntityManager().persist(user1);
    repositoryHelper.getEntityManager().persist(user2);
    repositoryHelper.getEntityManager().persist(user3);
    repositoryHelper.getEntityManager().persist(user4);

    String ql = "select o from User o";

    List<User> list = repositoryHelper.findAll(ql, new PageRequest(0, 2, new Sort(Sort.Direction.DESC, "id")));

    Assert.assertEquals(2, list.size());

    Assert.assertTrue(list.get(0).equals(user4));
    Assert.assertTrue(list.contains(user3));

    Assert.assertFalse(list.contains(user1));
}

From source file:com.luna.common.service.UserServiceTest.java

@Test
public void testFindAllBySearchAndSort() {
    int count = 15;
    User lastUser = null;/*from   w ww .  j a va2  s .  c o  m*/
    for (int i = 0; i < count; i++) {
        lastUser = createUser();
        lastUser.setUsername("zhang" + i);
        userService.save(lastUser);
    }

    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("username_like", "zhang");
    Sort sortDesc = new Sort(Sort.Direction.DESC, "id");
    Searchable search = Searchable.newSearchable(searchParams).addSort(sortDesc);

    List<User> userList = userService.findAllWithSort(search);
    assertEquals(count, userList.size());
    assertTrue(userList.contains(lastUser));

    assertTrue(userList.get(0).getId() > userList.get(1).getId());
}

From source file:com.chortitzer.web.bas.controller.DalBonificacionBean.java

/**
 * @return the bonificacionList/*from ww  w . j  a va2  s.c  o m*/
 */
public List<TblDalBonificaciones> getBonificacionList() {
    bonificacionList = tblDalBonificacionesRepository.findAll(new Sort(Sort.Direction.DESC, "fechahora"));
    return bonificacionList;
}

From source file:com.bgh.myopeninvoice.jsf.jsfbeans.InvoiceBean.java

private void refreshContracts() {
    Predicate predicateContracts = null;
    contractsEntityCollectionForSelection = null;
    Date today = new Date();
    if (selectedInvoiceEntity != null && selectedInvoiceEntity.getCompanyTo() != null) {
        predicateContracts = QContractsEntity.contractsEntity.contractSignedWith
                .eq(selectedInvoiceEntity.getCompanyTo());
        //                    .and(QContractsEntity.contractsEntity.validFrom.before(today))
        //                    .and(QContractsEntity.contractsEntity.validTo.after(today));

        Sort sortContracts = new Sort(Sort.Direction.DESC, "validTo");
        contractsEntityCollectionForSelection = Lists
                .newArrayList(invoiceDAO.getContractsRepository().findAll(predicateContracts, sortContracts));
    }//from   w ww  .j  a  v  a2 s . c  o  m
}

From source file:edu.zipcloud.cloudstreetmarket.core.services.IndexServiceImpl.java

@Override
public ChartIndex getChartIndex(Index index, ChartType type, ChartHistoSize histoSize,
        ChartHistoMovingAverage histoAverage, ChartHistoTimeSpan histoPeriod, Integer intradayWidth,
        Integer intradayHeight) {

    log.debug("getChartIndex(" + index + ", " + type + ", " + histoSize + ", " + histoAverage + ", "
            + histoPeriod + ", " + intradayWidth + ", " + intradayHeight + ")");

    Specification<ChartIndex> spec = new ChartSpecifications<ChartIndex>().typeEquals(type);

    if (type.equals(ChartType.HISTO)) {
        if (histoSize != null) {
            spec = Specifications.where(spec).and(new ChartSpecifications<ChartIndex>().sizeEquals(histoSize));
        }//from ww  w.j a va  2  s  .c  o  m
        if (histoAverage != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartIndex>().histoMovingAverageEquals(histoAverage));
        }
        if (histoPeriod != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartIndex>().histoTimeSpanEquals(histoPeriod));
        }
    } else {
        if (intradayWidth != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartIndex>().intradayWidthEquals(intradayWidth));
        }
        if (intradayHeight != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartIndex>().intradayHeightEquals(intradayHeight));
        }
    }

    spec = Specifications.where(spec).and(new ChartSpecifications<ChartIndex>().indexEquals(index));
    log.debug("DB CALL");

    return chartIndexRepository.findAll(spec, new Sort(Direction.DESC, "id")).stream().findFirst().orElse(null);
}

From source file:com.huake.saas.account.service.AccountService.java

/**
 * .//from w  ww .  ja  va2 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, "registerDate");
    } else if ("createDate".equals(sortType)) {
        sort = new Sort(Direction.DESC, "registerDate");
    }
    return new PageRequest(pageNumber - 1, pagzSize, sort);
}

From source file:com.pkrete.locationservice.admin.solr.service.impl.LanguageIndexServiceImpl.java

/**
 * Returns a Sort object that sorts the results in ascending order by name.
 *
 * @return Sort object that sorts the results in ascending order by name
 *///w w  w. j  a  v a2  s  .  c o m
private Sort sortByName() {
    return new Sort(Sort.Direction.ASC, RepositoryConstants.FIELD_NAME);
}

From source file:com.luna.common.web.bind.method.annotation.SearchableMethodArgumentResolverTest.java

@Test
public void testSearchableAndNoPageAndSort() throws Exception {

    int pn = 1;/* w  w  w.j ava 2 s  .  c  o m*/
    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");

    request.setParameter("search.baseInfo.realname_like", "zhang");
    request.setParameter("search.username_eq", "zhang");

    MethodParameter parameter = new MethodParameter(searchableAndNoPageAndSort, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Searchable searchable = (Searchable) new SearchableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    assertEquals(null, searchable.getPage());

    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, searchable.getSort());

    assertContainsSearchFilter(
            SearchFilterHelper.newCondition("baseInfo.realname", SearchOperator.like, "zhang"), searchable);
    assertContainsSearchFilter(SearchFilterHelper.newCondition("username", SearchOperator.eq, "zhang"),
            searchable);
}

From source file:com.restfiddle.controller.rest.TagController.java

@RequestMapping(value = "/api/workspaces/{workspaceId}/tags/{tagId}/nodes", method = RequestMethod.GET)
public @ResponseBody List<NodeDTO> findNodesByTag(@PathVariable("workspaceId") String workspaceId,
        @PathVariable("tagId") String tagId, @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "limit", required = false) Integer limit) {
    logger.debug("Finding nodes by tag id: " + tagId);

    int pageNo = 0;
    if (page != null && page > 0) {
        pageNo = page;/* w w w  .j a v a 2s . c o  m*/
    }

    int numberOfRecords = 10;
    if (limit != null && limit > 0) {
        numberOfRecords = limit;
    }
    Sort sort = new Sort(Direction.DESC, "lastModifiedDate");
    Pageable pageable = new PageRequest(pageNo, numberOfRecords, sort);

    Page<BaseNode> paginatedTaggedNodes = nodeRepository.findTaggedNodes(tagId, pageable);

    List<BaseNode> taggedNodes = paginatedTaggedNodes.getContent();

    List<NodeDTO> response = new ArrayList<NodeDTO>();
    for (BaseNode item : taggedNodes) {
        response.add(EntityToDTO.toDTO(item));
    }

    return response;
}

From source file:rzd.vivc.documentexamination.controller.UserController.java

/**
 * ?   ??   /*  ww  w. j  a  v  a 2s.c  om*/
 */
private void addDepartments(Model model) {
    model.addAttribute("departments", departmentRepository.findAll(new Sort(Sort.Direction.ASC, "name")));
    model.addAttribute("roles", roleRepository.findAll(new Sort(Sort.Direction.ASC, "name")));
}