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;
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.IDataReference in project javarosa by opendatakit.
the class QuestionDataElementTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
}
use of org.javarosa.core.model.IDataReference in project javarosa by opendatakit.
the class QuestionDataGroupTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
group = new TreeElement(groupName);
}
use of org.javarosa.core.model.IDataReference in project javarosa by opendatakit.
the class QuestionDefTest method newRef.
private IDataReference newRef() {
IDataReference ref = new DummyReference();
ref.setReference("/data");
pf.addClass(DummyReference.class);
return ref;
}
use of org.javarosa.core.model.IDataReference 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"));
}
Aggregations