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));
}
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");
}
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"));
}
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));
}
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();
}
Aggregations