package ch.rasc.eds.starter.util;

import java.util.ArrayList;
import java.util.List;

import org.bson.conversions.Bson;

import com.mongodb.client.model.Sorts;

import ch.ralscha.extdirectspring.bean.ExtDirectStoreReadRequest;
import ch.ralscha.extdirectspring.bean.SortDirection;
import ch.ralscha.extdirectspring.bean.SortInfo;

public abstract class QueryUtil {

	public static List<Bson> getSorts(ExtDirectStoreReadRequest request) {
		List<Bson> sorts = new ArrayList<>();
		for (SortInfo sortInfo : request.getSorters()) {

			if (sortInfo.getDirection() == SortDirection.ASCENDING) {
				sorts.add(Sorts.ascending(sortInfo.getProperty()));
			}
			else {
				sorts.add(Sorts.descending(sortInfo.getProperty()));
			}
		}
		return sorts;
	}

}
@@ -83,43 +83,190 @@
 st;%0A
-%0Aimport org.bson.conversions.Bson;%0A
+import java.util.stream.Collectors;%0Aimport java.util.stream.Stream;%0Aimport java.util.stream.StreamSupport;%0A%0Aimport org.bson.conversions.Bson;%0A%0Aimport com.mongodb.client.FindIterable;
 %0Aimp
@@ -889,9 +889,300 @@
 ts;%0A%09%7D%0A%0A
+%09public static %3CT%3E List%3CT%3E toList(FindIterable%3CT%3E iterable) %7B%0A%09%09return StreamSupport.stream(iterable.spliterator(), false)%0A%09%09%09%09.collect(Collectors.toList());%0A%09%7D%0A%0A%09public static %3CT%3E Stream%3CT%3E stream(FindIterable%3CT%3E iterable) %7B%0A%09%09return StreamSupport.stream(iterable.spliterator(), false);%0A%09%7D%0A
 %7D

Add helper methods that convert a FindIterable to a List and Stream