Search in sources :

Example 16 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateSiteSetValueToBlank.

@Test
public void updateSiteSetValueToBlank() throws JsonMappingException {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue("BENE", Json.createNull());
    changeObject.setFieldValue("comments", Json.createNull());
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "BENE", "comments");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("BENE"), hasValues(null, 3600, 10000));
    assertThat(column("comments"), hasValues((String) null, null, null));
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) Test(org.junit.Test)

Example 17 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method deleteSiteWithMonthlyReports.

@Test
public void deleteSiteWithMonthlyReports() {
    query(CuidAdapter.reportingPeriodFormClass(3), "_id", "site", CuidAdapter.indicatorField(5).asString());
    assertThat(column("site"), hasValues("s0000000009", "s0000000009", "s0000000009"));
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000009");
    changeObject.setFormId(activityFormClass(3).asString());
    changeObject.setDeleted(true);
    newRequest();
    Updater updater = updater();
    updater.executeChange(changeObject);
    newRequest();
    query(CuidAdapter.reportingPeriodFormClass(3), "_id", "site", CuidAdapter.indicatorField(5).asString());
    assertThat(column("site"), hasValues(new String[0]));
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) Test(org.junit.Test)

Example 18 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateLocation.

@Test
public void updateLocation() throws SQLException {
    ResourceId recordId = CuidAdapter.cuid(LOCATION_DOMAIN, 1);
    ResourceId formId = CuidAdapter.locationFormClass(1);
    RecordUpdate update = new RecordUpdate();
    update.setFormId(formId);
    update.setRecordId(recordId);
    update.setFieldValue(CuidAdapter.field(formId, CuidAdapter.NAME_FIELD), TextValue.valueOf("New Name"));
    Updater updater = updater();
    updater.executeChange(update);
    newRequest();
    FormStorage formStorage = catalog.getForm(formId).get();
    FormRecord record = formStorage.get(recordId).get();
    FormInstance typedRecord = FormInstance.toFormInstance(formStorage.getFormClass(), record);
    GeoPoint point = (GeoPoint) typedRecord.get(CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD));
    assertThat(point, not(nullValue()));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Updater(org.activityinfo.store.query.server.Updater) FormRecord(org.activityinfo.model.form.FormRecord) FormInstance(org.activityinfo.model.form.FormInstance) Test(org.junit.Test)

Example 19 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method deleteSite.

@Test
public void deleteSite() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setDeleted(true);
    Updater updater = updater();
    updater.executeChange(changeObject);
    newRequest();
    query(activityFormClass(1), "_id");
    assertThat(column("_id"), hasValues("s0000000002", "s0000000003"));
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) Test(org.junit.Test)

Aggregations

Updater (org.activityinfo.store.query.server.Updater)19 Test (org.junit.Test)13 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)12 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)11 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)3 ResourceId (org.activityinfo.model.resource.ResourceId)2 FormStorageProvider (org.activityinfo.store.spi.FormStorageProvider)2 JsonValue (org.activityinfo.json.JsonValue)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FormRecord (org.activityinfo.model.form.FormRecord)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 Quantity (org.activityinfo.model.type.number.Quantity)1 HrdSerialNumberProvider (org.activityinfo.store.hrd.HrdSerialNumberProvider)1 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)1 InvalidUpdateException (org.activityinfo.store.query.server.InvalidUpdateException)1