use of org.javarosa.core.model.SubmissionProfile in project collect by opendatakit.
the class FormController method getSubmissionDataReference.
/**
* Find the portion of the form that is to be submitted
*/
private IDataReference getSubmissionDataReference() {
FormDef formDef = formEntryController.getModel().getForm();
// Determine the information about the submission...
SubmissionProfile p = formDef.getSubmissionProfile();
if (p == null || p.getRef() == null) {
return new XPathReference("/");
} else {
return p.getRef();
}
}
use of org.javarosa.core.model.SubmissionProfile 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;
boolean audit = false;
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) {
audit = true;
IAnswerData answerData = new StringData();
answerData.setValue(AUDIT_FILE_NAME);
v.get(0).setValue(answerData);
}
}
return new InstanceMetadata(instanceId, instanceName, audit);
}
use of org.javarosa.core.model.SubmissionProfile in project javarosa by opendatakit.
the class SubmissionParserTest method parseSubmission.
@Test
public void parseSubmission() throws Exception {
// Given
final SubmissionParser submissionParser = new SubmissionParser();
final Element element = new Element();
element.setAttribute(null, "mediatype", "application/xml");
element.setAttribute(null, "custom_attribute", "custom value");
final String method = "POST";
final String action = "ACTION";
final IDataReference ref = new DummyReference();
// When
final SubmissionProfile submissionProfile = submissionParser.parseSubmission(method, action, ref, element);
// Then
assertEquals(action, submissionProfile.getAction());
assertEquals(method, submissionProfile.getMethod());
assertEquals(ref, submissionProfile.getRef());
assertEquals("application/xml", submissionProfile.getMediaType());
assertEquals("custom value", submissionProfile.getAttribute("custom_attribute"));
}
use of org.javarosa.core.model.SubmissionProfile in project javarosa by opendatakit.
the class XFormParser method parseSubmission.
private void parseSubmission(Element submission) {
String id = submission.getAttributeValue(null, ID_ATTR);
// These two are always required
String method = submission.getAttributeValue(null, "method");
String action = submission.getAttributeValue(null, "action");
SubmissionParser parser = new SubmissionParser();
for (SubmissionParser p : submissionParsers) {
if (p.matchesCustomMethod(method)) {
parser = p;
}
}
// These two might exist, but if neither do, we just assume you want the entire instance.
String ref = submission.getAttributeValue(null, REF_ATTR);
String bind = submission.getAttributeValue(null, BIND_ATTR);
IDataReference dataRef = null;
boolean refFromBind = false;
if (bind != null) {
DataBinding binding = bindingsByID.get(bind);
if (binding == null) {
throw new XFormParseException("XForm Parse: invalid binding ID in submit'" + bind + "'", submission);
}
dataRef = binding.getReference();
refFromBind = true;
} else if (ref != null) {
dataRef = new XPathReference(ref);
} else {
// no reference! No big deal, assume we want the root reference
dataRef = new XPathReference("/");
}
if (dataRef != null) {
if (!refFromBind) {
dataRef = FormDef.getAbsRef(dataRef, TreeReference.rootRef());
}
}
SubmissionProfile profile = parser.parseSubmission(method, action, dataRef, submission);
if (id == null) {
// default submission profile
_f.setDefaultSubmission(profile);
} else {
// typed submission profile
_f.addSubmissionProfile(id, profile);
}
}
use of org.javarosa.core.model.SubmissionProfile in project collect by opendatakit.
the class FormController method getSubmissionDataReference.
/**
* Find the portion of the form that is to be submitted
*/
private IDataReference getSubmissionDataReference() {
FormDef formDef = formEntryController.getModel().getForm();
// Determine the information about the submission...
SubmissionProfile p = formDef.getSubmissionProfile();
if (p == null || p.getRef() == null) {
return new XPathReference("/");
} else {
return p.getRef();
}
}
Aggregations