use of io.crnk.core.queryspec.FilterOperator in project crnk-framework by crnk-project.
the class ActivitiQuerySpecMapper method applyFilterSpec.
private static void applyFilterSpec(Query activitiQuery, QuerySpec querySpec, List<FilterSpec> baseFilters) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
List<FilterSpec> filters = new ArrayList<>();
filters.addAll(baseFilters);
filters.addAll(querySpec.getFilters());
for (FilterSpec filterSpec : filters) {
List<String> attributePath = filterSpec.getAttributePath();
if (attributePath.size() == 2 && "id".equals(attributePath.get(1))) {
attributePath = Arrays.asList(attributePath.get(0) + "Id");
}
PreconditionUtil.assertTrue("nested attribute paths not supported", attributePath.size() == 1);
String attrName = attributePath.get(0);
FilterOperator op = filterSpec.getOperator();
Class valueClass = filterSpec.getValue().getClass();
String attributeName = mapAttributeName(attrName, querySpec.getResourceClass(), op, valueClass);
Object value = filterSpec.getValue();
Method method = getMethod(activitiQuery.getClass(), attributeName);
if (method.getParameterCount() == 0) {
PreconditionUtil.assertEquals("only filtering by true supported for boolean values", Boolean.TRUE, value);
method.invoke(activitiQuery);
} else {
Class<?> expectedType = method.getParameterTypes()[0];
method.invoke(activitiQuery, unmapValue(value, expectedType));
}
}
}
Aggregations