Search in sources :

Example 1 with SyncRegionUpdate

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);
        }
    });
}
Also used : GetSyncRegionUpdates(org.activityinfo.legacy.shared.command.GetSyncRegionUpdates) SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)

Example 2 with SyncRegionUpdate

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

Example 3 with SyncRegionUpdate

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"));
}
Also used : GetSyncRegionUpdates(org.activityinfo.legacy.shared.command.GetSyncRegionUpdates) EntityManager(javax.persistence.EntityManager) User(org.activityinfo.server.database.hibernate.entity.User) SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with SyncRegionUpdate

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;
}
Also used : SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel)

Example 5 with SyncRegionUpdate

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

Aggregations

SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)9 GetSyncRegionUpdates (org.activityinfo.legacy.shared.command.GetSyncRegionUpdates)5 EntityManager (javax.persistence.EntityManager)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 User (org.activityinfo.server.database.hibernate.entity.User)4 Test (org.junit.Test)4 Date (java.util.Date)1 HashMap (java.util.HashMap)1 GetSyncRegions (org.activityinfo.legacy.shared.command.GetSyncRegions)1 SyncRegion (org.activityinfo.legacy.shared.command.result.SyncRegion)1 SyncRegions (org.activityinfo.legacy.shared.command.result.SyncRegions)1 GetSyncRegionsHandler (org.activityinfo.server.command.handler.GetSyncRegionsHandler)1 LocationTypePolicy (org.activityinfo.server.command.handler.crud.LocationTypePolicy)1 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)1 AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)1 Site (org.activityinfo.server.database.hibernate.entity.Site)1