Created
July 7, 2020 13:31
-
-
Save mstahv/240f9950e62bff4f0a8778561e059b33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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