Search in sources :

Example 1 with FilterConfig

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;
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig)

Example 2 with FilterConfig

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;
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig)

Example 3 with FilterConfig

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"));
}
Also used : FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Example 4 with FilterConfig

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)));
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FormulaNode(org.activityinfo.model.formula.FormulaNode) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Example 5 with FilterConfig

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"));
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) Test(org.junit.Test)

Aggregations

FilterConfig (com.sencha.gxt.data.shared.loader.FilterConfig)11 FilterConfigBean (com.sencha.gxt.data.shared.loader.FilterConfigBean)9 Test (org.junit.Test)6 FieldValue (org.activityinfo.model.type.FieldValue)2 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 Quantity (org.activityinfo.model.type.number.Quantity)1 HasStringValue (org.activityinfo.model.type.primitive.HasStringValue)1 LocalDate (org.activityinfo.model.type.time.LocalDate)1