use of org.javarosa.core.model.IDataReference in project collect by opendatakit.
the class FormController method isLogicalGroup.
/**
* Returns true if the group has an XML `ref` attribute,
* i.e. it's a "logical group".
* <p>
* TODO: Improve this nasty way to recreate what XFormParser#parseGroup does for nodes without a `ref`.
*/
private boolean isLogicalGroup(FormIndex groupIndex) {
TreeReference groupRef = groupIndex.getReference();
TreeReference parentRef = groupRef.getParentRef();
IDataReference absRef = FormDef.getAbsRef(new XPathReference(groupRef), parentRef);
IDataReference bindRef = getCaptionPrompt(groupIndex).getFormElement().getBind();
// If the group's bind is equal to what it would have been set to during parsing, it must not have a ref.
return !absRef.equals(bindRef);
}
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;
AuditConfig auditConfig = null;
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) {
TreeElement auditElement = v.get(0);
String locationPriority = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-priority");
String locationMinInterval = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-min-interval");
String locationMaxAge = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "location-max-age");
boolean isTrackingChangesEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes"));
boolean isIdentifyUserEnabled = Boolean.parseBoolean(auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "identify-user"));
String trackChangesReason = auditElement.getBindAttributeValue(XML_OPENDATAKIT_NAMESPACE, "track-changes-reasons");
auditConfig = new AuditConfig.Builder().setMode(locationPriority).setLocationMinInterval(locationMinInterval).setLocationMaxAge(locationMaxAge).setIsTrackingChangesEnabled(isTrackingChangesEnabled).setIsIdentifyUserEnabled(isIdentifyUserEnabled).setIsTrackChangesReasonEnabled(trackChangesReason != null && trackChangesReason.equals("on-form-edit")).createAuditConfig();
IAnswerData answerData = new StringData();
answerData.setValue(AUDIT_FILE_NAME);
auditElement.setValue(answerData);
}
}
return new InstanceMetadata(instanceId, instanceName, auditConfig);
}
Aggregations