use of org.activityinfo.io.xform.form.XForm in project activityinfo by bedatadriven.
the class XFormReaderTest method test.
@Test
public void test() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(XForm.class);
URL formURL = Resources.getResource(XFormReader.class, "survey.xml");
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
XForm xform = (XForm) jaxbUnmarshaller.unmarshal(formURL);
XFormReader reader = new XFormReader(xform);
reader.setDatabaseId(101);
reader.setActivityId(201);
FormClass formClass = reader.build();
dump("", formClass);
FormField veg408 = findField(formClass, "veg408");
assertThat(veg408.getLabel(), equalTo("E.37 In the last seven days did anyone in your household consume any cabbage ?"));
FormField consumption_veg401 = findField(formClass, "v_401/consumption_veg401");
assertThat(consumption_veg401.isVisible(), equalTo(true));
assertThat(consumption_veg401.getLabel(), equalTo("E.30.1.1 why was the previous question left blank?"));
}
use of org.activityinfo.io.xform.form.XForm in project activityinfo by bedatadriven.
the class XFormResources method form.
@GET
@Path("{id}/xform")
@Produces(MediaType.TEXT_XML)
public Response form(@PathParam("id") int id) {
AuthenticatedUser user = authProvider.get();
LOGGER.finer("ODK activity form " + id + " requested by " + user.getEmail() + " (" + user.getId() + ")");
FormClass formClass = fetchFormClass(id);
String authenticationToken = authenticationTokenService.createAuthenticationToken(user.getId(), formClass.getId());
XForm xForm = new XFormBuilder(factory).setUserId(authenticationToken).build(formClass);
return Response.ok(xForm).build();
}
use of org.activityinfo.io.xform.form.XForm in project activityinfo by bedatadriven.
the class XPathBuilderTest method containsAny.
@Test
public void containsAny() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
ResourceId female = formClass.getEnumValueByLabel("Female").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAny({%s},{%s})", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAny({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), male.asString(), female.asString()));
xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s') or selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString(), GENDER_FIELD_ID.asString(), female.asString()));
}
use of org.activityinfo.io.xform.form.XForm in project activityinfo by bedatadriven.
the class XPathBuilderTest method equals.
@Test
public void equals() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("{%s}==\"%s\"", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
}
use of org.activityinfo.io.xform.form.XForm in project activityinfo by bedatadriven.
the class XPathBuilderTest method containsAll.
@Test
public void containsAll() {
TFormClass formClass = createFormClass();
ResourceId male = formClass.getEnumValueByLabel("Male").getId();
ResourceId female = formClass.getEnumValueByLabel("Female").getId();
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAll({%s},{%s})", GENDER_FIELD_ID.asString(), male.asString()));
XForm xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString()));
formClass.getFormClass().getField(GENDER_FIELD_ID).setRelevanceConditionExpression(String.format("containsAll({%s},{%s},{%s})", GENDER_FIELD_ID.asString(), male.asString(), female.asString()));
xForm = xForm(formClass.getFormClass());
assertEquals(bindByFieldId(GENDER_FIELD_ID, xForm).getRelevant(), String.format("selected(/data/field_%s, '%s') and selected(/data/field_%s, '%s')", GENDER_FIELD_ID.asString(), male.asString(), GENDER_FIELD_ID.asString(), female.asString()));
}
Aggregations