Search in sources :

Example 1 with GetSyncRegionUpdates

use of org.activityinfo.legacy.shared.command.GetSyncRegionUpdates 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 GetSyncRegionUpdates

use of org.activityinfo.legacy.shared.command.GetSyncRegionUpdates 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 3 with GetSyncRegionUpdates

use of org.activityinfo.legacy.shared.command.GetSyncRegionUpdates in project activityinfo by bedatadriven.

the class LocationBuilderTest method sqlBuilding.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void sqlBuilding() throws Exception {
    EntityManager em = emf.createEntityManager();
    int locationType = 3;
    GetSyncRegionUpdates request = new GetSyncRegionUpdates("location/" + locationType, null);
    LocationUpdateBuilder builder = new LocationUpdateBuilder(em);
    SyncRegionUpdate update = builder.build(new User(), request);
    System.out.println("sql: " + update.getSql());
    System.out.println("size: " + update.getSql().length());
    assertThat(update.getSql(), containsString("location"));
    assertThat(update.getSql(), containsString("locationadminlink"));
    assertThat(update.getSql(), containsString("Shabunda"));
    // admin level for Shabunda
    assertThat(update.getSql(), containsString("12,7"));
}
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 GetSyncRegionUpdates

use of org.activityinfo.legacy.shared.command.GetSyncRegionUpdates in project activityinfo by bedatadriven.

the class LocationBuilderTest method locationTypeChange.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void locationTypeChange() throws Exception {
    EntityManager em = emf.createEntityManager();
    User user = em.find(User.class, 1);
    // Update the location type 1
    Map<String, Object> changes = new HashMap<>();
    changes.put("name", "Ishamael");
    em.getTransaction().begin();
    LocationTypePolicy locationTypePolicy = new LocationTypePolicy(em);
    locationTypePolicy.update(user, 1, new PropertyMap(changes));
    em.getTransaction().commit();
    // First update should include this change
    String regionId = "location/" + 1;
    LocationUpdateBuilder builder = new LocationUpdateBuilder(em);
    GetSyncRegionUpdates request = new GetSyncRegionUpdates(regionId, null);
    SyncRegionUpdate update = builder.build(user, request);
    assertThat(update.isComplete(), equalTo(true));
    assertThat(update.getSql(), containsString("Ishamael"));
    // We should be up to date now...
    GetSyncRegionsHandler getSyncRegionsHandler = new GetSyncRegionsHandler(em);
    SyncRegions syncRegions = getSyncRegionsHandler.execute(new GetSyncRegions(), user);
    System.out.println(syncRegions.getList());
    assertThat(syncRegions, hasItem(new SyncRegion(regionId, update.getVersion())));
}
Also used : GetSyncRegionUpdates(org.activityinfo.legacy.shared.command.GetSyncRegionUpdates) User(org.activityinfo.server.database.hibernate.entity.User) HashMap(java.util.HashMap) LocationTypePolicy(org.activityinfo.server.command.handler.crud.LocationTypePolicy) SyncRegions(org.activityinfo.legacy.shared.command.result.SyncRegions) GetSyncRegions(org.activityinfo.legacy.shared.command.GetSyncRegions) GetSyncRegions(org.activityinfo.legacy.shared.command.GetSyncRegions) SyncRegion(org.activityinfo.legacy.shared.command.result.SyncRegion) EntityManager(javax.persistence.EntityManager) PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate) GetSyncRegionsHandler(org.activityinfo.server.command.handler.GetSyncRegionsHandler) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 5 with GetSyncRegionUpdates

use of org.activityinfo.legacy.shared.command.GetSyncRegionUpdates in project activityinfo by bedatadriven.

the class SiteUpdateBuilderTest method subsequentCallsAreUpToDate.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void subsequentCallsAreUpToDate() throws Exception {
    User user = new User();
    user.setId(1);
    // update one of the sites so we have a realistic nano value type stamp
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Site site = em.find(Site.class, 1);
    site.setComments("I'm slightly new");
    site.setDateEdited(new Date());
    em.getTransaction().commit();
    em.close();
    SyncRegionUpdate initialUpdate = builder.get().build(user, new GetSyncRegionUpdates("sites/1", null));
    assertThat(initialUpdate.isComplete(), equalTo(true));
    assertThat(initialUpdate.getSql(), not(nullValue()));
    assertThat(initialUpdate.getSql(), containsString("slightly new"));
    System.out.println(initialUpdate.getSql());
    // nothing has changed!
    SyncRegionUpdate subsequentUpdate = builder.get().build(user, new GetSyncRegionUpdates("sites/1", initialUpdate.getVersion()));
    assertThat(subsequentUpdate.isComplete(), equalTo(true));
    assertThat(subsequentUpdate.getSql(), nullValue());
    assertThat(subsequentUpdate.getVersion(), equalTo(initialUpdate.getVersion()));
}
Also used : Site(org.activityinfo.server.database.hibernate.entity.Site) 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) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

GetSyncRegionUpdates (org.activityinfo.legacy.shared.command.GetSyncRegionUpdates)5 SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)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 Site (org.activityinfo.server.database.hibernate.entity.Site)1