Search in sources :

Example 6 with Order

use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.

the class QSortUnitTests method shouldSupportSortByOperatorExpressions.

// DATACMNS-566
@Test
public void shouldSupportSortByOperatorExpressions() {
    QUser user = QUser.user;
    QSort sort = new QSort(user.dateOfBirth.yearMonth().asc());
    Sort result = sort.and(Sort.by(Direction.ASC, "lastname"));
    assertThat(result).hasSize(2);
    assertThat(result).contains(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString()));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 7 with Order

use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.

the class QSortUnitTests method shouldCreateSortForDeepNestedPathCorrectly.

// DATACMNS-621
@Test
public void shouldCreateSortForDeepNestedPathCorrectly() {
    QSort sort = new QSort(wrapperForUserWrapper.wrapper.user.firstname.asc());
    assertThat(sort).contains(new Order(Direction.ASC, "wrapper.user.firstname"));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Test(org.junit.Test)

Example 8 with Order

use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.

the class QSortUnitTests method shouldCreateSortForNestedPathCorrectly.

// DATACMNS-621
@Test
public void shouldCreateSortForNestedPathCorrectly() {
    QSort sort = new QSort(userWrapper.user.firstname.asc());
    assertThat(sort).contains(new Order(Direction.ASC, "user.firstname"));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Test(org.junit.Test)

Example 9 with Order

use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.

the class QSortUnitTests method handlesPlainStringPathsCorrectly.

// DATACMNS-755
@Test
public void handlesPlainStringPathsCorrectly() {
    StringPath path = new PathBuilderFactory().create(User.class).getString("firstname");
    QSort sort = new QSort(new OrderSpecifier<>(com.querydsl.core.types.Order.ASC, path));
    assertThat(sort).contains(new Order(Direction.ASC, "firstname"));
}
Also used : Order(org.springframework.data.domain.Sort.Order) PathBuilderFactory(com.querydsl.core.types.dsl.PathBuilderFactory) StringPath(com.querydsl.core.types.dsl.StringPath) Test(org.junit.Test)

Example 10 with Order

use of org.springframework.data.domain.Sort.Order in project spring-data-commons by spring-projects.

the class SortHandlerMethodArgumentResolver method legacyFoldExpressions.

/**
 * Folds the given {@link Sort} instance into two expressions. The first being the property list, the second being the
 * direction.
 *
 * @throws IllegalArgumentException if a {@link Sort} with multiple {@link Direction}s has been handed in.
 * @param sort must not be {@literal null}.
 * @return
 */
protected List<String> legacyFoldExpressions(Sort sort) {
    List<String> expressions = new ArrayList<>();
    ExpressionBuilder builder = null;
    for (Order order : sort) {
        Direction direction = order.getDirection();
        if (builder == null) {
            builder = new ExpressionBuilder(direction);
        } else if (!builder.hasSameDirectionAs(order)) {
            throw new IllegalArgumentException(String.format("%s in legacy configuration only supports a single direction to sort by!", getClass().getSimpleName()));
        }
        builder.add(order.getProperty());
    }
    return builder == null ? Collections.emptyList() : builder.dumpExpressionIfPresentInto(expressions);
}
Also used : Order(org.springframework.data.domain.Sort.Order) ArrayList(java.util.ArrayList) Direction(org.springframework.data.domain.Sort.Direction)

Aggregations

Order (org.springframework.data.domain.Sort.Order)38 Sort (org.springframework.data.domain.Sort)20 PageRequest (org.springframework.data.domain.PageRequest)14 Test (org.junit.Test)13 Direction (org.springframework.data.domain.Sort.Direction)9 PageImpl (org.springframework.data.domain.PageImpl)8 ArrayList (java.util.ArrayList)6 IdentifiableTestEntity (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity)4 IdentifiableTestEntitySpecification (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification)4 Pageable (org.springframework.data.domain.Pageable)4 Specification (org.springframework.data.jpa.domain.Specification)4 Document (org.bson.Document)2 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1 PathBuilderFactory (com.querydsl.core.types.dsl.PathBuilderFactory)1 StringPath (com.querydsl.core.types.dsl.StringPath)1 ResourcePage (eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage)1 WorkflowHistoricProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)1 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 Comparator (java.util.Comparator)1