Search in sources :

Example 26 with Order

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

the class QSortUnitTests method concatenatesPlainSortCorrectly.

// DATACMNS-402
@Test
public void concatenatesPlainSortCorrectly() {
    QUser user = QUser.user;
    QSort sort = new QSort(user.firstname.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, "firstname"));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Sort(org.springframework.data.domain.Sort) Test(org.junit.Test)

Example 27 with Order

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

the class QSortUnitTests method shouldCreateSortForReallyDeepNestedPathCorrectly.

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

Example 28 with Order

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

the class SortUnitTests method ordersWithDifferentIgnoreCaseDoNotEqual.

// DATACMNS-436
@Test
public void ordersWithDifferentIgnoreCaseDoNotEqual() {
    Order foo = Order.by("foo");
    Order fooIgnoreCase = Order.by("foo").ignoreCase();
    assertThat(foo).isNotEqualTo(fooIgnoreCase);
    assertThat(foo.hashCode()).isNotEqualTo(fooIgnoreCase.hashCode());
}
Also used : Order(org.springframework.data.domain.Sort.Order) Test(org.junit.Test)

Example 29 with Order

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

the class SortHandlerMethodArgumentResolver method foldIntoExpressions.

/**
 * Folds the given {@link Sort} instance into a {@link List} of sort expressions, accumulating {@link Order} instances
 * of the same direction into a single expression if they are in order.
 *
 * @param sort must not be {@literal null}.
 * @return
 */
protected List<String> foldIntoExpressions(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)) {
            builder.dumpExpressionIfPresentInto(expressions);
            builder = new ExpressionBuilder(direction);
        }
        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)

Example 30 with Order

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

the class SortHandlerMethodArgumentResolverUnitTests method getRequestWithSort.

private static NativeWebRequest getRequestWithSort(Sort sort, String qualifier) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    if (sort == null) {
        return new ServletWebRequest(request);
    }
    for (Order order : sort) {
        String prefix = StringUtils.hasText(qualifier) ? qualifier + "_" : "";
        request.addParameter(prefix + "sort", String.format("%s,%s", order.getProperty(), order.getDirection().name()));
    }
    return new ServletWebRequest(request);
}
Also used : Order(org.springframework.data.domain.Sort.Order) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

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