Search in sources :

Example 1 with FormInstance

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

the class FormController method getSubmissionXml.

/**
 * Extract the portion of the form that should be uploaded to the server.
 */
public ByteArrayPayload getSubmissionXml() throws IOException {
    FormInstance instance = getInstance();
    XFormSerializingVisitor serializer = new XFormSerializingVisitor();
    return (ByteArrayPayload) serializer.createSerializedPayload(instance, getSubmissionDataReference());
}
Also used : ByteArrayPayload(org.javarosa.core.services.transport.payload.ByteArrayPayload) XFormSerializingVisitor(org.javarosa.model.xform.XFormSerializingVisitor) FormInstance(org.javarosa.core.model.instance.FormInstance)

Example 2 with FormInstance

use of org.javarosa.core.model.instance.FormInstance in project javarosa by opendatakit.

the class RestoreUtils method importRMS.

public static void importRMS(FormInstance dm, IStorageUtility storage, Class type, String path) {
    if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) {
        return;
    }
    boolean idMatters = Persistable.class.isAssignableFrom(type);
    String childName = ((Restorable) PrototypeFactory.getInstance(type)).getRestorableType();
    TreeElement e = dm.resolveReference(absRef(path, dm));
    List<TreeElement> children = e.getChildrenWithName(childName);
    for (int i = 0; i < children.size(); i++) {
        FormInstance child = subDataModel(children.get(i));
        Restorable inst = (Restorable) PrototypeFactory.getInstance(type);
        // restore record id first so 'importData' has access to it
        int recID = -1;
        if (idMatters) {
            recID = ((Integer) getValue(RECORD_ID_TAG, child)).intValue();
            ((Persistable) inst).setID(recID);
        }
        inst.importData(child);
        try {
            if (idMatters) {
                storage.write((Persistable) inst);
            } else {
                storage.add((Externalizable) inst);
            }
        } catch (Exception ex) {
            throw new RuntimeException("Error importing RMS during restore! [" + type.getName() + ":" + recID + "]; " + ex.getMessage());
        }
    }
}
Also used : Persistable(org.javarosa.core.services.storage.Persistable) FormInstance(org.javarosa.core.model.instance.FormInstance) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 3 with FormInstance

use of org.javarosa.core.model.instance.FormInstance in project javarosa by opendatakit.

the class RestoreUtils method newDataModel.

private static FormInstance newDataModel(String topTag) {
    FormInstance dm = new FormInstance();
    dm.addNode(ref("/" + topTag));
    return dm;
}
Also used : FormInstance(org.javarosa.core.model.instance.FormInstance)

Example 4 with FormInstance

use of org.javarosa.core.model.instance.FormInstance in project javarosa by opendatakit.

the class RestoreUtils method exportRMS.

public static FormInstance exportRMS(IStorageUtility storage, Class type, String parentTag, IRecordFilter filter) {
    if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) {
        return null;
    }
    FormInstance dm = newDataModel(parentTag);
    IStorageIterator ri = storage.iterate();
    while (ri.hasMore()) {
        Object obj = ri.nextRecord();
        if (filter == null || filter.filter(obj)) {
            FormInstance objModel = ((Restorable) obj).exportData();
            mergeDataModel(dm, objModel, topRef(dm));
        }
    }
    return dm;
}
Also used : IStorageIterator(org.javarosa.core.services.storage.IStorageIterator) FormInstance(org.javarosa.core.model.instance.FormInstance)

Example 5 with FormInstance

use of org.javarosa.core.model.instance.FormInstance in project javarosa by opendatakit.

the class RestoreUtils method createRootDataModel.

public static FormInstance createRootDataModel(Restorable r) {
    FormInstance inst = createDataModel(r);
    inst.schema = "http://openrosa.org/backup";
    addData(inst, "timestamp", new Date(), Constants.DATATYPE_DATE_TIME);
    return inst;
}
Also used : FormInstance(org.javarosa.core.model.instance.FormInstance) Date(java.util.Date)

Aggregations

FormInstance (org.javarosa.core.model.instance.FormInstance)32 TreeElement (org.javarosa.core.model.instance.TreeElement)16 TreeReference (org.javarosa.core.model.instance.TreeReference)8 Test (org.junit.Test)7 InstanceInitializationFactory (org.javarosa.core.model.instance.InstanceInitializationFactory)6 FormDef (org.javarosa.core.model.FormDef)5 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)5 IOException (java.io.IOException)4 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)3 StringData (org.javarosa.core.model.data.StringData)3 ByteArrayPayload (org.javarosa.core.services.transport.payload.ByteArrayPayload)3 XFormSerializingVisitor (org.javarosa.model.xform.XFormSerializingVisitor)3 XPathNodeset (org.javarosa.xpath.XPathNodeset)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 IFormElement (org.javarosa.core.model.IFormElement)2 ITreeVisitor (org.javarosa.core.model.instance.utils.ITreeVisitor)2 XPathTypeMismatchException (org.javarosa.xpath.XPathTypeMismatchException)2 XPathUnhandledException (org.javarosa.xpath.XPathUnhandledException)2 Cursor (android.database.Cursor)1