Search in sources :

Example 11 with CompoundExpr

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

the class SubFormDeletionTest method deleteParent.

@Test
public void deleteParent() {
    QueryModel queryModel = new QueryModel(ReferralSubForm.FORM_ID);
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr(new CompoundExpr(IncidentForm.FORM_ID, ColumnModel.ID_SYMBOL)).as("parent");
    queryModel.selectExpr(new ConstantNode(1)).as("count");
    ColumnSet columnSet = query(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT));
    System.out.println(columnSet.getColumnView("parent"));
    // Now delete a number of parent records
    delete(IncidentForm.FORM_ID, "c528");
    // The query results should reflect the change
    columnSet = query(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT - 2));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) ConstantNode(org.activityinfo.model.formula.ConstantNode) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 12 with CompoundExpr

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

the class AttributeFieldBinding method createAttributeColumns.

private List<ColumnModel> createAttributeColumns(EnumItem[] items) {
    List<ColumnModel> columns = new ArrayList<>(items.length);
    for (int i = 0; i < items.length; i++) {
        String itemId = items[i].getId().asString();
        FormulaNode expr = new CompoundExpr(attrField.getId(), itemId);
        columns.add(new ColumnModel().setFormula(expr).as(itemId));
    }
    return columns;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) FormulaNode(org.activityinfo.model.formula.FormulaNode) ArrayList(java.util.ArrayList)

Example 13 with CompoundExpr

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

the class AdminDimBinding method getColumnQuery.

@Override
public List<ColumnModel> getColumnQuery(FormTree formTree) {
    ResourceId levelClassId = adminLevelFormClass(model.getLevelId());
    Optional<FormClass> adminClass = formTree.getFormClassIfPresent(levelClassId);
    if (adminClass.isPresent()) {
        ColumnModel id = new ColumnModel();
        id.setFormula(new CompoundExpr(levelClassId, ColumnModel.ID_SYMBOL));
        id.setId(idColumn);
        ColumnModel label = new ColumnModel();
        label.setFormula(new FieldPath(levelClassId, field(levelClassId, NAME_FIELD)));
        label.setId(labelColumn);
        return Arrays.asList(id, label);
    } else {
        return Collections.emptyList();
    }
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 14 with CompoundExpr

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

the class NodeMatch method toExpr.

private static FormulaNode toExpr(List<FormTree.Node> partition) {
    Iterator<FormTree.Node> it = partition.iterator();
    FormulaNode expr = new SymbolNode(it.next().getFieldId());
    while (it.hasNext()) {
        expr = new CompoundExpr(expr, new SymbolNode(it.next().getFieldId()));
    }
    return expr;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) JoinNode(org.activityinfo.store.query.shared.join.JoinNode)

Example 15 with CompoundExpr

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

the class EffectiveMapping method getRequiredColumns.

public List<ColumnModel> getRequiredColumns() {
    if (multiValued) {
        List<ColumnModel> columns = new ArrayList<>();
        EnumType enumType = (EnumType) this.formula.getResultType();
        for (EnumItem enumItem : enumType.getValues()) {
            ColumnModel columnModel = new ColumnModel();
            columnModel.setId(getColumnId(enumItem));
            columnModel.setFormula(new CompoundExpr(this.formula.getRootNode(), new SymbolNode(enumItem.getId())));
            columns.add(columnModel);
        }
        return columns;
    }
    if (this.mapping != null && this.formula.isValid()) {
        ColumnModel columnModel = new ColumnModel();
        columnModel.setId(getColumnId());
        columnModel.setFormula(this.formula.getFormula());
        return Collections.singletonList(columnModel);
    }
    return Collections.emptyList();
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) EnumType(org.activityinfo.model.type.enumerated.EnumType) ColumnModel(org.activityinfo.model.query.ColumnModel) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

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