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();
}
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));
}
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));
}
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();
}
Aggregations