Search in sources :

Example 1 with GridComponentFilterException

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

the class GridComponentFilterSQLUtils method createIntegerCriterion.

private static String createIntegerCriterion(String table, GridComponentFilterOperator filterOperator, String data, String field) throws GridComponentFilterException {
    try {
        final Object value;
        if (filterOperator == GridComponentFilterOperator.IN) {
            Collection<String> values = parseListValue(data);
            Collection<Integer> integerValues = Lists.newArrayListWithCapacity(values.size());
            for (String stringValue : values) {
                integerValues.add(Integer.valueOf(stringValue));
            }
            value = integerValues;
        } else {
            value = Integer.valueOf(data);
        }
        return createSimpleCriterion(table, filterOperator, value, field);
    } catch (NumberFormatException nfe) {
        throw new GridComponentFilterException(data, nfe);
    }
}
Also used : GridComponentFilterException(com.qcadoo.view.internal.components.grid.GridComponentFilterException)

Example 2 with GridComponentFilterException

use of com.qcadoo.view.internal.components.grid.GridComponentFilterException 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)

Example 3 with GridComponentFilterException

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

the class GridComponentFilterSQLUtils method createDecimalCriterion.

private static String createDecimalCriterion(String table, GridComponentFilterOperator filterOperator, String data, String field) throws GridComponentFilterException {
    try {
        final Object value;
        if (filterOperator == GridComponentFilterOperator.IN) {
            Collection<String> values = parseListValue(data);
            Collection<BigDecimal> decimalValues = Lists.newArrayListWithCapacity(values.size());
            for (String stringValue : values) {
                decimalValues.add(new BigDecimal(stringValue));
            }
            value = decimalValues;
        } else {
            value = new BigDecimal(data);
        }
        return createSimpleCriterion(table, filterOperator, value, field);
    } catch (NumberFormatException nfe) {
        throw new GridComponentFilterException(data, nfe);
    }
}
Also used : GridComponentFilterException(com.qcadoo.view.internal.components.grid.GridComponentFilterException) BigDecimal(java.math.BigDecimal)

Aggregations

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