use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.
the class CreateSiteTest method persistSite.
@Test
public void persistSite() {
ResourceId locationClassId = CuidAdapter.locationFormClass(1);
FormInstance location = new FormInstance(CuidAdapter.generateLocationCuid(), locationClassId);
location.set(field(locationClassId, CuidAdapter.NAME_FIELD), "Virunga");
location.set(field(locationClassId, CuidAdapter.AXE_FIELD), "Goma - Rutshuru");
location.set(field(locationClassId, CuidAdapter.GEOMETRY_FIELD), new GeoPoint(27.432, 1.23));
assertResolves(locator.persist(location));
int databaseId = 1;
ResourceId formClassId = CuidAdapter.activityFormClass(1);
FormInstance instance = new FormInstance(CuidAdapter.generateSiteCuid(), formClassId);
instance.set(field(formClassId, LOCATION_FIELD), new ReferenceValue(new RecordRef(locationClassId, location.getId())));
instance.set(field(formClassId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
instance.set(field(formClassId, START_DATE_FIELD), new LocalDate(2008, 12, 1));
instance.set(field(formClassId, END_DATE_FIELD), new LocalDate(2009, 1, 3));
instance.set(indicatorField(1), 996.0);
instance.set(attributeField(1), new EnumValue(CuidAdapter.attributeId(1), CuidAdapter.attributeField(2)));
instance.set(commentsField(1), "objection!");
instance.set(field(formClassId, PROJECT_FIELD), CuidAdapter.projectRef(PROJECT_DOMAIN, 1));
assertResolves(locator.persist(instance));
}
use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method updateLocation.
@Test
public void updateLocation() {
// <location locationId="1" name="Penekusu Kivu" locationTypeId="1"
// X="1.532" Y="27.323" timeEdited="1"/>
// <locationAdminLink locationId="1" adminEntityId="2"/>
// <locationAdminLink locationId="1" adminEntityId="12"/>
FormInstance instance = assertResolves(locator.getFormInstance(HEALTH_CENTER_CLASS, locationInstanceId(1)));
instance.set(field(HEALTH_CENTER_CLASS, NAME_FIELD), "New Penekusu");
assertResolves(locator.persist(instance));
GetLocations query = new GetLocations(1);
LocationResult result = execute(query);
LocationDTO location = result.getData().get(0);
assertThat(location.getName(), equalTo("New Penekusu"));
assertThat(location.getLocationTypeId(), equalTo(1));
assertThat(location.getLatitude(), equalTo(27.323));
assertThat(location.getLongitude(), equalTo(1.532));
// 12 admin level is not returned because we eliminate redundant information org.activityinfo.store.mysql.side.AdminColumnBuilder.emit(int[])
assertThat(location.getAdminEntity(1).getId(), equalTo(2));
}
use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method persistSiteWithCalculatedIndicators.
@Test
@OnDataSet("/dbunit/sites-calculated-indicators.db.xml")
public void persistSiteWithCalculatedIndicators() {
int siteId = new KeyGenerator().generateInt();
FormInstance instance = new FormInstance(CuidAdapter.cuid(SITE_DOMAIN, siteId), NFI_DIST_FORM_CLASS);
instance.set(indicatorField(1), 1);
instance.set(indicatorField(2), 2);
instance.set(locationField(NFI_DIST_ID), locationRef(VILLAGE_CLASS, 1));
instance.set(partnerField(NFI_DIST_ID), partnerRef(PEAR_DATABASE_ID, 1));
instance.set(projectField(NFI_DIST_ID), projectRef(PEAR_DATABASE_ID, 1));
instance.set(field(NFI_DIST_FORM_CLASS, START_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(field(NFI_DIST_FORM_CLASS, END_DATE_FIELD), new LocalDate(2014, 1, 1));
instance.set(field(NFI_DIST_FORM_CLASS, COMMENT_FIELD), NarrativeValue.valueOf("My comment"));
assertResolves(locator.persist(instance));
FormInstance firstRead = assertResolves(locator.getFormInstance(NFI_DIST_FORM_CLASS, instance.getId()));
assertThat(firstRead.get(indicatorField(1)), equalTo((FieldValue) new Quantity(1)));
assertThat(firstRead.get(indicatorField(2)), equalTo((FieldValue) new Quantity(2)));
// set indicators to null
instance.set(indicatorField(1).asString(), null);
instance.set(indicatorField(2).asString(), null);
// persist it
assertResolves(locator.persist(instance));
// read from server
FormInstance secondRead = assertResolves(locator.getFormInstance(NFI_DIST_FORM_CLASS, instance.getId()));
// BENE
assertThat(secondRead.get(indicatorField(1)), nullValue());
// BACHE
assertThat(secondRead.get(indicatorField(2)), nullValue());
// // Both BENE+BACHE and BENE/BACHE should be missing, because both
// // BENE and BACHE are missing
// assertEquals(null, secondRead.getValue(path(indicatorField(11))));
// assertEquals(null, secondRead.getValue(path(indicatorField(12))));
}
use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method getLocation.
@Test
@OnDataSet("/dbunit/jordan-locations.db.xml")
public void getLocation() {
ResourceId classId = locationFormClass(50512);
FormInstance instance = assertResolves(locator.getFormInstance(classId, locationInstanceId(1590565828)));
ReferenceValue adminUnits = (ReferenceValue) instance.get(field(classId, ADMIN_FIELD));
System.out.println(adminUnits);
}
use of org.activityinfo.model.form.FormInstance in project activityinfo by bedatadriven.
the class SitePersisterTest method test.
@Test
public void test() {
FormClass formClass = assertResolves(locator.getFormClass(PEAR_Activity));
FormInstance siteFormInstance = new FormInstance(CuidAdapter.generateSiteCuid(), formClass.getId());
siteFormInstance.set(CONTENU_DI_KIT_FIELD, new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
// built-in values
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.PARTNER_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.partnerFormId(DATABASE_ID), CuidAdapter.partnerRecordId(1))));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.START_DATE_FIELD), new LocalDate(2014, 1, 1));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.END_DATE_FIELD), new LocalDate(2014, 1, 2));
siteFormInstance.set(CuidAdapter.field(formClass.getId(), CuidAdapter.LOCATION_FIELD), new ReferenceValue(new RecordRef(CuidAdapter.locationFormClass(1), CuidAdapter.locationInstanceId(1))));
assertResolves(locator.persist(siteFormInstance));
// query by id
FormInstance fromServer = assertResolves(locator.getFormInstance(siteFormInstance.getFormId(), siteFormInstance.getId()));
Assert.assertNotNull(fromServer);
Assert.assertEquals(fromServer.get(CONTENU_DI_KIT_FIELD), new EnumValue(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
FormTree formTree = assertResolves(locator.getFormTree(formClass.getId()));
final List<FieldPath> paths = Lists.newArrayList(formTree.getRootPaths());
Assert.assertTrue(paths.contains(new FieldPath(CONTENU_DI_KIT_FIELD)));
// query projection
FormInstance instance = assertResolves(locator.getFormInstance(formClass.getId(), siteFormInstance.getId()));
EnumValue fieldValue = (EnumValue) instance.get(CONTENU_DI_KIT_FIELD);
assertThat(fieldValue.getValueId(), equalTo(CONTENU_DI_KIT_FIELD_ATTR_VALUE));
}
Aggregations