Skip to content

Instantly share code, notes, and snippets.

@mstahv
Created July 7, 2020 13:31
Show Gist options
  • Save mstahv/240f9950e62bff4f0a8778561e059b33 to your computer and use it in GitHub Desktop.
Save mstahv/240f9950e62bff4f0a8778561e059b33 to your computer and use it in GitHub Desktop.
import java.util.stream.Collectors;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import com.vaadin.flow.data.provider.Query;
import com.vaadin.flow.data.provider.SortDirection;
public class SpringDataVaadinUtil {
public static Sort toSpringDataSort(Query<?, Void> q) {
Sort springDataSort = Sort.by(q.getSortOrders().stream()
.map(so -> so.getDirection() == SortDirection.ASCENDING ? Order.asc(so.getSorted())
: Order.desc(so.getSorted()))
.collect(Collectors.toList()))
// default sort order for deterministic testing
.and(Sort.by("id"));
return springDataSort;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment