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