Search in sources :

Example 1 with SymbolNode

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

the class PermissionFilters method getReferenceBaseFilter.

/**
 * Returns a filter for records referenced by the given field.
 */
public Optional<FormulaNode> getReferenceBaseFilter(ResourceId fieldId) {
    FormulaNode filter = fieldFilters.get(fieldId);
    if (filter == null) {
        return Optional.absent();
    }
    SymbolNode fieldExpr = new SymbolNode(fieldId);
    return Optional.of(filter.transform(x -> {
        if (x.equals(fieldExpr)) {
            return new SymbolNode(ColumnModel.ID_SYMBOL);
        } else {
            return x;
        }
    }));
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) AndFunction(org.activityinfo.model.formula.functions.AndFunction) java.util(java.util) FormulaParser(org.activityinfo.model.formula.FormulaParser) FormulaValidator(org.activityinfo.analysis.FormulaValidator) Formulas(org.activityinfo.model.formula.Formulas) Multimap(com.google.common.collect.Multimap) FormPermissions(org.activityinfo.model.form.FormPermissions) FormulaNode(org.activityinfo.model.formula.FormulaNode) HashMultimap(com.google.common.collect.HashMultimap) FieldReference(org.activityinfo.analysis.FieldReference) ResourceId(org.activityinfo.model.resource.ResourceId) Optional(com.google.common.base.Optional) ColumnModel(org.activityinfo.model.query.ColumnModel) Operation(org.activityinfo.model.database.Operation) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FormTree(org.activityinfo.model.formTree.FormTree) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode)

Example 2 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode 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 SymbolNode

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

the class Presenter method choices.

private Supplier<Promise<List<Choice>>> choices(final Level level) {
    final QueryModel queryModel = new QueryModel(level.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr("label").as("label");
    if (!level.isRoot()) {
        Choice selectedParent = getSelection(level.getParent());
        queryModel.selectExpr("parent").as("parent");
        queryModel.setFilter(Formulas.equals(new SymbolNode("parent"), Formulas.idConstant(selectedParent.getRef().getRecordId())));
    }
    return new Supplier<Promise<List<Choice>>>() {

        @Override
        public Promise<List<Choice>> get() {
            return locator.queryTable(queryModel).then(new Function<ColumnSet, List<Choice>>() {

                @Nullable
                @Override
                public List<Choice> apply(ColumnSet input) {
                    ColumnView id = input.getColumnView("id");
                    ColumnView label = input.getColumnView("label");
                    ColumnView parent = input.getColumnView("parent");
                    List<Choice> choices = new ArrayList<>();
                    for (int i = 0; i < input.getNumRows(); i++) {
                        if (parent == null) {
                            choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i)));
                        } else {
                            choices.add(new Choice(level.getFormId(), ResourceId.valueOf(id.getString(i)), label.getString(i), new RecordRef(level.getParent().getFormId(), ResourceId.valueOf(parent.getString(i)))));
                        }
                    }
                    return choices;
                }
            });
        }
    };
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) Supplier(com.google.common.base.Supplier) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Nullable(javax.annotation.Nullable)

Example 4 with SymbolNode

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

the class QueryModel method selectResourceId.

/**
 * Adds the {@code ResourceId} as a string column to the table model with
 * the given column id
 */
public ColumnModel selectResourceId() {
    ColumnModel columnModel = new ColumnModel();
    columnModel.setFormula(new SymbolNode(ColumnModel.ID_SYMBOL));
    columns.add(columnModel);
    return columnModel;
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode)

Example 5 with SymbolNode

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

the class QueryModel method selectClassId.

public ColumnModel selectClassId() {
    ColumnModel columnModel = new ColumnModel();
    columnModel.setFormula(new SymbolNode(ColumnModel.CLASS_SYMBOL));
    columns.add(columnModel);
    return columnModel;
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode)

Aggregations

SymbolNode (org.activityinfo.model.formula.SymbolNode)22 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)12 FormulaNode (org.activityinfo.model.formula.FormulaNode)8 ColumnModel (org.activityinfo.model.query.ColumnModel)6 Test (org.junit.Test)5 FormTree (org.activityinfo.model.formTree.FormTree)4 ResourceId (org.activityinfo.model.resource.ResourceId)3 JoinNode (org.activityinfo.store.query.shared.join.JoinNode)3 ConstantNode (org.activityinfo.model.formula.ConstantNode)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Supplier (com.google.common.base.Supplier)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1