Search in sources :

Example 1 with CompoundExpr

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));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree) LookupKey(org.activityinfo.model.formTree.LookupKey) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 2 with CompoundExpr

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()));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) TableColumn(org.activityinfo.model.analysis.TableColumn) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Example 3 with CompoundExpr

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);
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 4 with CompoundExpr

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);
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 5 with CompoundExpr

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;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree)

Aggregations

CompoundExpr (org.activityinfo.model.formula.CompoundExpr)16 SymbolNode (org.activityinfo.model.formula.SymbolNode)12 FormulaNode (org.activityinfo.model.formula.FormulaNode)7 ColumnModel (org.activityinfo.model.query.ColumnModel)6 Test (org.junit.Test)4 FormTree (org.activityinfo.model.formTree.FormTree)3 ArrayList (java.util.ArrayList)2 LookupKey (org.activityinfo.model.formTree.LookupKey)2 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)2 ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)1 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)1 TableColumn (org.activityinfo.model.analysis.TableColumn)1 TableModel (org.activityinfo.model.analysis.TableModel)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FieldPath (org.activityinfo.model.formTree.FieldPath)1 ConstantNode (org.activityinfo.model.formula.ConstantNode)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1