io.bitexpress.topia.commons.data.page.PageUtils Maven / Gradle / Ivy
package io.bitexpress.topia.commons.data.page;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import io.bitexpress.topia.commons.pagination.OneSortPageParam;
import io.bitexpress.topia.commons.pagination.PageParam;
import io.bitexpress.topia.commons.pagination.SortPageParam;
import io.bitexpress.topia.commons.pagination.SortParam;
public class PageUtils {
private PageUtils() {
}
public static PageRequest convert(OneSortPageParam pageParam) {
return convert((PageParam) pageParam,
pageParam.getSortParam() != null ? Arrays.asList(pageParam.getSortParam()) : null);
}
public static PageRequest convert(SortPageParam pageParam) {
return convert((PageParam) pageParam, pageParam.getSortParamList());
}
public static PageRequest convert(PageParam pageParam) {
return convert(pageParam, null);
}
public static PageRequest convert(PageParam pageParam, List sortParamList) {
Sort sort = Sort.unsorted();
if (CollectionUtils.isNotEmpty(sortParamList)) {
List orderList = new ArrayList<>();
for (SortParam sortParam : sortParamList) {
Order order = new Order(Direction.valueOf(sortParam.getDirection().name()), sortParam.getProperty());
orderList.add(order);
}
sort = Sort.by(orderList);
}
return PageRequest.of(pageParam.getNumber(), pageParam.getSize(), sort);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy