Search in sources :

Example 6 with UpdateSite

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();
        }
    });
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite)

Example 7 with UpdateSite

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));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) Test(org.junit.Test)

Example 8 with UpdateSite

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));
}
Also used : SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) Test(org.junit.Test)

Aggregations

UpdateSite (org.activityinfo.legacy.shared.command.UpdateSite)8 Test (org.junit.Test)6 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)4 HashMap (java.util.HashMap)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 GregorianCalendar (java.util.GregorianCalendar)1 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Site (org.activityinfo.server.database.hibernate.entity.Site)1