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.lixiaocong.service.impl.CommentServiceImpl.java

@Override
public List<Comment> getByArticle(long articleId) {
    return commentRepository.findByArticle_Id(articleId, new Sort(Sort.Direction.ASC, "createTime"));
}

From source file:org.terasoluna.gfw.web.pagination.PaginationInfoTest.java

/**
 * Sort Set/*from   w  ww.  j  a va  2  s .com*/
 */
@Test
public void testCreateAttributeMap_SortSet() {

    int page = 1;
    int size = 1;
    Sort mockedSort = new Sort(Direction.DESC, "id");

    // run
    Map<String, Object> attributesMap = PaginationInfo.createAttributeMap(page, size, mockedSort);

    // assert
    assertThat(Integer.valueOf(attributesMap.get("page").toString()), is(page));
    assertThat(Integer.valueOf(attributesMap.get("size").toString()), is(size));
    assertThat(attributesMap.get("sortOrderProperty").toString(), is("id"));
    assertThat(attributesMap.get("sortOrderDirection").toString(), is("DESC"));
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.MetricRepositoryImpl.java

/**
 * {@inheritDoc}//ww  w  . ja  va 2  s .c  o m
 */
@Override
public List<? extends ProcedureExecutionMetric> find(final DbApplication application, final String className,
        final String procedureName, final String[] procedureArguments) {
    final Criteria criteria = new Criteria(APPLICATION).is(application).and(PROC__CLASS_NAME).is(className)
            .and(PROC__NAME).is(procedureName).and(PROC__ARGUMENTS).is(procedureArguments);
    final Sort sort = new Sort(Sort.Direction.ASC, TIMESTAMP);
    final Query query = new Query(criteria).with(sort);
    return mongoTemplate.find(query, DbProcedureExecutionMetricImpl.class, DbTableNames.METRICS);
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.AddressStatsDAOMongo.java

@Override
public List<AddressStats> getAddressStatsSince(Integer addressId, Date time) {
    Query query = new Query(Criteria.where("addressId").is(addressId).and("refreshTime").gte(time));
    query.with(new Sort(Sort.Direction.ASC, "refreshTime"));
    return mongoOperation.find(query, AddressStats.class);
}

From source file:com.epam.ta.reportportal.core.log.impl.GetLogHandlerTest.java

@Test
public void testGetLogPageNumberDesc() {
    final PageRequest pageRequest = new PageRequest(0, 2, new Sort(Sort.Direction.DESC, "logTime"));

    final List<Log> logs = generateLogs(logRepository);
    final Log logToFind = logs.get(9);

    long pageNumber = prepareHandler().getPageNumber(logToFind.getId(), PROJECT_ID, Filter.builder()
            .withCondition(FilterCondition.builder().withCondition(Condition.EQUALS).withSearchCriteria("item")
                    .withValue(ITEM_ID).build())
            .withTarget(Log.class).build(),

            pageRequest);/* w  w w.ja  va 2  s .  co m*/

    Assert.assertThat(pageNumber, Matchers.equalTo(1L));
}

From source file:com.epam.ta.reportportal.core.widget.content.WidgetContentProvider.java

/**
 * Load content according input parameters
 *
 * @param filter//ww w .  java2  s.com
 * @param selectionOptions
 * @param options
 */
public Map<String, List<ChartObject>> getChartContent(Filter filter, SelectionOptions selectionOptions,
        ContentOptions options) {

    boolean revertResult = false;

    Class<?> type = filter.getTarget();
    CriteriaMap<?> criteriaMap = criteriaMapFactory.getCriteriaMap(type);

    // all data fields names should be converted to db style
    List<String> contentFields = transformToDBStyle(criteriaMap, options.getContentFields());
    List<String> metaDataFields = transformToDBStyle(criteriaMap, options.getMetadataFields());

    boolean isAscSort = selectionOptions.isAsc();

    /*
     * Dirty handler of not full output during ASC start_time sorting. In
     * 'a- lot-of-results' case users got last results truncated by page
     * limitation.
     */
    Sort sort;
    String sortingColumnName = selectionOptions.getSortingColumnName();
    if ("start_time".equalsIgnoreCase(sortingColumnName) && isAscSort) {
        sort = new Sort(Sort.Direction.DESC,
                criteriaMap.getCriteriaHolder(sortingColumnName).getQueryCriteria());
        revertResult = true;
    } else {
        sort = new Sort(isAscSort ? Sort.Direction.ASC : Sort.Direction.DESC,
                criteriaMap.getCriteriaHolder(sortingColumnName).getQueryCriteria());
    }

    Map<String, List<ChartObject>> result;

    IContentLoadingStrategy loadingStrategy = contentLoadersMap
            .get(GadgetTypes.findByName(options.getGadgetType()).get());
    expect(loadingStrategy, notNull()).verify(UNABLE_LOAD_WIDGET_CONTENT,
            Suppliers.formattedSupplier("Unknown gadget type: '{}'.", options.getGadgetType()));
    Map<String, List<String>> widgetOptions = null == options.getWidgetOptions() ? new HashMap<>()
            : options.getWidgetOptions();
    result = loadingStrategy.loadContent(filter, sort, options.getItemsCount(), contentFields, metaDataFields,
            widgetOptions);

    if (null != options.getContentFields()) {
        result = transformToFilterStyle(criteriaMap, result, options.getContentFields());
        result = transformNamesForUI(result);
    }
    /*
     * Reordering of results for user-friendly UI output. NOTE: Probably it
     * will be moved to 'transformation' method.
     */
    // TODO: move transformations in one common method
    // TODO: replace dirty-hack with specific gadget data freeze
    if (!revertResult || options.getGadgetType().equalsIgnoreCase(GadgetTypes.CASES_TREND.getType())) {
        result = mapRevert(result);
    }
    return result;
}

From source file:org.springside.examples.quickstart.service.BuyerDataService.java

/***/
private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
    Sort sort = null;/* ww  w  .  j a  va2  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.ASC, "customerId");

    }
    return new PageRequest(pageNumber - 1, pagzSize, sort);
}

From source file:com.dickthedeployer.dick.web.service.ProjectService.java

public List<ProjectModel> getProjects(List<Long> ids) {
    return projectDao.findByIdIn(ids, new Sort(Sort.Direction.DESC, "creationDate")).stream()
            .map(this::mapProjectView).collect(toList());
}

From source file:org.obiba.mica.security.service.SubjectAclService.java

/**
 * Get all permissions for the given resource and instance and for any subject.
 *
 * @param resource//from   ww  w.  j  a v a  2s  .c om
 * @param instance
 * @return
 */
public List<SubjectAcl> findByResourceInstance(String resource, String instance) {
    return subjectAclRepository.findByResourceAndInstance(resource, encode(instance), new Sort(
            new Sort.Order(Sort.Direction.DESC, "type"), new Sort.Order(Sort.Direction.ASC, "principal")));
}

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

@Test
public void testSearchable() throws Exception {
    int pn = 1;/*from   w  ww. j  a v  a  2s . com*/
    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(searchable, 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("username", SearchOperator.eq, "zhang"),
            searchable);
}