use of org.javarosa.core.model.instance.TreeElement in project collect by opendatakit.
the class InstanceGoogleSheetsUploader method insertRows.
private void insertRows(TreeElement element, String parentKey, String key, File instanceFile, String sheetTitle) throws UploadException {
insertRow(element, parentKey, key, instanceFile, sheetTitle);
int repeatIndex = 0;
for (int i = 0; i < element.getNumChildren(); i++) {
TreeElement child = element.getChildAt(i);
if (child.isRepeatable() && child.getMultiplicity() != TreeReference.INDEX_TEMPLATE) {
insertRows(child, key, getKeyBasedOnParentKey(key, child.getName(), repeatIndex++), instanceFile, getElementTitle(child));
}
if (child.getMultiplicity() == TreeReference.INDEX_TEMPLATE) {
repeatIndex = 0;
}
}
}
use of org.javarosa.core.model.instance.TreeElement in project collect by opendatakit.
the class InstanceGoogleSheetsUploader method getChildElements.
private List<TreeElement> getChildElements(TreeElement element) {
List<TreeElement> elements = new ArrayList<>();
TreeElement prior = null;
for (int i = 0; i < element.getNumChildren(); ++i) {
TreeElement current = element.getChildAt(i);
// avoid duplicated elements https://github.com/opendatakit/javarosa/issues/248
if ((prior != null) && (prior.getName().equals(current.getName()))) {
prior = current;
} else {
switch(current.getDataType()) {
case org.javarosa.core.model.Constants.DATATYPE_TEXT:
case org.javarosa.core.model.Constants.DATATYPE_INTEGER:
case org.javarosa.core.model.Constants.DATATYPE_DECIMAL:
case org.javarosa.core.model.Constants.DATATYPE_DATE:
case org.javarosa.core.model.Constants.DATATYPE_TIME:
case org.javarosa.core.model.Constants.DATATYPE_DATE_TIME:
case org.javarosa.core.model.Constants.DATATYPE_CHOICE:
case org.javarosa.core.model.Constants.DATATYPE_CHOICE_LIST:
case org.javarosa.core.model.Constants.DATATYPE_BOOLEAN:
case org.javarosa.core.model.Constants.DATATYPE_GEOPOINT:
case org.javarosa.core.model.Constants.DATATYPE_BARCODE:
case org.javarosa.core.model.Constants.DATATYPE_BINARY:
case org.javarosa.core.model.Constants.DATATYPE_LONG:
case org.javarosa.core.model.Constants.DATATYPE_GEOSHAPE:
case org.javarosa.core.model.Constants.DATATYPE_GEOTRACE:
case org.javarosa.core.model.Constants.DATATYPE_UNSUPPORTED:
elements.add(current);
break;
case org.javarosa.core.model.Constants.DATATYPE_NULL:
if (current.isRepeatable()) {
// repeat group
elements.add(current);
} else if (current.getNumChildren() == 0) {
// assume fields that don't have children are string fields
elements.add(current);
} else {
// one or more children - this is a group
elements.addAll(getChildElements(current));
}
break;
}
prior = current;
}
}
return elements;
}
use of org.javarosa.core.model.instance.TreeElement in project briefcase by opendatakit.
the class ExportToCsv method populateRepeatGroupsIntoFileMap.
private void populateRepeatGroupsIntoFileMap(TreeElement primarySet, TreeElement treeElement) throws IOException {
// OK -- group with at least one element -- assume no value...
// TreeElement list has the begin and end tags for the nested groups.
// Swallow the end tag by looking to see if the prior and current
// field names are the same.
TreeElement prior = null;
for (int i = 0; i < treeElement.getNumChildren(); ++i) {
TreeElement current = (TreeElement) treeElement.getChildAt(i);
if ((prior != null) && (prior.getName().equals(current.getName()))) {
// it is the end-group tag... seems to happen with two adjacent repeat
// groups
log.info("repeating tag at " + i + " skipping " + current.getName());
prior = current;
} else {
switch(current.getDataType()) {
default:
break;
case org.javarosa.core.model.Constants.DATATYPE_NULL:
/* for nodes that have no data, or data type otherwise unknown */
if (current.isRepeatable()) {
processRepeatingGroupDefinition(current, primarySet, false);
} else if (current.getNumChildren() == 0 && current != briefcaseLfd.getSubmissionElement()) {
// ignore - string type
} else {
/* one or more children -- this is a non-repeating group */
populateRepeatGroupsIntoFileMap(primarySet, current);
}
break;
}
prior = current;
}
}
}
use of org.javarosa.core.model.instance.TreeElement in project briefcase by opendatakit.
the class ExportToCsv method emitRepeatingGroupCsv.
private void emitRepeatingGroupCsv(EncryptionInformation ei, List<Element> groupElementList, TreeElement group, String uniqueParentPath, String uniqueGroupPath, File instanceDir) throws IOException {
OutputStreamWriter osw = fileMap.get(group);
int trueOrdinal = 1;
for (Element groupElement : groupElementList) {
String uniqueGroupInstancePath = uniqueGroupPath + "[" + trueOrdinal + "]";
boolean first = true;
first = emitSubmissionCsv(osw, ei, groupElement, group, group, first, uniqueGroupInstancePath, instanceDir);
emitString(osw, first, uniqueParentPath);
emitString(osw, false, uniqueGroupInstancePath);
emitString(osw, false, uniqueGroupPath);
osw.append("\n");
++trueOrdinal;
}
}
use of org.javarosa.core.model.instance.TreeElement in project javarosa by opendatakit.
the class XFormParser method restoreDataModel.
public static FormInstance restoreDataModel(Document doc, Class restorableType) {
Restorable r = (restorableType != null ? (Restorable) PrototypeFactory.getInstance(restorableType) : null);
Element e = doc.getRootElement();
TreeElement te = buildInstanceStructure(e, null, buildNamespacesMap(e), null);
FormInstance dm = new FormInstance(te);
loadNamespaces(e, dm);
if (r != null) {
RestoreUtils.templateData(r, dm, null);
}
loadInstanceData(e, te, null);
return dm;
}
Aggregations