Search in sources :

Example 1 with XForm

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?"));
}
Also used : XForm(org.activityinfo.io.xform.form.XForm) JAXBContext(javax.xml.bind.JAXBContext) XFormReader(org.activityinfo.io.xform.XFormReader) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL) Test(org.junit.Test)

Example 2 with XForm

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();
}
Also used : XForm(org.activityinfo.io.xform.form.XForm) FormClass(org.activityinfo.model.form.FormClass) XFormBuilder(org.activityinfo.server.endpoint.odk.build.XFormBuilder) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 3 with XForm

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Example 4 with XForm

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Example 5 with XForm

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()));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) XForm(org.activityinfo.io.xform.form.XForm) TFormClass(org.activityinfo.model.form.TFormClass) Test(org.junit.Test)

Aggregations

XForm (org.activityinfo.io.xform.form.XForm)5 Test (org.junit.Test)4 TFormClass (org.activityinfo.model.form.TFormClass)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 URL (java.net.URL)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XFormReader (org.activityinfo.io.xform.XFormReader)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 FormClass (org.activityinfo.model.form.FormClass)1 XFormBuilder (org.activityinfo.server.endpoint.odk.build.XFormBuilder)1