use of org.activityinfo.store.spi.CursorObserver in project activityinfo by bedatadriven.
the class ExprQueryBuilder method addExpr.
private void addExpr(FormulaNode expr, CursorObserver<FieldValue> target) {
if (expr instanceof SymbolNode) {
SymbolNode symbol = (SymbolNode) expr;
FormField field = symbolTable.resolveSymbol(symbol);
queryBuilder.addField(field.getId(), target);
} else if (expr instanceof FunctionCallNode) {
FunctionCallNode call = (FunctionCallNode) expr;
if (call.getArguments().isEmpty()) {
} else {
List<CursorObserver<FieldValue>> argumentObservers = CursorObservers.collect(target, call.getArguments().size(), call.getFunction());
for (int i = 0; i < call.getArgumentCount(); i++) {
addExpr(call.getArgument(i), argumentObservers.get(i));
}
}
} else if (expr instanceof CompoundExpr) {
CompoundExpr compoundExpr = (CompoundExpr) expr;
Function<FieldValue, FieldValue> reader;
if (isEnumItemReference(compoundExpr)) {
reader = new EnumItemReader(compoundExpr.getField().asResourceId());
} else {
reader = new ComponentReader(compoundExpr.getField().getName());
}
CursorObserver<FieldValue> valueObserver = CursorObservers.transform(reader, target);
addExpr(compoundExpr.getValue(), valueObserver);
} else if (expr instanceof ConstantNode) {
ConstantNode constantNode = (ConstantNode) expr;
Function<Object, FieldValue> constantFunction = Functions.constant(constantNode.getValue());
CursorObserver<ResourceId> rowObserver = CursorObservers.transform(constantFunction, target);
queryBuilder.addResourceId(rowObserver);
} else if (expr instanceof GroupNode) {
addExpr(((GroupNode) expr).getExpr(), target);
} else {
throw new UnsupportedOperationException("TODO: " + expr);
}
}
use of org.activityinfo.store.spi.CursorObserver in project activityinfo by bedatadriven.
the class TestingFormQueryBuilder method execute.
@Override
public void execute() {
for (FormInstance record : records) {
for (CursorObserver<ResourceId> idObserver : idObservers) {
idObserver.onNext(record.getId());
}
for (CursorObserver<FieldValue> parentObserver : parentObservers) {
parentObserver.onNext(new ReferenceValue(new RecordRef(formClass.getParentFormId().get(), record.getParentRecordId())));
}
for (Map.Entry<ResourceId, CursorObserver<FieldValue>> field : fieldObservers.entries()) {
ResourceId fieldId = field.getKey();
FieldValue fieldValue = record.get(fieldId);
CursorObserver<FieldValue> observer = field.getValue();
observer.onNext(fieldValue);
}
}
for (CursorObserver<ResourceId> observer : idObservers) {
observer.done();
}
for (CursorObserver<FieldValue> parentObserver : parentObservers) {
parentObserver.done();
}
for (CursorObserver<FieldValue> observer : fieldObservers.values()) {
observer.done();
}
}
Aggregations