Search in sources :

Example 1 with GridComponentFilterOperator

use of com.qcadoo.view.internal.components.grid.GridComponentFilterOperator in project qcadoo by qcadoo.

the class GridComponentFilterSQLUtils method parseFilterValue.

private static Entry<GridComponentFilterOperator, String> parseFilterValue(final String filterValue) {
    GridComponentFilterOperator operator = GridComponentFilterOperator.EQ;
    String value;
    if (filterValue.charAt(0) == '>') {
        if (filterValue.length() > 1 && filterValue.charAt(1) == '=') {
            operator = GridComponentFilterOperator.GE;
            value = filterValue.substring(2);
        } else if (filterValue.length() > 1 && filterValue.charAt(1) == '<') {
            operator = GridComponentFilterOperator.NE;
            value = filterValue.substring(2);
        } else {
            operator = GridComponentFilterOperator.GT;
            value = filterValue.substring(1);
        }
    } else if (filterValue.charAt(0) == '<') {
        if (filterValue.length() > 1 && filterValue.charAt(1) == '=') {
            operator = GridComponentFilterOperator.LE;
            value = filterValue.substring(2);
        } else if (filterValue.length() > 1 && filterValue.charAt(1) == '>') {
            operator = GridComponentFilterOperator.NE;
            value = filterValue.substring(2);
        } else {
            operator = GridComponentFilterOperator.LT;
            value = filterValue.substring(1);
        }
    } else if (filterValue.charAt(0) == '=') {
        if (filterValue.length() > 1 && filterValue.charAt(1) == '<') {
            operator = GridComponentFilterOperator.LE;
            value = filterValue.substring(2);
        } else if (filterValue.length() > 1 && filterValue.charAt(1) == '>') {
            operator = GridComponentFilterOperator.GE;
            value = filterValue.substring(2);
        } else if (filterValue.length() > 1 && filterValue.charAt(1) == '=') {
            value = filterValue.substring(2);
        } else {
            value = filterValue.substring(1);
        }
    } else if (filterValue.charAt(0) == '[' && filterValue.charAt(filterValue.length() - 1) == ']') {
        operator = GridComponentFilterOperator.IN;
        value = filterValue.substring(1, filterValue.length() - 1);
    } else if (filterValue.charAt(0) == '{' && filterValue.charAt(filterValue.length() - 1) == '}') {
        operator = GridComponentFilterOperator.CIN;
        value = filterValue.substring(1, filterValue.length() - 1);
    } else if (ISNULL.name().equals(filterValue.toUpperCase())) {
        operator = GridComponentFilterOperator.ISNULL;
        value = "";
    } else {
        value = filterValue;
    }
    return Collections.singletonMap(operator, value.trim()).entrySet().iterator().next();
}
Also used : GridComponentFilterOperator(com.qcadoo.view.internal.components.grid.GridComponentFilterOperator)

Example 2 with GridComponentFilterOperator

use of com.qcadoo.view.internal.components.grid.GridComponentFilterOperator in project qcadoo by qcadoo.

the class GridComponentFilterSQLUtils method addStringFilter.

private static void addStringFilter(final String table, final StringBuilder filterQuery, final Entry<GridComponentFilterOperator, String> filterValue, final String field) {
    String value = filterValue.getValue();
    GridComponentFilterOperator operator = filterValue.getKey();
    if (filterValue.getKey() == GridComponentFilterOperator.EQ) {
        operator = GridComponentFilterOperator.CN;
    }
    filterQuery.append(GridComponentFilterGroupOperator.AND + " ");
    filterQuery.append(createStringCriterion(table, operator, value, field));
}
Also used : GridComponentFilterOperator(com.qcadoo.view.internal.components.grid.GridComponentFilterOperator)

Example 3 with GridComponentFilterOperator

use of com.qcadoo.view.internal.components.grid.GridComponentFilterOperator in project qcadoo by qcadoo.

the class GridComponentMultiSearchFilter method addRule.

public void addRule(final String field, final String operator, final String data) {
    GridComponentFilterOperator filterOperator = resolveOperator(operator);
    rules.add(new GridComponentMultiSearchFilterRule(field, filterOperator, data));
}
Also used : GridComponentFilterOperator(com.qcadoo.view.internal.components.grid.GridComponentFilterOperator) GridComponentMultiSearchFilterRule(com.qcadoo.view.internal.components.grid.GridComponentMultiSearchFilterRule)

Example 4 with GridComponentFilterOperator

use of com.qcadoo.view.internal.components.grid.GridComponentFilterOperator in project qcadoo by qcadoo.

the class GridComponentFilterSQLUtils method addFilters.

public static String addFilters(final Map<String, String> filters, final Map<String, GridComponentColumn> columns, String table, final DataDefinition dataDefinition) throws GridComponentFilterException {
    StringBuilder filterQuery = new StringBuilder(" 1=1 ");
    for (Entry<String, String> filter : filters.entrySet()) {
        String field = getFieldNameByColumnName(columns, filter.getKey());
        if (field != null) {
            try {
                FieldDefinition fieldDefinition = getFieldDefinition(dataDefinition, field);
                Entry<GridComponentFilterOperator, String> filterValue = parseFilterValue(filter.getValue());
                if ("".equals(filterValue.getValue()) && !ISNULL.equals(filterValue.getKey())) {
                    continue;
                }
                if (fieldDefinition != null && String.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    addStringFilter(table, filterQuery, filterValue, field);
                } else if (fieldDefinition != null && Boolean.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    addSimpleFilter(table, filterQuery, filterValue, field, "1".equals(filterValue.getValue()));
                } else if (fieldDefinition != null && Date.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    addDateFilter(table, filterQuery, filterValue, field);
                } else if (fieldDefinition != null && BigDecimal.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    addDecimalFilter(table, filterQuery, filterValue, field);
                } else if (fieldDefinition != null && Integer.class.isAssignableFrom(fieldDefinition.getType().getType())) {
                    addIntegerFilter(table, filterQuery, filterValue, field);
                } else {
                    addSimpleFilter(table, filterQuery, filterValue, field, filterValue.getValue());
                }
            } catch (ParseException pe) {
                throw new GridComponentFilterException(filter.getValue());
            }
        }
    }
    return filterQuery.toString();
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) ParseException(java.text.ParseException) GridComponentFilterException(com.qcadoo.view.internal.components.grid.GridComponentFilterException) GridComponentFilterOperator(com.qcadoo.view.internal.components.grid.GridComponentFilterOperator) Date(java.util.Date)

Aggregations

GridComponentFilterOperator (com.qcadoo.view.internal.components.grid.GridComponentFilterOperator)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 GridComponentFilterException (com.qcadoo.view.internal.components.grid.GridComponentFilterException)1 GridComponentMultiSearchFilterRule (com.qcadoo.view.internal.components.grid.GridComponentMultiSearchFilterRule)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1