Search in sources :

Example 1 with FilterOperator

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));
        }
    }
}
Also used : FilterOperator(io.crnk.core.queryspec.FilterOperator) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FilterSpec(io.crnk.core.queryspec.FilterSpec)

Aggregations

FilterOperator (io.crnk.core.queryspec.FilterOperator)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1