use of com.querydsl.core.types.dsl.BooleanExpression in project Settler by EmhyrVarEmreis.
the class AbstractService method applyFilters.
private BooleanExpression applyFilters(String filtersJson, QEntity qObject, boolean isAnd) throws NoSuchFieldException, IllegalAccessException {
BooleanExpressionWrapper pWrapper = new BooleanExpressionWrapper();
if (isAnd) {
pWrapper.predicate = qObject.isNotNull();
} else {
pWrapper.predicate = qObject.ne(qObject);
}
for (BooleanExpression preFilter : getPreFilters()) {
pWrapper.predicate = pWrapper.predicate.and(preFilter);
}
if (filtersJson.length() == 0) {
return pWrapper.predicate;
}
ListFilters filters;
try {
filters = new ObjectMapper().readValue(filtersJson, getListFilterClass());
Stream.concat(Arrays.stream(filters.getClass().getDeclaredFields()), getExtendedFields(filters)).filter(field -> extractValueFromField(field, filters) != null).forEach(field -> {
AbstractServiceSingleFilter abstractServiceSingleFilter = AbstractServiceSingleFilter.getAbstractServiceSingleFilterClassFromField(field, singleFiltersPack);
if (abstractServiceSingleFilter == null) {
getAbstractServiceSingleFilters().stream().filter(filter -> filter.isApplicable(extractValueFromField(field, filters), extractValueFromField(extractFieldFromObject(qObject, field.getName()), qObject))).findFirst().ifPresent(filter -> pWrapper.predicate = apply(pWrapper, filter, field, filters, qObject, isAnd));
} else {
pWrapper.predicate = apply(pWrapper, abstractServiceSingleFilter, field, filters, qObject, isAnd);
}
});
} catch (IOException e) {
e.printStackTrace();
}
return pWrapper.predicate;
}
Aggregations