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