use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class PermissionsEnforcer method can.
public boolean can(FormInstance record, Operation operation) {
FormPermissions formPermissions = supervisor.getFormPermissions(record.getFormId());
if (!formPermissions.isAllowed(operation)) {
return false;
}
if (!formPermissions.isFiltered(operation)) {
return true;
}
FormulaNode filter = parseFilter(record.getFormId(), formPermissions.getFilter(operation));
return evalFilter(record, filter);
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class TableViewModel method parentFormula.
private String parentFormula(ParsedFormula formula) {
if (!formula.isValid()) {
return formula.getFormula();
}
SymbolNode parentSymbol = new SymbolNode(ColumnModel.PARENT_SYMBOL);
FormulaNode transformed = formula.getRootNode().transform(node -> {
if (node instanceof SymbolNode) {
// A -> parent.A
return new CompoundExpr(parentSymbol, (SymbolNode) node);
} else {
return node;
}
});
return transformed.asExpression();
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class SelectionViewModel method evalPermission.
private static boolean evalPermission(FormMetadata form, FormInstance record, Operation operation) {
if (!form.getPermissions().isAllowed(operation)) {
return false;
}
if (!form.getPermissions().isFiltered(operation)) {
return true;
}
String filter = form.getPermissions().getFilter(operation);
try {
FormEvalContext context = new FormEvalContext(form.getSchema(), record);
FormulaNode formula = FormulaParser.parse(filter);
FieldValue result = formula.evaluate(context);
return result == BooleanFieldValue.TRUE;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to evaluate permission filter '" + filter + "'", e);
return false;
}
}
use of org.activityinfo.model.formula.FormulaNode in project activityinfo by bedatadriven.
the class FieldPath method toExpr.
public FormulaNode toExpr() {
Iterator<ResourceId> it = path.iterator();
FormulaNode expr = new SymbolNode(it.next());
while (it.hasNext()) {
expr = new CompoundExpr(expr, new SymbolNode(it.next()));
}
return expr;
}
use of org.activityinfo.model.formula.FormulaNode 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;
}
Aggregations