Search in sources :

Example 6 with Updater

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

the class MySqlUpdateTest method createSite.

@Test
public void createSite() throws JsonMappingException {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000013");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue("partner", partnerRecordId(1).asString());
    changeObject.setFieldValue("date1", "2015-01-01");
    changeObject.setFieldValue("date2", "2015-01-01");
    changeObject.setFieldValue("BENE", 45000);
    changeObject.setFieldValue("location", locationInstanceId(3).asString());
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "partner.label", "BENE");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003", "s0000000013"));
    assertThat(column("partner.label"), hasValues("NRC", "NRC", "Solidarites", "NRC"));
    assertThat(column("BENE"), hasValues(1500, 3600, 10000, 45000));
}
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 7 with Updater

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

the class MySqlUpdateTest method creatingActivitiesWithNullaryLocations.

@Test
public void creatingActivitiesWithNullaryLocations() {
    int newId = new KeyGenerator().generateInt();
    RecordUpdate change = new RecordUpdate();
    change.setRecordId(cuid(SITE_DOMAIN, newId).asString());
    change.setFormId(activityFormClass(ADVOCACY).asString());
    change.setFieldValue("partner", partnerRecordId(1).asString());
    change.setFieldValue("date1", "2015-01-01");
    change.setFieldValue("date2", "2015-01-31");
    Updater updater = updater();
    updater.executeChange(change);
    query(activityFormClass(ADVOCACY), "_id", "partner");
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 8 with Updater

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

the class MySqlUpdateTest method deleteAdminEntity.

@Test
public void deleteAdminEntity() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId(entity(21).asString());
    changeObject.setFormId(adminLevelFormClass(2).asString());
    changeObject.setDeleted(true);
    Updater updater = updater();
    updater.setEnforcePermissions(false);
    updater.executeChange(changeObject);
    query(adminLevelFormClass(2), "_id", "name");
    assertThat(column("name"), hasValues("Bukavu", "Walungu", "Shabunda", "Kalehe"));
}
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 9 with Updater

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

the class MySqlUpdateTest method updateSite.

@Test
public void updateSite() throws JsonMappingException {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue("partner", partnerRecordId(2).asString());
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "partner.label", "BENE");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("partner.label"), hasValues("Solidarites", "NRC", "Solidarites"));
    assertThat(column("BENE"), hasValues(1500, 3600, 10000));
}
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 10 with Updater

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

the class RootResource method update.

@POST
@Path("/update")
@Consumes(MediaType.APPLICATION_JSON)
public Response update(String json) {
    final JsonValue jsonElement = Json.parse(json);
    Updater updater = backend.newUpdater();
    try {
        updater.execute(jsonElement);
    } catch (InvalidUpdateException e) {
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
    }
    return Response.ok().build();
}
Also used : Updater(org.activityinfo.store.query.server.Updater) JsonValue(org.activityinfo.json.JsonValue) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException)

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