Search in sources :

Example 1 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;
    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 2 with IDataReference

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

the class QuestionDataElementTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData("Answer Value");
    integerData = new IntegerData(4);
    stringReference = new IDataReference() {

        String reference = "stringValue";

        public Object getReference() {
            return reference;
        }

        public void setReference(Object reference) {
            this.reference = (String) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.reference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(reference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    integerReference = new IDataReference() {

        Integer intReference = new Integer(15);

        public Object getReference() {
            return intReference;
        }

        public void setReference(Object reference) {
            this.intReference = (Integer) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.intReference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(intReference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    intElement = new TreeElement("intElement");
    intElement.setValue(integerData);
    stringElement = new TreeElement(stringElementName);
    stringElement.setValue(stringData);
}
Also used : PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) IDataReference(org.javarosa.core.model.IDataReference) DataOutputStream(java.io.DataOutputStream) IntegerData(org.javarosa.core.model.data.IntegerData) IOException(java.io.IOException) StringData(org.javarosa.core.model.data.StringData) DataInputStream(java.io.DataInputStream) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 3 with IDataReference

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

the class QuestionDataGroupTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData("Answer Value");
    integerData = new IntegerData(4);
    stringReference = new IDataReference() {

        String reference = "stringValue";

        public Object getReference() {
            return reference;
        }

        public void setReference(Object reference) {
            this.reference = (String) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.reference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(reference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    integerReference = new IDataReference() {

        Integer intReference = new Integer(15);

        public Object getReference() {
            return intReference;
        }

        public void setReference(Object reference) {
            this.intReference = (Integer) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.intReference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(intReference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    intElement = new TreeElement("intElement");
    intElement.setValue(integerData);
    stringElement = new TreeElement(stringElementName);
    stringElement.setValue(stringData);
    group = new TreeElement(groupName);
}
Also used : PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) IDataReference(org.javarosa.core.model.IDataReference) DataOutputStream(java.io.DataOutputStream) IntegerData(org.javarosa.core.model.data.IntegerData) IOException(java.io.IOException) StringData(org.javarosa.core.model.data.StringData) DataInputStream(java.io.DataInputStream) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 4 with IDataReference

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

the class QuestionDefTest method newRef.

private IDataReference newRef() {
    IDataReference ref = new DummyReference();
    ref.setReference("/data");
    pf.addClass(DummyReference.class);
    return ref;
}
Also used : IDataReference(org.javarosa.core.model.IDataReference)

Example 5 with IDataReference

use of org.javarosa.core.model.IDataReference 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)

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