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