Search in sources :

Example 16 with IDataReference

use of org.javarosa.core.model.IDataReference in project collect by opendatakit.

the class FormController method isLogicalGroup.

/**
 * Returns true if the group has an XML `ref` attribute,
 * i.e. it's a "logical group".
 * <p>
 * TODO: Improve this nasty way to recreate what XFormParser#parseGroup does for nodes without a `ref`.
 */
private boolean isLogicalGroup(FormIndex groupIndex) {
    TreeReference groupRef = groupIndex.getReference();
    TreeReference parentRef = groupRef.getParentRef();
    IDataReference absRef = FormDef.getAbsRef(new XPathReference(groupRef), parentRef);
    IDataReference bindRef = getCaptionPrompt(groupIndex).getFormElement().getBind();
    // If the group's bind is equal to what it would have been set to during parsing, it must not have a ref.
    return !absRef.equals(bindRef);
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) IDataReference(org.javarosa.core.model.IDataReference) XPathReference(org.javarosa.model.xform.XPathReference)

Example 17 with IDataReference

use of org.javarosa.core.model.IDataReference in project collect by opendatakit.

the class FormController method getSubmissionMetadata.

/**
 * Get the OpenRosa required metadata of the portion of the form beng submitted
 */
public InstanceMetadata getSubmissionMetadata() {
    FormDef formDef = formEntryController.getModel().getForm();
    TreeElement rootElement = formDef.getInstance().getRoot();
    TreeElement trueSubmissionElement;
    // Determine the information about the submission...
    SubmissionProfile p = formDef.getSubmissionProfile();
    if (p == null || p.getRef() == null) {
        trueSubmissionElement = rootElement;
    } else {
        IDataReference ref = p.getRef();
        trueSubmissionElement = formDef.getInstance().resolveReference(ref);
        // resolveReference returns null if the reference is to the root element...
        if (trueSubmissionElement == null) {
            trueSubmissionElement = rootElement;
        }
    }
    // and find the depth-first meta block in this...
    TreeElement e = findDepthFirst(trueSubmissionElement, "meta");
    String instanceId = null;
    String instanceName = null;
    AuditConfig auditConfig = null;
    if (e != null) {
        List<TreeElement> v;
        // instance id...
        v = e.getChildrenWithName(INSTANCE_ID);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceId = sa.getDisplayText();
            }
        }
        // instance name...
        v = e.getChildrenWithName(INSTANCE_NAME);
        if (v.size() == 1) {
            IAnswerData sa = v.get(0).getValue();
            if (sa != null) {
                instanceName = sa.getDisplayText();
            }
        }
        // timing element...
        v = e.getChildrenWithName(AUDIT);
        if (v.size() == 1) {
            TreeElement auditElement = v.get(0);
            String locationPriority = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-priority");
            String locationMinInterval = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-min-interval");
            String locationMaxAge = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-max-age");
            boolean isTrackingChangesEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes"));
            boolean isIdentifyUserEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "identify-user"));
            String trackChangesReason = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes-reasons");
            auditConfig = new AuditConfig.Builder().setMode(locationPriority).setLocationMinInterval(locationMinInterval).setLocationMaxAge(locationMaxAge).setIsTrackingChangesEnabled(isTrackingChangesEnabled).setIsIdentifyUserEnabled(isIdentifyUserEnabled).setIsTrackChangesReasonEnabled(trackChangesReason != null && trackChangesReason.equals("on-form-edit")).createAuditConfig();
            IAnswerData answerData = new StringData();
            answerData.setValue(AUDIT_FILE_NAME);
            auditElement.setValue(answerData);
        }
    }
    return new InstanceMetadata(instanceId, instanceName, auditConfig);
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) FormDef(org.javarosa.core.model.FormDef) IDataReference(org.javarosa.core.model.IDataReference) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) StringData(org.javarosa.core.model.data.StringData) AuditConfig(org.odk.collect.android.formentry.audit.AuditConfig) TreeElement(org.javarosa.core.model.instance.TreeElement)

Aggregations

IDataReference (org.javarosa.core.model.IDataReference)17 XPathReference (org.javarosa.model.xform.XPathReference)7 TreeElement (org.javarosa.core.model.instance.TreeElement)6 DataBinding (org.javarosa.core.model.DataBinding)5 SubmissionProfile (org.javarosa.core.model.SubmissionProfile)5 TreeReference (org.javarosa.core.model.instance.TreeReference)5 IFormElement (org.javarosa.core.model.IFormElement)4 StringData (org.javarosa.core.model.data.StringData)4 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)4 FormDef (org.javarosa.core.model.FormDef)3 GroupDef (org.javarosa.core.model.GroupDef)3 QuestionDef (org.javarosa.core.model.QuestionDef)3 Test (org.junit.Test)3 Element (org.kxml2.kdom.Element)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 IntegerData (org.javarosa.core.model.data.IntegerData)2