use of org.activityinfo.legacy.shared.command.result.SyncRegionUpdate in project activityinfo by bedatadriven.
the class DownSynchronizer method doUpdate.
private void doUpdate(final SyncRegion region, String localVersion) {
fireStatusEvent(uiConstants.downSyncProgress(), regionIt.percentComplete());
Log.info("Synchronizer: Region " + region.getId() + ": localVersion=" + localVersion);
stats.onRemoteCallStarted();
dispatch.execute(new GetSyncRegionUpdates(region.getId(), localVersion), new AsyncCallback<SyncRegionUpdate>() {
@Override
public void onFailure(Throwable throwable) {
handleException("GetSyncRegionUpdates for region id " + region.getId() + " failed.", throwable);
}
@Override
public void onSuccess(SyncRegionUpdate update) {
stats.onRemoteCallFinished();
persistUpdates(region, update);
}
});
}
use of org.activityinfo.legacy.shared.command.result.SyncRegionUpdate in project activityinfo by bedatadriven.
the class TableDefinitionUpdateBuilder method build.
@Override
public SyncRegionUpdate build(User user, GetSyncRegionUpdates request) throws JSONException {
SyncRegionUpdate update = new SyncRegionUpdate();
update.setComplete(true);
update.setVersion(CURRENT_VERSION);
if (!CURRENT_VERSION.equals(request.getLocalVersion())) {
for (Class schemaClass : tablesToSync) {
builder.createTableIfNotExists(schemaClass);
}
builder.createTableIfNotExists(Site.class);
builder.createTableIfNotExists(ReportingPeriod.class);
builder.executeStatement("create table if not exists AttributeGroupInActivity (ActivityId integer, AttributeGroupId integer)");
builder.executeStatement("create table if not exists PartnerInDatabase (DatabaseId integer, PartnerId int)");
builder.executeStatement("create table if not exists IndicatorLink (SourceIndicatorId integer, DestinationIndicatorId int)");
builder.executeStatement("create index if not exists site_activity on site (ActivityId)");
builder.executeStatement("create table if not exists AttributeValue (SiteId integer, AttributeId integer, Value integer)");
builder.executeStatement("create table if not exists IndicatorValue (ReportingPeriodId integer, IndicatorId integer, " + "Value real, TextValue text, DateValue text, BooleanValue bit)");
builder.executeStatement("create table if not exists sitehistory (id integer, siteid integer, userid integer, " + "timecreated real, initial integer, json text)");
builder.createTableIfNotExists(Location.class);
builder.executeStatement("create table if not exists LocationAdminLink (LocationId integer, AdminEntityId integer)");
builder.executeStatement("CREATE TABLE IF NOT EXISTS target (targetId int, name text, date1 text, date2 text, projectId int, " + "partnerId int, adminEntityId int, databaseId int)");
builder.executeStatement("CREATE TABLE IF NOT EXISTS targetvalue (targetId int, IndicatorId int, value real)");
update.setSql(builder.asJson());
}
return update;
}
use of org.activityinfo.legacy.shared.command.result.SyncRegionUpdate in project activityinfo by bedatadriven.
the class LocationBuilderTest method cutting.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void cutting() throws Exception {
EntityManager em = emf.createEntityManager();
int chunkSize = 2;
LocationUpdateBuilder builder = new LocationUpdateBuilder(em, chunkSize);
GetSyncRegionUpdates request = new GetSyncRegionUpdates("location/" + 1, null);
SyncRegionUpdate update = builder.build(new User(), request);
assertThat(update.isComplete(), equalTo(false));
// first chunk
assertThat(update.getVersion(), equalTo("2"));
assertThat(update.getSql(), containsString("Ngshwe"));
request.setLocalVersion(update.getVersion());
update = builder.build(new User(), request);
assertThat(update.isComplete(), equalTo(true));
// second chunk
assertThat(update.getVersion(), equalTo("3"));
assertThat(update.getSql(), containsString("Boga"));
}
use of org.activityinfo.legacy.shared.command.result.SyncRegionUpdate in project activityinfo by bedatadriven.
the class AdminUpdateBuilder method build.
@Override
public SyncRegionUpdate build(User user, GetSyncRegionUpdates request) throws IOException {
SyncRegionUpdate update = new SyncRegionUpdate();
batch = new SqliteBatchBuilder();
AdminLevel level = em.find(AdminLevel.class, request.getRegionId());
JpaBatchBuilder builder = new JpaBatchBuilder(batch, em);
if (request.getLocalVersionNumber() < LAST_VERSION_NUMBER) {
/*
* This level is out of date, delete all on the client and send all
* from the server
*/
builder.insert(Country.class, "CountryId=" + level.getCountry().getId());
builder.insert(AdminLevel.class, "AdminLevelId=" + level.getId());
builder.delete(AdminEntity.class, "AdminLevelId=" + level.getId());
builder.insert(AdminEntity.class, "AdminLevelId=" + level.getId());
update.setSql(batch.build());
}
update.setComplete(true);
update.setVersion(Integer.toString(LAST_VERSION_NUMBER));
return update;
}
use of org.activityinfo.legacy.shared.command.result.SyncRegionUpdate in project activityinfo by bedatadriven.
the class CountryUpdateBuilder method build.
@Override
public SyncRegionUpdate build(User user, GetSyncRegionUpdates request) throws JSONException, IOException {
int countryId = request.getRegionId();
JpaBatchBuilder batch = new JpaBatchBuilder(new SqliteBatchBuilder(), entityManager);
String inCountry = "countryId = " + countryId;
batch.insert(Country.class, inCountry);
batch.insert(AdminLevel.class, inCountry);
batch.delete(LocationType.class, inCountry);
batch.insert(LocationType.class, inCountry);
SyncRegionUpdate update = new SyncRegionUpdate();
update.setComplete(true);
update.setSql(batch.build());
update.setVersion("1");
return update;
}
Aggregations