use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class BoundingBoxFunction method apply.
@Override
public FieldValue apply(List<FieldValue> arguments) {
checkArity(arguments, 1);
GeoArea value = (GeoArea) arguments.get(0);
return new Quantity(apply(value));
}
use of org.activityinfo.model.type.number.Quantity 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.type.number.Quantity in project activityinfo by bedatadriven.
the class UpdaterTest method validQuantity.
@Test
public void validQuantity() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", 41.3);
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class UpdaterTest method parsedQuantity.
@Test
public void parsedQuantity() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = Json.createObject();
fields.put("Q1", "41.3");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.
the class MySqlUpdateTest method testSingleSiteResource.
@Test
public void testSingleSiteResource() throws IOException {
int databaseId = 1;
ResourceId formId = CuidAdapter.activityFormClass(1);
TypedRecordUpdate update = new TypedRecordUpdate();
update.setUserId(userId);
update.setFormId(formId);
update.setRecordId(cuid(SITE_DOMAIN, 1));
update.set(field(formId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 2));
update.set(indicatorField(1), new Quantity(900));
update.set(attributeGroupField(1), new EnumValue(attributeId(CATASTROPHE_NATURELLE_ID)));
Updater updater = updater();
updater.execute(update);
query(CuidAdapter.activityFormClass(1), "_id", "partner", "BENE", "cause");
assertThat(column("_id"), hasValues(cuid(SITE_DOMAIN, 1), cuid(SITE_DOMAIN, 2), cuid(SITE_DOMAIN, 3)));
assertThat(column("partner"), hasValues(partnerRecordId(2), partnerRecordId(1), partnerRecordId(2)));
assertThat(column("BENE"), hasValues(900, 3600, 10000));
assertThat(column("cause"), hasValues("Catastrophe Naturelle", "Deplacement", "Catastrophe Naturelle"));
}
Aggregations