Search in sources :

Example 1 with Constraint

use of org.javarosa.core.model.condition.Constraint in project javarosa by opendatakit.

the class FormDef method evaluateConstraint.

public boolean evaluateConstraint(TreeReference ref, IAnswerData data) {
    if (data == null) {
        return true;
    }
    TreeElement node = mainInstance.resolveReference(ref);
    Constraint c = node.getConstraint();
    if (c == null) {
        return true;
    }
    EvaluationContext ec = new EvaluationContext(exprEvalContext, ref);
    ec.isConstraint = true;
    ec.candidateValue = data;
    boolean result = c.constraint.eval(mainInstance, ec);
    getEventNotifier().publishEvent(new Event("Constraint", new EvaluationResult(ref, result)));
    return result;
}
Also used : Constraint(org.javarosa.core.model.condition.Constraint) Event(org.javarosa.debug.Event) EvaluationContext(org.javarosa.core.model.condition.EvaluationContext) EvaluationResult(org.javarosa.debug.EvaluationResult) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 2 with Constraint

use of org.javarosa.core.model.condition.Constraint in project javarosa by opendatakit.

the class FormInstanceParser method attachBind.

private static void attachBind(TreeElement node, DataBinding bind) {
    node.setDataType(bind.getDataType());
    if (bind.relevancyCondition == null) {
        node.setRelevant(bind.relevantAbsolute);
    }
    if (bind.requiredCondition == null) {
        node.setRequired(bind.requiredAbsolute);
    }
    if (bind.readonlyCondition == null) {
        node.setEnabled(!bind.readonlyAbsolute);
    }
    if (bind.constraint != null) {
        node.setConstraint(new Constraint(bind.constraint, bind.constraintMessage));
    }
    node.setPreloadHandler(bind.getPreload());
    node.setPreloadParams(bind.getPreloadParams());
    node.setBindAttributes(bind.getAdditionalAttributes());
}
Also used : Constraint(org.javarosa.core.model.condition.Constraint)

Example 3 with Constraint

use of org.javarosa.core.model.condition.Constraint in project javarosa by opendatakit.

the class TreeElement method readExternal.

/* ==== SERIALIZATION ==== */
/*
     * TODO:
     *
     * this new serialization scheme is kind of lame. ideally, we shouldn't have
     * to sub-class TreeElement at all; we should have an API that can
     * seamlessly represent complex data model objects (like weight history or
     * immunizations) as if they were explicity XML subtrees underneath the
     * parent TreeElement
     *
     * failing that, we should wrap this scheme in an ExternalizableWrapper
     */
@Override
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
    name = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    multiplicity = ExtUtil.readInt(in);
    flags = ExtUtil.readInt(in);
    value = (IAnswerData) ExtUtil.read(in, new ExtWrapNullable(new ExtWrapTagged()), pf);
    // child
    if (!ExtUtil.readBool(in)) {
        // 1.
        // todo is this needed?
        children.clear();
    } else {
        // 2.
        int numChildren = (int) ExtUtil.readNumeric(in);
        children.clear();
        // 3.
        List<TreeElement> newChildren = new ArrayList<>(numChildren);
        for (int i = 0; i < numChildren; ++i) {
            boolean normal = ExtUtil.readBool(in);
            TreeElement child;
            if (normal) {
                // 3.1
                child = new TreeElement();
                child.readExternal(in, pf);
            } else {
                // 3.2
                child = (TreeElement) ExtUtil.read(in, new ExtWrapTagged(), pf);
            }
            child.setParent(this);
            newChildren.add(child);
        }
        children.addAll(newChildren);
    }
    // end Jan 22, 2009
    dataType = ExtUtil.readInt(in);
    instanceName = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    constraint = (Constraint) ExtUtil.read(in, new ExtWrapNullable(Constraint.class), pf);
    preloadHandler = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    preloadParams = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    namespace = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
    bindAttributes = ExtUtil.readAttributes(in, this);
    attributes = ExtUtil.readAttributes(in, this);
}
Also used : Constraint(org.javarosa.core.model.condition.Constraint) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) ArrayList(java.util.ArrayList) Constraint(org.javarosa.core.model.condition.Constraint) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Aggregations

Constraint (org.javarosa.core.model.condition.Constraint)3 ArrayList (java.util.ArrayList)1 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 ExtWrapNullable (org.javarosa.core.util.externalizable.ExtWrapNullable)1 ExtWrapTagged (org.javarosa.core.util.externalizable.ExtWrapTagged)1 EvaluationResult (org.javarosa.debug.EvaluationResult)1 Event (org.javarosa.debug.Event)1