Search in sources :

Example 1 with StringData

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

the class ExStringWidget method setBinaryData.

/**
 * Allows answer to be set externally in {@link FormEntryActivity}.
 */
@Override
public void setBinaryData(Object answer) {
    StringData stringData = ExternalAppsUtils.asStringData(answer);
    this.answer.setText(stringData == null ? null : stringData.getValue().toString());
}
Also used : StringData(org.javarosa.core.model.data.StringData)

Example 2 with StringData

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

the class ItemsetWidgetTest method getInitialAnswer.

@Override
public StringData getInitialAnswer() {
    int selectedIndex = Math.abs(random.nextInt()) % choices.size();
    String answer = choices.get(Integer.toString(selectedIndex));
    return new StringData(answer);
}
Also used : RandomString(net.bytebuddy.utility.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StringData(org.javarosa.core.model.data.StringData)

Example 3 with StringData

use of org.javarosa.core.model.data.StringData 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 4 with StringData

use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.

the class StringDataTests method testNullData.

public void testNullData() {
    boolean exceptionThrown = false;
    StringData data = new StringData();
    data.setValue(stringA);
    try {
        data.setValue(null);
    } catch (NullPointerException e) {
        exceptionThrown = true;
    }
    assertTrue("StringData failed to throw an exception when setting null data", exceptionThrown);
    assertTrue("StringData overwrote existing value on incorrect input", data.getValue().equals(stringA));
}
Also used : StringData(org.javarosa.core.model.data.StringData)

Example 5 with StringData

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

Aggregations

StringData (org.javarosa.core.model.data.StringData)19 IntegerData (org.javarosa.core.model.data.IntegerData)7 TreeElement (org.javarosa.core.model.instance.TreeElement)6 DateData (org.javarosa.core.model.data.DateData)4 TimeData (org.javarosa.core.model.data.TimeData)4 Date (java.util.Date)3 IDataReference (org.javarosa.core.model.IDataReference)3 DateTimeData (org.javarosa.core.model.data.DateTimeData)3 DecimalData (org.javarosa.core.model.data.DecimalData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 LongData (org.javarosa.core.model.data.LongData)3 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)3 FormInstance (org.javarosa.core.model.instance.FormInstance)3 Test (org.junit.Test)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 RandomString (net.bytebuddy.utility.RandomString)2 FormDef (org.javarosa.core.model.FormDef)2 BooleanData (org.javarosa.core.model.data.BooleanData)2