use of org.activityinfo.model.formula.CompoundExpr in project activityinfo by bedatadriven.
the class LookupKeySetTest method multipleTextKeysTest.
@Test
public void multipleTextKeysTest() {
TestingStorageProvider catalog = setup.getCatalog();
SimpleReferenceForm refForm = catalog.getSimpleReferenceForm();
MultipleTextKeysForm multTextKeyForm = catalog.getMultipleTextKeysForm();
FormField refField = refForm.getRefField();
CompoundExpr pathToKey1 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.FIRST_TEXT_KEY_ID.asString());
CompoundExpr pathToKey2 = new CompoundExpr(refField.getId(), MultipleTextKeysForm.SECOND_TEXT_KEY_ID.asString());
FormTree formTree = catalog.getFormTree(multTextKeyForm.getFormId());
LookupKeySet lookupKeySet = new LookupKeySet(formTree, refField);
Map<LookupKey, FormulaNode> formulas = lookupKeySet.getKeyFormulas(refField.getId());
assertThat(formulas.values(), containsInAnyOrder(pathToKey1, pathToKey2));
}
use of org.activityinfo.model.formula.CompoundExpr in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormExport.
@Test
public void testSubFormExport() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).addColumns(ImmutableTableColumn.builder().label("My PCODE").formula(IncidentForm.PROTECTION_CODE_FIELD_ID.asString()).build()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<TableModel> exportModel = setup.connect(viewModel.computeExportModel(Observable.just(ReferralSubForm.FORM_ID), Observable.just(ExportScope.SELECTED)));
System.out.println(Json.stringify(exportModel.assertLoaded().toJson(), 2));
assertThat(exportModel.assertLoaded().getFormId(), equalTo(ReferralSubForm.FORM_ID));
assertThat(exportModel.assertLoaded().getColumns(), hasSize(3));
TableColumn firstColumn = exportModel.assertLoaded().getColumns().get(0);
assertThat(firstColumn.getLabel(), equalTo(Optional.of("My PCODE")));
assertThat(firstColumn.getFormula(), equalTo(new CompoundExpr(new SymbolNode(ColumnModel.PARENT_SYMBOL), IncidentForm.PROTECTION_CODE_FIELD_ID).asExpression()));
}
use of org.activityinfo.model.formula.CompoundExpr in project activityinfo by bedatadriven.
the class PartnerDimBinding method getColumnQuery.
private List<ColumnModel> getColumnQuery(ResourceId formId) {
SymbolNode partnerField = new SymbolNode(CuidAdapter.field(formId, CuidAdapter.PARTNER_FIELD));
ColumnModel partnerId = new ColumnModel();
partnerId.setFormula(partnerField);
partnerId.setId(PARTNER_ID_COLUMN);
ColumnModel partnerLabel = new ColumnModel();
partnerLabel.setFormula(new CompoundExpr(partnerField, new SymbolNode("label")));
partnerLabel.setId(PARTNER_LABEL_COLUMN);
return Arrays.asList(partnerId, partnerLabel);
}
use of org.activityinfo.model.formula.CompoundExpr in project activityinfo by bedatadriven.
the class ProjectDimBinding method getTargetColumnQuery.
@Override
public List<ColumnModel> getTargetColumnQuery(ResourceId targetFormId) {
SymbolNode projectField = new SymbolNode(CuidAdapter.field(targetFormId, CuidAdapter.PROJECT_FIELD));
ColumnModel projectId = new ColumnModel();
projectId.setFormula(projectField);
projectId.setId(PROJECT_ID_COLUMN);
ColumnModel projectLabel = new ColumnModel();
projectLabel.setFormula(new CompoundExpr(projectField, new SymbolNode("label")));
projectLabel.setId(PROJECT_LABEL_COLUMN);
return Arrays.asList(projectId, projectLabel);
}
use of org.activityinfo.model.formula.CompoundExpr in project activityinfo by bedatadriven.
the class NodeMatcherTest method resolve.
private Collection<String> resolve(String exprString) {
FormTree tree = tree();
symbolTable = new NodeMatcher(tree);
FormulaNode expr = FormulaParser.parse(exprString);
Collection<NodeMatch> matches;
if (expr instanceof SymbolNode) {
matches = symbolTable.resolveSymbol((SymbolNode) expr);
} else if (expr instanceof CompoundExpr) {
matches = symbolTable.resolveCompoundExpr((CompoundExpr) expr);
} else {
throw new IllegalArgumentException(exprString);
}
// Create a string that we can match against easily
List<String> strings = Lists.newArrayList();
for (NodeMatch match : matches) {
strings.add(match.toDebugString());
}
System.out.println("Resolved " + exprString + " => " + strings);
return strings;
}
Aggregations