Search in sources :

Example 1 with SubmissionProfile

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

the class FormController method getSubmissionDataReference.

/**
 * Find the portion of the form that is to be submitted
 */
private IDataReference getSubmissionDataReference() {
    FormDef formDef = formEntryController.getModel().getForm();
    // Determine the information about the submission...
    SubmissionProfile p = formDef.getSubmissionProfile();
    if (p == null || p.getRef() == null) {
        return new XPathReference("/");
    } else {
        return p.getRef();
    }
}
Also used : FormDef(org.javarosa.core.model.FormDef) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) XPathReference(org.javarosa.model.xform.XPathReference)

Example 2 with SubmissionProfile

use of org.javarosa.core.model.SubmissionProfile 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;
    boolean audit = false;
    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) {
            audit = true;
            IAnswerData answerData = new StringData();
            answerData.setValue(AUDIT_FILE_NAME);
            v.get(0).setValue(answerData);
        }
    }
    return new InstanceMetadata(instanceId, instanceName, audit);
}
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) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 3 with SubmissionProfile

use of org.javarosa.core.model.SubmissionProfile in project javarosa by opendatakit.

the class SubmissionParserTest method parseSubmission.

@Test
public void parseSubmission() throws Exception {
    // Given
    final SubmissionParser submissionParser = new SubmissionParser();
    final Element element = new Element();
    element.setAttribute(null, "mediatype", "application/xml");
    element.setAttribute(null, "custom_attribute", "custom value");
    final String method = "POST";
    final String action = "ACTION";
    final IDataReference ref = new DummyReference();
    // When
    final SubmissionProfile submissionProfile = submissionParser.parseSubmission(method, action, ref, element);
    // Then
    assertEquals(action, submissionProfile.getAction());
    assertEquals(method, submissionProfile.getMethod());
    assertEquals(ref, submissionProfile.getRef());
    assertEquals("application/xml", submissionProfile.getMediaType());
    assertEquals("custom value", submissionProfile.getAttribute("custom_attribute"));
}
Also used : DummyReference(org.javarosa.core.model.test.DummyReference) IDataReference(org.javarosa.core.model.IDataReference) Element(org.kxml2.kdom.Element) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) Test(org.junit.Test)

Example 4 with SubmissionProfile

use of org.javarosa.core.model.SubmissionProfile in project javarosa by opendatakit.

the class XFormParser method parseSubmission.

private void parseSubmission(Element submission) {
    String id = submission.getAttributeValue(null, ID_ATTR);
    // These two are always required
    String method = submission.getAttributeValue(null, "method");
    String action = submission.getAttributeValue(null, "action");
    SubmissionParser parser = new SubmissionParser();
    for (SubmissionParser p : submissionParsers) {
        if (p.matchesCustomMethod(method)) {
            parser = p;
        }
    }
    // These two might exist, but if neither do, we just assume you want the entire instance.
    String ref = submission.getAttributeValue(null, REF_ATTR);
    String bind = submission.getAttributeValue(null, BIND_ATTR);
    IDataReference dataRef = null;
    boolean refFromBind = false;
    if (bind != null) {
        DataBinding binding = bindingsByID.get(bind);
        if (binding == null) {
            throw new XFormParseException("XForm Parse: invalid binding ID in submit'" + bind + "'", submission);
        }
        dataRef = binding.getReference();
        refFromBind = true;
    } else if (ref != null) {
        dataRef = new XPathReference(ref);
    } else {
        // no reference! No big deal, assume we want the root reference
        dataRef = new XPathReference("/");
    }
    if (dataRef != null) {
        if (!refFromBind) {
            dataRef = FormDef.getAbsRef(dataRef, TreeReference.rootRef());
        }
    }
    SubmissionProfile profile = parser.parseSubmission(method, action, dataRef, submission);
    if (id == null) {
        // default submission profile
        _f.setDefaultSubmission(profile);
    } else {
        // typed submission profile
        _f.addSubmissionProfile(id, profile);
    }
}
Also used : IDataReference(org.javarosa.core.model.IDataReference) DataBinding(org.javarosa.core.model.DataBinding) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) XPathReference(org.javarosa.model.xform.XPathReference)

Example 5 with SubmissionProfile

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

the class FormController method getSubmissionDataReference.

/**
 * Find the portion of the form that is to be submitted
 */
private IDataReference getSubmissionDataReference() {
    FormDef formDef = formEntryController.getModel().getForm();
    // Determine the information about the submission...
    SubmissionProfile p = formDef.getSubmissionProfile();
    if (p == null || p.getRef() == null) {
        return new XPathReference("/");
    } else {
        return p.getRef();
    }
}
Also used : FormDef(org.javarosa.core.model.FormDef) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) XPathReference(org.javarosa.model.xform.XPathReference)

Aggregations

SubmissionProfile (org.javarosa.core.model.SubmissionProfile)8 FormDef (org.javarosa.core.model.FormDef)5 IDataReference (org.javarosa.core.model.IDataReference)5 XPathReference (org.javarosa.model.xform.XPathReference)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 StringData (org.javarosa.core.model.data.StringData)2 TreeElement (org.javarosa.core.model.instance.TreeElement)2 Test (org.junit.Test)2 DataBinding (org.javarosa.core.model.DataBinding)1 FormInstance (org.javarosa.core.model.instance.FormInstance)1 DummyReference (org.javarosa.core.model.test.DummyReference)1 ParseResult (org.javarosa.xform.parse.FormParserHelper.ParseResult)1 Element (org.kxml2.kdom.Element)1 AuditConfig (org.odk.collect.android.formentry.audit.AuditConfig)1 ODKIncompleteSubmissionData (org.opendatakit.aggregate.exception.ODKIncompleteSubmissionData)1