Search in sources :

Example 11 with RecordUpdate

use of org.activityinfo.model.resource.RecordUpdate in project activityinfo by bedatadriven.

the class TestingStorageProvider method addNew.

public RecordUpdate addNew(ResourceId formId) {
    TestingFormStorage form = formMap.get(formId);
    if (form == null) {
        throw new RuntimeException("No such form: " + formId);
    }
    FormInstance newRecord = form.getGenerator().get();
    RecordUpdate update = new RecordUpdate();
    update.setFormId(formId);
    update.setRecordId(newRecord.getRef().getRecordId());
    for (Map.Entry<ResourceId, FieldValue> entry : newRecord.getFieldValueMap().entrySet()) {
        update.setFieldValue(entry.getKey(), entry.getValue());
    }
    return update;
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) ResourceId(org.activityinfo.model.resource.ResourceId) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with RecordUpdate

use of org.activityinfo.model.resource.RecordUpdate in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateSiteWithMultipleProperties.

@Test
public void updateSiteWithMultipleProperties() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue("partner", partnerRecordId(2).asString());
    changeObject.setFieldValue("BENE", 2100);
    changeObject.setFieldValue(attributeGroupField(1).asString(), "Deplacement");
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "partner.label", "BENE", "cause");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("partner.label"), hasValues("Solidarites", "NRC", "Solidarites"));
    assertThat(column("BENE"), hasValues(2100, 3600, 10000));
    assertThat(column("cause"), hasValues("Deplacement", "Deplacement", "Catastrophe Naturelle"));
}
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 13 with RecordUpdate

use of org.activityinfo.model.resource.RecordUpdate in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateSiteWithMultiAttributes.

@Test
public void updateSiteWithMultiAttributes() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue(attributeGroupField(1).asString(), "Deplacement");
    changeObject.setFieldValue(attributeGroupField(2).asString(), "Casserole");
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "cause", "[contenu du kit]");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("cause"), hasValues("Deplacement", "Deplacement", "Catastrophe Naturelle"));
}
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 14 with RecordUpdate

use of org.activityinfo.model.resource.RecordUpdate 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 15 with RecordUpdate

use of org.activityinfo.model.resource.RecordUpdate 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)

Aggregations

RecordUpdate (org.activityinfo.model.resource.RecordUpdate)21 Test (org.junit.Test)14 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)12 Updater (org.activityinfo.store.query.server.Updater)11 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)3 ResourceId (org.activityinfo.model.resource.ResourceId)3 RecordRef (org.activityinfo.model.type.RecordRef)3 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)3 HashMap (java.util.HashMap)2 FormInstance (org.activityinfo.model.form.FormInstance)2 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)2 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)2 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)2 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 JsOverlay (jsinterop.annotations.JsOverlay)1 FieldMapping (org.activityinfo.geoadmin.merge2.view.mapping.FieldMapping)1