Search in sources :

Example 11 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class SyncIntegrationTest method run.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void run() throws SQLException, InterruptedException {
    synchronize();
    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 ProjectId is null and ActivityId is 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((Double) 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.getIndicatorDoubleValue(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.getIndicatorDoubleValue(1), equalTo(10000d));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Date(java.util.Date) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 12 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO 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()));
}
Also used : SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) Test(org.junit.Test)

Example 13 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class PiechartMapLayerGeneratorTest method testSomething.

@Test
public void testSomething() {
    SiteDTO siteData = new SiteDTO();
    siteData.setId(42);
    siteData.setX(15.0);
    siteData.setY(0.0);
    siteData.setIndicatorValue(1, 50.0);
    siteData.setIndicatorValue(2, 10.0);
    siteData.setIndicatorValue(3, 20.0);
    siteData.setIndicatorValue(4, 40.0);
    PiechartMapLayer pcml = new PiechartMapLayer();
    pcml.setMinRadius(10);
    pcml.setMaxRadius(50);
    pcml.addIndicatorId(1);
    pcml.addIndicatorId(2);
    pcml.addIndicatorId(3);
    pcml.addIndicatorId(4);
    pcml.setClustering(new NoClustering());
    TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(1, new Indicator());
    indicators.put(2, new Indicator());
    indicators.put(3, new Indicator());
    indicators.put(4, new Indicator());
    PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
    gen.setSites(Arrays.asList(siteData));
    MapContent mc = new MapContent();
    gen.generate(map, mc);
    assertThat(mc.getMarkers().size(), equalTo(1));
    assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
Also used : MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) NoClustering(org.activityinfo.legacy.shared.reports.model.clustering.NoClustering) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 14 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class GetSitesTest method testActivityQueryBasic.

@Test
public void testActivityQueryBasic() throws CommandException {
    setUser(DATABASE_OWNER);
    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());
    // try {
    Assert.assertNotNull("admin bounds", s.getAdminEntity(1).getBounds());
    // throw new CommandException("Admin Bounds Location extraction enabled - remove AssertionError catch");
    // } catch (AssertionError err) {
    // Admin Bounds Location extraction disabled until "ST_" functions corrected on QueryEngine
    // Remove try{} catch{} when enabled and I start throwing CommandExceptions
    // }
    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(3));
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 15 with SiteDTO

use of org.activityinfo.legacy.shared.model.SiteDTO in project activityinfo by bedatadriven.

the class GetSitesTest method testAdminEntitySort.

@Test
@OnDataSet("/dbunit/sites-public.db.xml")
public void testAdminEntitySort() throws CommandException {
    setUser(DATABASE_OWNER);
    // level 1 - DESC
    GetSites cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E1", SortDir.DESC));
    PagingLoadResult<SiteDTO> result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 2, "E1"), equalTo("Ituri"));
    // level 1 - ASC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E1", SortDir.ASC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E1"), equalTo("Ituri"));
    assertThat("sorted", adminName(result, 1, "E1"), equalTo("Sud Kivu"));
    assertThat("sorted", adminName(result, 2, "E1"), equalTo("Sud Kivu"));
    // level 2 - DESC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E2", SortDir.DESC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E2"), equalTo("Walungu"));
    assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
    assertThat("sorted", adminName(result, 2, "E2"), equalTo("Irumu"));
    // level 2 - ASC
    cmd = new GetSites();
    cmd.filter().onActivity(1);
    cmd.setSortInfo(new SortInfo("E2", SortDir.ASC));
    result = execute(cmd);
    assertThat("sorted", adminName(result, 0, "E2"), equalTo("Irumu"));
    assertThat("sorted", adminName(result, 1, "E2"), equalTo("Shabunda"));
    assertThat("sorted", adminName(result, 2, "E2"), equalTo("Walungu"));
}
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)

Aggregations

SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)48 Test (org.junit.Test)31 GetSites (org.activityinfo.legacy.shared.command.GetSites)16 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)12 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)9 OnDataSet (org.activityinfo.server.database.OnDataSet)8 Date (java.util.Date)6 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)6 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)5 ArrayList (java.util.ArrayList)4 UpdateSite (org.activityinfo.legacy.shared.command.UpdateSite)4 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)3 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)3 TableData (org.activityinfo.legacy.shared.reports.content.TableData)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 Filter (org.activityinfo.legacy.shared.command.Filter)2 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)2