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;
}
}));
}
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()));
}
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;
}
});
}
};
}
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;
}
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;
}
Aggregations