Search in sources :

Example 6 with TypedRecordUpdate

use of org.activityinfo.store.spi.TypedRecordUpdate 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

TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)6 Test (org.junit.Test)6 FormClass (org.activityinfo.model.form.FormClass)5 FormField (org.activityinfo.model.form.FormField)5 JsonValue (org.activityinfo.json.JsonValue)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 Quantity (org.activityinfo.model.type.number.Quantity)4 QuantityType (org.activityinfo.model.type.number.QuantityType)4 FieldValue (org.activityinfo.model.type.FieldValue)3 FormInstance (org.activityinfo.model.form.FormInstance)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 SerialNumber (org.activityinfo.model.type.SerialNumber)1 SerialNumberType (org.activityinfo.model.type.SerialNumberType)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)1 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)1 Updater (org.activityinfo.store.query.server.Updater)1