use of org.javarosa.core.model.FormDef 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);
}
use of org.javarosa.core.model.FormDef in project collect by opendatakit.
the class FileUtils method getMetadataFromFormDefinition.
/**
* Given a form definition file, return a map containing form metadata. The form ID is required
* by the specification and will always be included. Title and version are optionally included.
* If the form definition contains a submission block, any or all of submission URI, base 64 RSA
* public key, auto-delete and auto-send may be included.
*/
public static HashMap<String, String> getMetadataFromFormDefinition(File formDefinitionXml) {
FormDef formDef = XFormUtils.getFormFromFormXml(formDefinitionXml.getAbsolutePath(), "jr://file/" + LAST_SAVED_FILENAME);
final HashMap<String, String> fields = new HashMap<>();
fields.put(TITLE, formDef.getTitle());
fields.put(FORMID, formDef.getMainInstance().getRoot().getAttributeValue(null, "id"));
String version = formDef.getMainInstance().getRoot().getAttributeValue(null, "version");
if (version != null && StringUtils.isBlank(version)) {
version = null;
}
fields.put(VERSION, version);
if (formDef.getSubmissionProfile() != null) {
fields.put(SUBMISSIONURI, formDef.getSubmissionProfile().getAction());
final String key = formDef.getSubmissionProfile().getAttribute("base64RsaPublicKey");
if (key != null && key.trim().length() > 0) {
fields.put(BASE64_RSA_PUBLIC_KEY, key.trim());
}
fields.put(AUTO_DELETE, formDef.getSubmissionProfile().getAttribute("auto-delete"));
fields.put(AUTO_SEND, formDef.getSubmissionProfile().getAttribute("auto-send"));
}
fields.put(GEOMETRY_XPATH, getOverallFirstGeoPoint(formDef));
return fields;
}
use of org.javarosa.core.model.FormDef in project collect by opendatakit.
the class FormEntryViewModel method canAddRepeat.
public boolean canAddRepeat() {
if (formController != null && formController.indexContainsRepeatableGroup()) {
FormDef formDef = formController.getFormDef();
FormIndex repeatGroupIndex = getRepeatGroupIndex(formController.getFormIndex(), formDef);
return !((GroupDef) formDef.getChild(repeatGroupIndex)).noAddRemove;
} else {
return false;
}
}
use of org.javarosa.core.model.FormDef in project collect by opendatakit.
the class FormLoaderTask method createFormDefFromCacheOrXml.
private FormDef createFormDefFromCacheOrXml(String formPath, File formXml) {
publishProgress(getLocalizedString(Collect.getInstance(), R.string.survey_loading_reading_form_message));
final FormDef formDefFromCache = FormDefCache.readCache(formXml);
if (formDefFromCache != null) {
return formDefFromCache;
}
// no binary, read from xml
Timber.i("Attempting to load from: %s", formXml.getAbsolutePath());
final long start = System.currentTimeMillis();
String lastSavedSrc = FileUtils.getOrCreateLastSavedSrc(formXml);
FormDef formDefFromXml = XFormUtils.getFormFromFormXml(formPath, lastSavedSrc);
if (formDefFromXml == null) {
Timber.w("Error reading XForm file");
errorMsg = "Error reading XForm file";
} else {
Timber.i("Loaded in %.3f seconds.", (System.currentTimeMillis() - start) / 1000F);
formDef = formDefFromXml;
try {
FormDefCache.writeCache(formDef, formXml.getPath());
} catch (IOException e) {
Timber.e(e);
}
return formDefFromXml;
}
return null;
}
Aggregations