Removed redundant code that calculated count on queries, already implemented on the data tools package
This commit is contained in:
parent
d5c62539c5
commit
234aa359c0
|
@ -1,36 +0,0 @@
|
||||||
package eu.eudat.controllers.v2;
|
|
||||||
|
|
||||||
import eu.eudat.model.result.QueryResult;
|
|
||||||
import gr.cite.tools.data.query.Lookup;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class BaseController {
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(Function<L, List<T>> service, L lookup) {
|
|
||||||
return extractQueryResultWithCountWhen(service, lookup, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCountWhen(Function<L, List<T>> service, L lookup, Function<T, Boolean> when) {
|
|
||||||
List<T> result = service.apply(lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
List<T> all = service.apply(lookup);
|
|
||||||
long count = all.size();
|
|
||||||
if (when == null) return new QueryResult<>(result, count);
|
|
||||||
long countOverride = count;
|
|
||||||
for (T item : all) {
|
|
||||||
if (!when.apply(item)) countOverride--;
|
|
||||||
}
|
|
||||||
return new QueryResult<>(result, count, countOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, L extends Lookup> QueryResult<T> extractQueryResultWithCount(BiFunction<String, L, List<T>> service, String name, L lookup) {
|
|
||||||
List<T> result = service.apply(name, lookup);
|
|
||||||
lookup.setPage(null);
|
|
||||||
long count = service.apply(name, lookup).size();
|
|
||||||
return new QueryResult<>(result, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue