use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.
the class ColumnFilterParser method parseEnumList.
/**
* Parse a list of enum item conditionals in the form (X.A || X.B || X.C)
*/
private boolean parseEnumList(FormulaNode node, Multimap<Integer, FilterConfig> result) {
List<FormulaNode> terms = Formulas.findBinaryTree(node, OrFunction.INSTANCE);
// Ensure that each term is a compound expression in the form X.Y1, X.Y2, X.Y2
Iterator<FormulaNode> termIt = terms.iterator();
FormulaNode first = termIt.next();
if (!(first instanceof CompoundExpr)) {
return false;
}
List<String> enumItemIds = new ArrayList<>();
CompoundExpr firstCompoundExpr = (CompoundExpr) first;
Integer firstColumnIndex = findColumnIndex(firstCompoundExpr.getValue());
if (firstColumnIndex == null) {
return false;
}
enumItemIds.add(firstCompoundExpr.getField().getName());
// same field
while (termIt.hasNext()) {
FormulaNode term = termIt.next();
if (!(term instanceof CompoundExpr)) {
return false;
}
CompoundExpr compoundExpr = (CompoundExpr) term;
Integer columnIndex = findColumnIndex(compoundExpr.getValue());
if (columnIndex == null || columnIndex != firstColumnIndex) {
return false;
}
enumItemIds.add(compoundExpr.getField().getName());
}
// We have a filter that is supported by ListFilter
FilterConfig listFilter = new FilterConfigBean();
listFilter.setType("list");
listFilter.setValue(Joiner.on("::").join(enumItemIds));
result.put(firstColumnIndex, listFilter);
return true;
}
use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.
the class ColumnFilterParser method numericFilter.
private FilterConfig numericFilter(FunctionCallNode callNode, Quantity quantity) {
FilterConfig config = new FilterConfigBean();
config.setType("numeric");
config.setComparison(parseNumericComparison(callNode));
config.setValue(Double.toString(quantity.getValue()));
return config;
}
use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.
the class ColumnFilterParserTest method simpleTest.
@Test
public void simpleTest() {
ColumnFilterParser parser = new ColumnFilterParser(asList(A));
Multimap<Integer, FilterConfig> map = parser.parseFilter(parse("A > 50"));
Collection<FilterConfig> filters = map.get(0);
assertThat(filters, hasSize(1));
assertThat(map.get(0), contains(numericFilter("gt", 50)));
FilterConfig filter = filters.iterator().next();
assertThat(filter.getType(), equalTo("numeric"));
assertThat(filter.getComparison(), equalTo("gt"));
assertThat(filter.getValue(), equalTo("50.0"));
}
use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.
the class ColumnFilterParserTest method roundTrip.
@Test
public void roundTrip() {
FilterConfig config = new FilterConfigBean();
config.setType("numeric");
config.setComparison("eq");
config.setValue("1");
FormulaNode columnExpr = parse("IF(A && B, A * 42 / 3, CEIL(B / 99))");
String filterFormula = toFormula(columnExpr, config).asExpression();
ColumnFilterParser parser = new ColumnFilterParser(asList(A, columnExpr));
Multimap<Integer, FilterConfig> map = parser.parseFilter(parse(filterFormula));
assertThat(map.get(1), contains(numericFilter("eq", 1)));
}
use of com.sencha.gxt.data.shared.loader.FilterConfig in project activityinfo by bedatadriven.
the class ColumnFilterParserTest method numeric.
@Test
public void numeric() {
FilterConfig config = new FilterConfigBean();
config.setField("A");
config.setType("numeric");
config.setComparison("eq");
config.setValue("42");
assertThat(toFormula(A, config).asExpression(), equalTo("A == 42"));
}
Aggregations