Search in sources :

Example 16 with Quantity

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));
}
Also used : GeoArea(org.activityinfo.model.type.geo.GeoArea) Quantity(org.activityinfo.model.type.number.Quantity)

Example 17 with Quantity

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))));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocalDate(org.activityinfo.model.type.time.LocalDate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 18 with Quantity

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)));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 19 with Quantity

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)));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 20 with Quantity

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"));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Updater(org.activityinfo.store.query.server.Updater) Quantity(org.activityinfo.model.type.number.Quantity) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Aggregations

Quantity (org.activityinfo.model.type.number.Quantity)23 Test (org.junit.Test)13 FieldValue (org.activityinfo.model.type.FieldValue)9 LocalDate (org.activityinfo.model.type.time.LocalDate)8 FormClass (org.activityinfo.model.form.FormClass)6 ResourceId (org.activityinfo.model.resource.ResourceId)6 QuantityType (org.activityinfo.model.type.number.QuantityType)6 FormField (org.activityinfo.model.form.FormField)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 QueryModel (org.activityinfo.model.query.QueryModel)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)3 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)3 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)3 JsonValue (org.activityinfo.json.JsonValue)2 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)2 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)2 RecordRef (org.activityinfo.model.type.RecordRef)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2