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:it.reply.orchestrator.controller.DeploymentControllerTest.java

@Test
public void getPagedDeployments() throws Exception {

    List<Deployment> deployments = ControllerTestUtils.createDeployments(5, true);
    Pageable pageable = new PageRequest(1, 2,
            new Sort(Direction.DESC, AbstractResourceEntity.CREATED_COLUMN_NAME));
    Mockito.when(deploymentService.getDeployments(pageable))
            .thenReturn(new PageImpl<Deployment>(deployments, pageable, deployments.size()));

    mockMvc.perform(get("/deployments?page=1&size=2").accept(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andDo(document("deployment-paged", preprocessResponse(prettyPrint()),
                    links(atomLinks(), linkWithRel("first").description("Hyperlink to the first page"),
                            linkWithRel("prev").description("Hyperlink to the previous page"),
                            linkWithRel("self").description("Self-referencing hyperlink"),
                            linkWithRel("next").description("Self-referencing hyperlink"),
                            linkWithRel("last").description("Hyperlink to the last page")),
                    responseFields(fieldWithPath("links[]").ignored(), fieldWithPath("content").ignored(),
                            fieldWithPath("page.").ignored())));

    // .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(1)));
}

From source file:edu.chalmers.dat076.moviefinder.controller.FileController.java

private PageRequest getPageRequest(Integer page, String sort, Boolean asc) {
    Sort s = null;//ww  w  .j  ava2 s .  c om
    if (sort != null) {
        if (asc != null) {
            if (asc) {
                s = new Sort(Sort.Direction.ASC, sort);
            } else {
                s = new Sort(Sort.Direction.DESC, sort);
            }
        } else {
            s = new Sort(Sort.Direction.DESC, sort);
        }
    }
    PageRequest pageRequest;
    if (page != null) {
        pageRequest = new PageRequest(page, Constants.MEDIA_DISPLAYED, s);
    } else {
        pageRequest = new PageRequest(0, Constants.MEDIA_DISPLAYED, s);
    }
    return pageRequest;
}

From source file:com.github.camellabs.iot.cloudlet.geofencing.service.DefaultRouteService.java

protected RouteGpsCoordinates findLastRouteCoordinates(String client) {
    Query lastRouteCoordinatesQuery = new Query().addCriteria(where("client").is(client))
            .with(new Sort(DESC, "_id")).limit(1);
    return mongoTemplate.findOne(lastRouteCoordinatesQuery, RouteGpsCoordinates.class,
            collectionName(RouteGpsCoordinates.class));
}

From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java

List<M> findByBetweenAndDesc(Integer minWeight, Integer maxWeight) {
    Map<String, Object> searchParams = Maps.newHashMap();
    searchParams.put("weight_gte", minWeight);
    searchParams.put("weight_lte", maxWeight);

    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    return findAllWithSort(Searchable.newSearchable(searchParams).addSort(sort));
}

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

/**
 * ?   ??  // ww  w .j av  a2 s  .  c  o m
 */
private void addTypes(Model model) {
    model.addAttribute("types", documentTypeRepository.findAll(new Sort(Sort.Direction.ASC, "name")));
    model.addAttribute("departments", departmentRepository.findAll(new Sort(Sort.Direction.ASC, "name")));
}

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

@Test
public void testParameterDefaultSearchable() throws Exception {
    int pn = 1;/*from  w w  w . j av  a 2s .  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");

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

    //-10
    assertEquals(pn - 1, searchable.getPage().getPageNumber());
    assertEquals(pageSize, searchable.getPage().getPageSize());

    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("id", SearchOperator.eq, "1"), searchable);
}

From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java

@Override
public List<Launch> findLaunchesByProjectId(String projectId, Date from, String mode) {
    Query query = query(where(PROJECT_ID_REFERENCE).is(projectId))
            .addCriteria(where(STATUS).ne(IN_PROGRESS.name())).addCriteria(where(MODE).is(mode))
            .addCriteria(where(START_TIME).gt(from)).with(new Sort(Sort.Direction.ASC, START_TIME));
    return mongoTemplate.find(query, Launch.class);
}

From source file:com.github.jens_meiss.blog.server.service.impl.BlogServiceImpl.java

@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
@Override//  ww w  .  j a  v a 2s . c  o m
public List<PopularBlogDTO> getPopularBlogs(final int startIndex, final int length) {

    logger.debug("getPopularBlogs");

    final Page<BlogEntity> page = blogRepository.findAll(
            new PageRequest(startIndex, length, new Sort(new Sort.Order(Direction.DESC, "visitsPerDay"),
                    new Sort.Order(Direction.DESC, "dateLastUpdated"))));

    final List<PopularBlogDTO> popularBlogs = blogEntryToPopularBlogDTO(page.getContent());

    final PopulardBlogDTOImpl popularBlogDTO = new PopulardBlogDTOImpl();
    popularBlogDTO.setAuthor("author");
    popularBlogDTO.setDateLastUpdate(new Date(System.currentTimeMillis() + 1000));
    popularBlogDTO.setPath("path");
    popularBlogDTO.setPreview("preview");
    popularBlogDTO.setTitle("title");
    popularBlogDTO.setVisitsPerDay(12345);

    popularBlogs.add(popularBlogDTO);

    return popularBlogs;
}

From source file:com.minlia.cloud.framework.common.persistence.service.AbstractRawService.java

protected final Sort constructSort(final String sortBy, final String sortOrder) {
    Sort sortInfo = null;// w w  w .  j  av  a  2  s . co m
    if (sortBy != null) {
        sortInfo = new Sort(Direction.fromString(sortOrder), sortBy);
    }
    return sortInfo;
}

From source file:org.activiti.app.rest.editor.AbstractModelsResource.java

protected Sort getSort(String sort, boolean prefixWithProcessModel) {
    String propName;//from w  w  w  .  j  av  a  2  s.c om
    Direction direction;
    if (SORT_NAME_ASC.equals(sort)) {
        if (prefixWithProcessModel) {
            propName = "model.name";
        } else {
            propName = "name";
        }
        direction = Direction.ASC;
    } else if (SORT_NAME_DESC.equals(sort)) {
        if (prefixWithProcessModel) {
            propName = "model.name";
        } else {
            propName = "name";
        }
        direction = Direction.DESC;
    } else if (SORT_MODIFIED_ASC.equals(sort)) {
        if (prefixWithProcessModel) {
            propName = "model.lastUpdated";
        } else {
            propName = "lastUpdated";
        }
        direction = Direction.ASC;
    } else {
        // Default sorting
        if (prefixWithProcessModel) {
            propName = "model.lastUpdated";
        } else {
            propName = "lastUpdated";
        }
        direction = Direction.DESC;
    }
    return new Sort(direction, propName);
}