Search in sources :

Example 1 with CursorObserver

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);
    }
}
Also used : Function(com.google.common.base.Function) CursorObserver(org.activityinfo.store.spi.CursorObserver) List(java.util.List) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue) FormField(org.activityinfo.model.form.FormField)

Example 2 with CursorObserver

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();
    }
}
Also used : CursorObserver(org.activityinfo.store.spi.CursorObserver) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) Map(java.util.Map)

Aggregations

CursorObserver (org.activityinfo.store.spi.CursorObserver)2 Function (com.google.common.base.Function)1 List (java.util.List)1 Map (java.util.Map)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 FieldValue (org.activityinfo.model.type.FieldValue)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 BooleanFieldValue (org.activityinfo.model.type.primitive.BooleanFieldValue)1