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());
}
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());
}
}
}
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;
}
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;
}
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;
}
Aggregations