Search in sources :

Example 1 with XFormReader

use of org.activityinfo.io.xform.XFormReader 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 XFormReader

use of org.activityinfo.io.xform.XFormReader in project activityinfo by bedatadriven.

the class DatabaseResource method createFormFromXForm.

@POST
@Path("/forms")
@Consumes("application/xml")
public Response createFormFromXForm(@Context UriInfo uri, XForm xForm) {
    UserDatabaseDTOWithForms schema = getSchema();
    LocationTypeDTO locationType = schema.getCountry().getNullLocationType();
    ActivityFormDTO activityDTO = new ActivityFormDTO();
    activityDTO.setName(xForm.getHead().getTitle());
    activityDTO.set("databaseId", databaseId);
    activityDTO.set("locationTypeId", locationType.getId());
    CreateResult createResult = dispatcher.execute(new CreateEntity(activityDTO));
    int activityId = createResult.getNewId();
    XFormReader builder = new XFormReader(xForm);
    FormClass formClass = builder.build();
    formClass.setId(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(CuidAdapter.databaseId(databaseId));
    MySqlStorageProvider formCatalog = (MySqlStorageProvider) catalog.get();
    formCatalog.createOrUpdateFormSchema(formClass);
    return Response.created(uri.getAbsolutePathBuilder().path(RootResource.class).path("forms").path(formClass.getId().asString()).build()).build();
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) FormClass(org.activityinfo.model.form.FormClass) XFormReader(org.activityinfo.io.xform.XFormReader) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Aggregations

XFormReader (org.activityinfo.io.xform.XFormReader)2 URL (java.net.URL)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XForm (org.activityinfo.io.xform.form.XForm)1 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 FormClass (org.activityinfo.model.form.FormClass)1 MySqlStorageProvider (org.activityinfo.store.mysql.MySqlStorageProvider)1 Test (org.junit.Test)1