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