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?"));
}
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();
}
Aggregations