Search in sources :

Example 41 with OnDataSet

use of org.activityinfo.server.database.OnDataSet 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 42 with OnDataSet

use of org.activityinfo.server.database.OnDataSet 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)

Example 43 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class GetSitesTest method testGetPublicSites.

@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testGetPublicSites() throws CommandException {
    int anonnoymsUserID = 0;
    setUser(anonnoymsUserID);
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("date2", SortDir.DESC));
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("totalLength", 3, result.getData().size());
    Assert.assertEquals("totalLength", 3, result.getTotalLength());
    Assert.assertEquals("offset", 0, result.getOffset());
    // Assert.assertNull("row(0).activity",
    // result.getData().get(0).getActivity());
    // assure sorted
    Assert.assertEquals("sorted", 2, result.getData().get(0).getId());
    Assert.assertEquals("sorted", 1, result.getData().get(1).getId());
    Assert.assertEquals("sorted", 3, result.getData().get(2).getId());
    // assure indicators are present (site id=3)
    SiteDTO s = result.getData().get(2);
    Assert.assertEquals("entityName", "Ituri", s.getAdminEntity(1).getName());
    Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
    Assert.assertThat("indicator", (Double) s.getIndicatorValue(1), equalTo(10000.0));
    Assert.assertNull("site x", s.getX());
    // assure project is present
    SiteDTO s1 = result.getData().get(1);
    assertThat(s1.getId(), equalTo(1));
    assertThat(s1.getProject().getId(), equalTo(1));
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 44 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class GetSitesTest method linkedSites.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void linkedSites() {
    setUser(1);
    GetSites cmd = new GetSites();
    cmd.filter().addRestriction(DimensionType.Activity, 1);
    cmd.setSortInfo(new SortInfo("locationName", SortDir.ASC));
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(2));
    SiteDTO site1 = result.getData().get(0);
    SiteDTO site2 = result.getData().get(1);
    System.out.println(site1.getProperties());
    System.out.println(site2.getProperties());
    assertThat(site1.getId(), equalTo(1));
    assertThat(site1.getLocationName(), equalTo("Penekusu Kivu"));
    assertThat(site1.getActivityId(), equalTo(1));
    assertThat((Double) site1.getIndicatorValue(1), equalTo(1500d));
    assertThat(site2.getId(), equalTo(2));
    assertThat(site2.getLocationName(), equalTo("Penekusu Kivu 2"));
    assertThat(site2.getActivityId(), equalTo(1));
    assertThat((Double) site2.getIndicatorValue(1), equalTo(400d));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 45 with OnDataSet

use of org.activityinfo.server.database.OnDataSet in project activityinfo by bedatadriven.

the class GetSitesTest method linkedSitesFilteredByIndicator.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void linkedSitesFilteredByIndicator() {
    setUser(1);
    GetSites cmd = new GetSites();
    cmd.filter().addRestriction(DimensionType.Indicator, 1);
    cmd.setSortInfo(new SortInfo("locationName", SortDir.ASC));
    SiteResult result = execute(cmd);
    assertThat(result.getData().size(), equalTo(2));
    SiteDTO site1 = result.getData().get(0);
    SiteDTO site2 = result.getData().get(1);
    System.out.println(site1.getProperties());
    System.out.println(site2.getProperties());
    assertThat(site1.getId(), equalTo(1));
    assertThat(site1.getLocationName(), equalTo("Penekusu Kivu"));
    assertThat(site1.getActivityId(), equalTo(1));
    assertThat((Double) site1.getIndicatorValue(1), equalTo(1500d));
    assertThat(site2.getId(), equalTo(2));
    assertThat(site2.getLocationName(), equalTo("Penekusu Kivu 2"));
    assertThat(site2.getActivityId(), equalTo(1));
    assertThat((Double) site2.getIndicatorValue(1), equalTo(400d));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

OnDataSet (org.activityinfo.server.database.OnDataSet)48 Test (org.junit.Test)46 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)9 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)8 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)6 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)6 EntityManager (javax.persistence.EntityManager)5 GetSites (org.activityinfo.legacy.shared.command.GetSites)5 FormInstance (org.activityinfo.model.form.FormInstance)5 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)4 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 GetSyncRegionUpdates (org.activityinfo.legacy.shared.command.GetSyncRegionUpdates)4 SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)4 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3