use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class SiteDialog method updateSite.
private void updateSite() {
final SiteDTO updated = new SiteDTO(site);
updateModel(updated);
dispatcher.execute(new UpdateSite(site, updated), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(VoidResult result) {
hide();
callback.onSaved();
}
});
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class UpdateSiteTest method testUpdatePreservesAdminMemberships.
@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
Map<String, Object> changes = Maps.newHashMap();
changes.put("comments", "new comments");
execute(new UpdateSite(1, changes));
// retrieve the old one
SiteResult result = execute(GetSites.byId(1));
SiteDTO secondRead = result.getData().get(0);
assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
use of org.activityinfo.legacy.shared.command.UpdateSite in project activityinfo by bedatadriven.
the class UpdateSiteTest method testUpdate.
@Test
public void testUpdate() throws CommandException {
// retrieve from the server
ListResult<SiteDTO> result = execute(GetSites.byId(1));
SiteDTO original = result.getData().get(0);
SiteDTO modified = original.copy();
assertThat(modified.getId(), equalTo(original.getId()));
// modify and generate command
modified.setComments("NEW <b>Commentaire</b>");
modified.setAttributeValue(1, true);
modified.setAttributeValue(2, null);
modified.setAttributeValue(3, true);
modified.setAttributeValue(4, false);
modified.setIndicatorValue(2, 995.0);
modified.setAdminEntity(2, null);
UpdateSite cmd = new UpdateSite(original, modified);
assertThat((String) cmd.getChanges().get("comments"), equalTo(modified.getComments()));
execute(cmd);
// retrieve the old one
result = execute(GetSites.byId(1));
SiteDTO secondRead = result.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.comments", modified.getComments(), secondRead.getComments());
Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 995, ((Double) secondRead.getIndicatorValue(2)).intValue());
Assert.assertEquals("site.attribute[1]", true, modified.getAttributeValue(1));
Assert.assertEquals("site.attribute[3]", true, modified.getAttributeValue(3));
Assert.assertEquals("site.attribute[4]", false, modified.getAttributeValue(4));
}
Aggregations