Search in sources :

Example 26 with FormulaNode

use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.

the class LookupKeySetTest method overlappingHierarchiesKeyQuery.

@Test
public void overlappingHierarchiesKeyQuery() {
    TestingStorageProvider catalog = setup.getCatalog();
    LocaliteForm localiteForm = catalog.getLocaliteForm();
    FormTree formTree = setup.getFormTree(localiteForm.getFormId());
    LookupKeySet lookupKeySet = new LookupKeySet(formTree, localiteForm.getAdminField());
    Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(localiteForm.getAdminField().getId());
    QueryModel queryModel = new QueryModel(localiteForm.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr(formulas.get(lookupKeySet.getKey(0))).as("province");
    queryModel.selectExpr(formulas.get(lookupKeySet.getKey(1))).as("territory");
    queryModel.selectExpr(formulas.get(lookupKeySet.getKey(2))).as("zs");
    Connection<ColumnSet> table = setup.connect(setup.getFormStore().query(queryModel));
    ColumnSet columnSet = table.assertLoaded();
    ColumnView id = columnSet.getColumnView("id");
    ColumnView province = columnSet.getColumnView("province");
    ColumnView territory = columnSet.getColumnView("territory");
    ColumnView zs = columnSet.getColumnView("zs");
    // First row references a Zone de Sante
    assertThat(id.getString(0), equalTo("c0"));
    assertThat(province.getString(0), equalTo("Province 14"));
    assertThat(territory.getString(0), nullValue());
    assertThat(zs.getString(0), equalTo("Zone de Sante 56"));
    // Second row references only a Province
    assertThat(id.getString(1), equalTo("c1"));
    assertThat(province.getString(1), equalTo("Province 8"));
    assertThat(territory.getString(1), nullValue());
    assertThat(zs.getString(1), nullValue());
    // Fifth row references a territory
    assertThat(id.getString(4), equalTo("c4"));
    assertThat(province.getString(4), equalTo("Province 15"));
    assertThat(territory.getString(4), equalTo("Territory 42"));
    assertThat(zs.getString(4), nullValue());
}
Also used : LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree) LookupKey(org.activityinfo.model.formTree.LookupKey) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 27 with FormulaNode

use of org.activityinfo.model.formula.FormulaNode 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)

Aggregations

FormulaNode (org.activityinfo.model.formula.FormulaNode)27 SymbolNode (org.activityinfo.model.formula.SymbolNode)8 FormTree (org.activityinfo.model.formTree.FormTree)7 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)7 Test (org.junit.Test)7 LookupKey (org.activityinfo.model.formTree.LookupKey)5 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)5 ColumnView (org.activityinfo.model.query.ColumnView)4 FormulaParser (org.activityinfo.model.formula.FormulaParser)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 ForeignKeyId (org.activityinfo.store.query.shared.join.ForeignKeyId)3 FormEvalContext (org.activityinfo.model.form.FormEvalContext)2 FormField (org.activityinfo.model.form.FormField)2 FormPermissions (org.activityinfo.model.form.FormPermissions)2 FormulaLexer (org.activityinfo.model.formula.FormulaLexer)2 FieldValue (org.activityinfo.model.type.FieldValue)2 JoinNode (org.activityinfo.store.query.shared.join.JoinNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 HashMultimap (com.google.common.collect.HashMultimap)1