Search in sources :

Example 1 with UpdateSite

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

Example 2 with UpdateSite

use of org.activityinfo.shared.command.UpdateSite in project activityinfo by bedatadriven.

the class SyncIntegrationTest method run.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
    synchronizeFirstTime();
    Collector<Date> lastUpdate = Collector.newCollector();
    syncHistoryTable.get(lastUpdate);
    assertThat(lastUpdate.getResult(), is(not(nullValue())));
    assertThat(queryString("select Name from Indicator where IndicatorId=103"), equalTo("Nb. of distributions"));
    assertThat(queryString("select Name from AdminLevel where AdminLevelId=1"), equalTo("Province"));
    assertThat(queryString("select Name from AdminEntity where AdminEntityId=21"), equalTo("Irumu"));
    assertThat(queryString("select Name from Location where LocationId=7"), equalTo("Shabunda"));
    assertThat(queryInt("select value from IndicatorValue where ReportingPeriodId=601 and IndicatorId=6"), equalTo(35));
    assertThat(queryInt("select PartnerId from partnerInDatabase where databaseid=2"), equalTo(1));
    assertThat(queryInt("select AttributeGroupId  from AttributeGroupInActivity where ActivityId=2"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod"), equalTo(4));
    assertThat(queryInt("select count(*) from LockedPeriod where ProjectId is not null"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod where ActivityId is not null"), equalTo(1));
    assertThat(queryInt("select count(*) from LockedPeriod where UserDatabaseId is not null"), equalTo(2));
    // / now try updating a site remotely (from another client)
    // and veryify that we get the update after we synchronized
    Thread.sleep(1000);
    SiteDTO s1 = executeLocally(GetSites.byId(1)).getData().get(0);
    assertThat(s1.getIndicatorValue(1), equalTo(1500d));
    Map<String, Object> changes = Maps.newHashMap();
    changes.put(AttributeDTO.getPropertyName(1), true);
    changes.put("comments", "newComments");
    executeRemotely(new UpdateSite(1, changes));
    synchronize();
    s1 = executeLocally(GetSites.byId(1)).getData().get(0);
    assertThat(s1.getAttributeValue(1), equalTo(true));
    assertThat(s1.getAttributeValue(2), equalTo(false));
    assertThat(s1.getComments(), equalTo("newComments"));
    // old values are preserved...
    assertThat(s1.getIndicatorValue(1), equalTo(1500d));
    // Try deleting a site
    executeRemotely(new Delete("Site", 1));
    synchronize();
    SiteResult siteResult = executeLocally(GetSites.byId(1));
    assertThat(siteResult.getData().size(), equalTo(0));
    // Verify that we haven't toasted the other data
    SiteDTO site = executeLocally(GetSites.byId(3)).getData().get(0);
    assertThat(site.getIndicatorValue(1), equalTo(10000d));
}
Also used : Delete(org.activityinfo.shared.command.Delete) SiteResult(org.activityinfo.shared.command.result.SiteResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 3 with UpdateSite

use of org.activityinfo.shared.command.UpdateSite in project activityinfo by bedatadriven.

the class UpdateSiteTest method charsets.

@Test
public void charsets() 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
    // note that the character sequence below is two characters:
    // the first a simple unicode character and the second a code point
    // requiring 4-bytes.
    // http://www.charbase.com/20731-unicode-cjk-unified-ideograph
    // NOTE: for the moment, i'm rolling back utf8mb4 support becuase it
    // requires
    // Mysql-5.5 which is **PITA*** to get running on earlier versions of
    // ubuntu.
    // To be reapplied when suppport
    // modified.setComments("≥\ud841\udf31");
    modified.setComments("≥");
    System.out.println(modified.getComments());
    assertThat(modified.getComments().codePointCount(0, modified.getComments().length()), equalTo(1));
    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
    assertThat(secondRead.getComments(), equalTo(modified.getComments()));
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Example 4 with UpdateSite

use of org.activityinfo.shared.command.UpdateSite in project activityinfo by bedatadriven.

the class UpdateSiteTest method testUpdatePartner.

@Test
public void testUpdatePartner() throws CommandException {
    // define changes for site id=2
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("partnerId", 2);
    execute(new UpdateSite(2, changes));
    // assure that the change has been effected
    Site site = em.find(Site.class, 2);
    Assert.assertEquals("partnerId", 2, site.getPartner().getId());
}
Also used : Site(org.activityinfo.server.database.hibernate.entity.Site) UpdateSite(org.activityinfo.shared.command.UpdateSite) HashMap(java.util.HashMap) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Example 5 with UpdateSite

use of org.activityinfo.shared.command.UpdateSite in project activityinfo by bedatadriven.

the class CommandQueueTest method testUpdateSite.

@Test
public void testUpdateSite() {
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("anInt", 34);
    changes.put("aString", "testing");
    final UpdateSite cmd = new UpdateSite(99, changes);
    db.transaction(new SqlTransactionCallback() {

        @Override
        public void begin(SqlTransaction tx) {
            queue.queue(tx, cmd);
        }
    });
    Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
    queue.peek(reread);
    assertThat(reread.getResult(), not(nullValue()));
    assertThat(cmd, equalTo(reread.getResult().getCommand()));
}
Also used : SqlTransactionCallback(com.bedatadriven.rebar.sql.client.SqlTransactionCallback) HashMap(java.util.HashMap) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) UpdateSite(org.activityinfo.shared.command.UpdateSite) Test(org.junit.Test)

Aggregations

UpdateSite (org.activityinfo.shared.command.UpdateSite)7 Test (org.junit.Test)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)5 HashMap (java.util.HashMap)2 SiteResult (org.activityinfo.shared.command.result.SiteResult)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 Date (java.util.Date)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Site (org.activityinfo.server.database.hibernate.entity.Site)1 Delete (org.activityinfo.shared.command.Delete)1 VoidResult (org.activityinfo.shared.command.result.VoidResult)1