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:business.services.LabRequestService.java

private Sort sortByIdDesc() {
    return new Sort(Sort.Direction.DESC, "id");
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogService.java

private Sort createAttributeSort(Filter filter) {
    Sort.Direction direction = Sort.Direction.ASC;

    if (filter.getSortOrder() == Filter.SortOrder.DESCENDING) {
        direction = Sort.Direction.DESC;
    }/* ww w  .  j av  a2 s .com*/

    String sortAttribute = filter.getSortAttribute();

    if (sortAttribute != null) {
        if (sortAttribute.equals("originator")) {
            return new Sort(direction, "label.originatorOrFrom.value");
        } else if (sortAttribute.equals("from")) {
            return new Sort(direction, "label.originatorOrFrom.value");
        } else if (sortAttribute.equals("endrecipient")) {
            return new Sort(direction, "label.endRecipient.value");
        } else if (sortAttribute.equals("producttype")) {
            return new Sort(direction, "label.product.value");
        } else if (sortAttribute.equals("subject")) {
            return new Sort(direction, "label.subject");
        } else if (sortAttribute.equals("contentid")) {
            return new Sort(direction, "label.content.contentId");
        } else if (sortAttribute.equals("-corrid")) {
            return new Sort(direction, "label.corrId");
        } else if (sortAttribute.equals("sequencetype")) {
            return new Sort(direction, "label.sequenceType");
        } else if (sortAttribute.equals("transfertype")) {
            return new Sort(direction, "label.transferType");
        } else if (sortAttribute.startsWith("meta-")) {
            // for now: lets sort on the meta name instead of the meta name's value
            log.warn("Sorting on meta name instead of value corresponding to meta name.");
            return new Sort(direction, "label.meta.name");
        } else {
            throw new IllegalArgumentException("Unsupported sort attribute: " + sortAttribute);
        }
    }

    return null;
}

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

/**
 * Returns a Sort object that sorts the results in ascending order by call
 * number./*from   w ww.j av a 2s .co  m*/
 *
 * @return Sort object that sorts the results in ascending order by call
 * number
 */
private Sort sortByCallNumber() {
    return new Sort(Sort.Direction.ASC, "call_number");
}

From source file:org.openlmis.fulfillment.repository.OrderRepositoryIntegrationTest.java

@Test
public void shouldSort() {
    final Order one = orderRepository.save(generateInstance(OrderStatus.ORDERED));
    final Order two = orderRepository.save(generateInstance(OrderStatus.ORDERED));
    final Order three = orderRepository.save(generateInstance(OrderStatus.ORDERED));
    final Order four = orderRepository.save(generateInstance(OrderStatus.ORDERED));

    two.setCreatedDate(ZonedDateTime.of(2017, 3, 29, 0, 0, 0, 0, ZoneId.systemDefault()));
    four.setCreatedDate(ZonedDateTime.of(2017, 3, 29, 1, 0, 0, 0, ZoneId.systemDefault()));
    one.setCreatedDate(ZonedDateTime.of(2017, 3, 30, 0, 0, 0, 0, ZoneId.systemDefault()));
    three.setCreatedDate(ZonedDateTime.of(2017, 4, 1, 0, 0, 0, 0, ZoneId.systemDefault()));

    orderRepository.save(one);//w  w  w. jav  a  2  s  .c  o m
    orderRepository.save(two);
    orderRepository.save(three);
    orderRepository.save(four);

    HashSet<UUID> availableSupplyingFacilities = newHashSet(one.getSupplyingFacilityId(),
            two.getSupplyingFacilityId(), three.getSupplyingFacilityId(), four.getSupplyingFacilityId());

    OrderSearchParams params = new OrderSearchParams();
    params.setStatus(newHashSet(OrderStatus.ORDERED.name()));
    Page<Order> result = orderRepository.searchOrders(params, null,
            new PageRequest(0, 10, new Sort(Sort.Direction.DESC, "createdDate")), availableSupplyingFacilities,
            null);

    assertEquals(4, result.getContent().size());
    // They should be returned from the most recent to the least recent
    assertTrue(
            result.getContent().get(0).getCreatedDate().isAfter(result.getContent().get(1).getCreatedDate()));
    assertTrue(
            result.getContent().get(1).getCreatedDate().isAfter(result.getContent().get(2).getCreatedDate()));
    assertTrue(
            result.getContent().get(2).getCreatedDate().isAfter(result.getContent().get(3).getCreatedDate()));
}

From source file:com.pkrete.locationservice.admin.solr.service.impl.LocationIndexServiceImpl.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 a  2  s . com*/
private Sort sortByName() {
    return new Sort(Sort.Direction.ASC, "name");
}

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

/**
 * Generates a new Sort object based on the given values.
 *
 * @param sortDirection sort direction/*from w  w  w. j  a v a2 s .  c om*/
 * @param sortField field which value is used for sorting
 * @return new Sort object
 */
private Sort generateSort(String sortDirection, String sortField) {
    if (sortDirection.equals(RepositoryConstants.SORT_DESC)) {
        return new Sort(Sort.Direction.DESC, sortField);
    } else {
        return new Sort(Sort.Direction.ASC, sortField);
    }
}

From source file:de.inren.service.banking.BankDataServiceImpl.java

private Sort SortByValutaDateAsc() {
    return new Sort(Sort.Direction.ASC, "valutaDate");
}

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

@Override
public List<TestItem> findByHasChildStatus(boolean hasChildren, String launch) {
    Query query = query(where(LAUNCH_REFERENCE).is(launch)).addCriteria(where(HAS_CHILD).is(hasChildren))
            .with(new Sort(Sort.Direction.ASC, START_TIME));
    return mongoTemplate.find(query, TestItem.class);
}

From source file:com.traffitruck.service.MongoDAO.java

public List<Load> getLoadsForTruckByFilter(Truck truck, Double sourceLat, Double sourceLng,
        Integer source_radius, Double destinationLat, Double destinationLng, Integer destination_radius) {
    // The criteria API isn't good enough
    String query = "{";

    query += "weight: { $exists: true, $lte: " + truck.getMaxWeight() + " } ";
    if (truck.getMaxVolume() != null) {
        query += ", volume: { $exists: true, $lte: " + truck.getMaxVolume() + " } ";
    }/*from   w w  w .ja v a 2s .  c om*/
    query += ", type: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLoadTypes()) + "] } ";
    query += ", loadingType: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLiftTypes())
            + "] } ";
    query += ", downloadingType: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLiftTypes())
            + "] } ";
    if (sourceLat != null && sourceLng != null && source_radius != null) {
        query += ", sourceLocation : { $geoWithin : { $centerSphere: [ [" + sourceLng + ", " + sourceLat + "], "
                + source_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }
    if (destinationLat != null && destinationLng != null && destination_radius != null) {
        query += ", destinationLocation : { $geoWithin : { $centerSphere: [ [" + destinationLng + ", "
                + destinationLat + "], " + destination_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }
    // no need for the photo here
    query += "} , {loadPhoto:0}";
    BasicQuery queryobj = new BasicQuery(query);
    // sort results
    queryobj.with(new Sort(Direction.DESC, "driveDate"));

    List<Load> coll = mongoTemplate.find(queryobj, Load.class);
    coll.stream().forEach(load -> load.setLoadPhoto(null));

    return coll;
}

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

@Override
public List<TestItem> findForSpecifiedSubType(List<String> launchesIds, boolean hasChild,
        StatisticSubType type) {/*from   w w w  .j a  v  a2  s .c  o m*/
    String issueField = "statistics.issueCounter."
            + TestItemIssueType.valueOf(type.getTypeRef()).awareStatisticsField() + "." + type.getLocator();
    Query query = query(where(LAUNCH_REFERENCE).in(launchesIds)).addCriteria(where(HAS_CHILD).is(hasChild))
            .addCriteria(where(issueField).exists(true)).with(new Sort(Sort.Direction.ASC, START_TIME));
    return mongoTemplate.find(query, TestItem.class);
}