use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class SimpleConditionListTest method existing.
@Test
public void existing() throws IOException {
URL resource = Resources.getResource(SimpleConditionList.class, "formulas.txt");
List<String> formulas = Resources.readLines(resource, Charsets.UTF_8);
for (String formula : formulas) {
FormulaNode parsed = FormulaParser.parse(formula);
SimpleConditionList conditionList = SimpleConditionParser.parse(parsed);
String reformula = conditionList.toFormula().asExpression();
FormulaNode reparsed;
try {
reparsed = FormulaParser.parse(reformula);
} catch (Exception e) {
System.err.println("Original formula: " + formula);
System.err.println("conditionList: " + conditionList);
System.err.println("conditionList.toFormula(): " + reformula);
throw e;
}
SimpleConditionList reparsedConditionList = SimpleConditionParser.parse(reparsed);
if (!conditionList.equals(reparsedConditionList)) {
System.err.println("Original formula: " + formula);
System.err.println("conditionList: " + conditionList);
System.err.println("conditionList.toFormula(): " + reformula);
System.err.println("reparsedConditionList: " + reparsedConditionList);
throw new AssertionError("Round trip failed");
}
}
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class SimpleConditionListTest method singleSelectEqual.
@Test
public void singleSelectEqual() {
SimpleConditionList conditionList = SimpleConditionParser.parse(FormulaParser.parse("{Q1717540673}=={t1717155924}"));
FormulaNode formulaRoot = conditionList.toFormula();
System.out.println(formulaRoot.asExpression());
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class SimpleConditionListTest method testReparsing.
private void testReparsing(String expression, String errMessage) {
SimpleConditionList conditionList = SimpleConditionParser.parse(FormulaParser.parse(expression));
String reformula = conditionList.toFormula().asExpression();
FormulaNode reparsed = FormulaParser.parse(reformula);
SimpleConditionList reparsedConditionList = SimpleConditionParser.parse(reparsed);
if (!conditionList.equals(reparsedConditionList)) {
System.err.println(expression);
System.err.println("conditionList: " + conditionList);
System.err.println("conditionList.toFormula(): " + reformula);
System.err.println("reparsedConditionList: " + reparsedConditionList);
throw new AssertionError(errMessage);
}
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class FormScan method getValuesToCache.
public Map<String, Object> getValuesToCache() {
Map<String, Object> toPut = new HashMap<>();
for (Map.Entry<FormulaNode, PendingSlot<ColumnView>> column : columnMap.entrySet()) {
ColumnView value;
try {
value = column.getValue().get();
} catch (IllegalStateException e) {
throw new IllegalStateException(column.getKey().toString(), e);
}
toPut.put(fieldCacheKey(column.getKey()), value);
}
for (Map.Entry<ForeignKeyId, PendingSlot<ForeignKey>> fk : foreignKeyMap.entrySet()) {
toPut.put(fkCacheKey(fk.getKey()), fk.getValue().get());
}
if (!columnMap.isEmpty()) {
toPut.put(rowCountKey(), rowCountFromColumn(columnMap));
} else if (rowCount != null) {
toPut.put(rowCountKey(), rowCount.get());
}
return toPut;
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class FormScan method updateFromCache.
public void updateFromCache(Map<String, Object> cached) {
// See which columns we could retrieve from cache
for (FormulaNode fieldId : Lists.newArrayList(columnMap.keySet())) {
ColumnView view = (ColumnView) cached.get(fieldCacheKey(fieldId));
if (view != null) {
// populate the pending result slot with the view from the cache
columnMap.get(fieldId).set(view);
// remove this column from the list of columns to fetch
columnMap.remove(fieldId);
// resolve the rowCount slot if still needed
if (rowCount != null) {
rowCount.set(view.numRows());
rowCount = null;
}
}
}
// And which foreign keys...
for (ForeignKeyId keyId : Lists.newArrayList(foreignKeyMap.keySet())) {
ForeignKey map = (ForeignKey) cached.get(fkCacheKey(keyId));
if (map != null) {
foreignKeyMap.get(keyId).set(map);
foreignKeyMap.remove(keyId);
}
}
// Do we need a row count?
if (rowCount != null) {
Integer count = (Integer) cached.get(rowCountKey());
if (count != null) {
rowCount.set(count);
}
}
}
Aggregations