Search in sources :

Example 66 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO 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(site1.getIndicatorValue(1), equalTo(1500d));
    assertThat(site2.getId(), equalTo(2));
    assertThat(site2.getLocationName(), equalTo("Penekusu Kivu 2"));
    assertThat(site2.getActivityId(), equalTo(1));
    assertThat(site2.getIndicatorValue(1), equalTo(400d));
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 67 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class LocalSiteCreateTest method createNew.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void createNew() throws CommandException {
    synchronizeFirstTime();
    // create a new detached, client model
    SiteDTO newSite = SiteDTOs.newSite();
    LocationDTO location = LocationDTOs.newLocation();
    executeLocally(new CreateLocation(location));
    newSite.setLocation(location);
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    CreateResult result = executeLocally(cmd);
    // let the client know the command has succeeded
    newSite.setId(result.getNewId());
    // try to retrieve what we've created FROM OUR CLIENT SIDE DATABASE
    SiteResult loadResult = executeLocally(GetSites.byId(newSite.getId()));
    Assert.assertEquals(1, loadResult.getData().size());
    SiteDTO secondRead = loadResult.getData().get(0);
    // confirm that the changes are there
    SiteDTOs.validateNewSite(secondRead);
    newRequest();
    // now Sync with the server
    synchronize();
    // Confirm that paging works client side
    GetSites pagingRequest = new GetSites();
    pagingRequest.setLimit(1);
    loadResult = executeLocally(pagingRequest);
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) SiteDTO(org.activityinfo.shared.dto.SiteDTO) LocationDTO(org.activityinfo.shared.dto.LocationDTO) CreateSite(org.activityinfo.shared.command.CreateSite) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 68 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class TableGeneratorTest method testMap.

// 
// @Test
// public void tableWithMap() {
// 
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
// 
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
// 
// TableElement table = new TableElement();
// table.setMap(map);
// 
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
// 
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
// 
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
// 
// Assert.assertNotNull("content is set", table.getContent());
// 
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
// 
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
    TableElement table = new TableElement();
    table.addColumn(new TableColumn("Index", "map"));
    table.addColumn(new TableColumn("Site", "location.name"));
    MapReportElement map = new MapReportElement();
    map.setBaseMapId("map1");
    CircledMapLayer layer = new BubbleMapLayer();
    layer.setLabelSequence(new ArabicNumberSequence());
    map.addLayer(layer);
    table.setMap(map);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    TileBaseMap baseMap1 = new TileBaseMap();
    baseMap1.setId("map1");
    baseMap1.setMinZoom(0);
    baseMap1.setMaxZoom(12);
    baseMap1.setCopyright("(C)");
    baseMap1.setName("Grand Canyon");
    baseMap1.setTileUrlPattern("http://s/test.png");
    expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
    replay(dispatcher);
    TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
    gtor.generate(user, table, null, null);
    MapContent mapContent = map.getContent();
    Assert.assertNotNull("map content", mapContent);
    Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
    Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
    Map<Integer, String> siteLabels = mapContent.siteLabelMap();
    Assert.assertEquals("site id in map", "1", siteLabels.get(1));
    SiteDTO row = table.getContent().getData().getRows().get(0);
    Assert.assertEquals("label on row", "1", row.get("map"));
}
Also used : ArabicNumberSequence(org.activityinfo.shared.report.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.shared.report.content.MapContent) BaseMapResult(org.activityinfo.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) SiteResult(org.activityinfo.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) CircledMapLayer(org.activityinfo.shared.report.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.shared.dto.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 69 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class TableGeneratorTest method simpleTable.

@Test
public void simpleTable() {
    TableElement table = new TableElement();
    TableColumn column = new TableColumn("Location", "location.name");
    table.addColumn(column);
    TableGenerator gtor = new TableGenerator(createDispatcher(), null);
    gtor.generate(user, table, null, null);
    Assert.assertNotNull("content is set", table.getContent());
    TableData data = table.getContent().getData();
    List<SiteDTO> rows = data.getRows();
    Assert.assertEquals("row count", 1, rows.size());
    SiteDTO row = rows.get(0);
    assertThat((String) row.get(column.getSitePropertyName()), equalTo("tampa bay"));
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) Test(org.junit.Test)

Example 70 with SiteDTO

use of org.activityinfo.shared.dto.SiteDTO in project activityinfo by bedatadriven.

the class CoincidentPointsClusterTest method testSimpleData.

@Test
public void testSimpleData() throws Exception {
    List<PointValue> points = new ArrayList<PointValue>();
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 7.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 2.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 41.0, new Point(100, 100)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 9.0, new Point(0, 0)));
    points.add(new PointValue(new SiteDTO(), new MapSymbol(), 39.0, new Point(100, 100)));
    double originalSum = 7 + 2 + 9 + 41 + 39;
    // Now build the graph
    MarkerGraph graph = new MarkerGraph(points, new BubbleIntersectionCalculator(15));
    GeneticSolver solver = new GeneticSolver();
    List<Cluster> clusters = solver.solve(graph, new GsLogCalculator(5, 15), new BubbleFitnessFunctor(), UpperBoundsCalculator.calculate(graph, new FixedRadiiCalculator(5)));
    // check to make sure all values were included
    double sumAfterClustering = 0;
    for (Cluster cluster : clusters) {
        sumAfterClustering += cluster.sumValues();
    }
    Assert.assertEquals(originalSum, sumAfterClustering, 0.0001);
    Assert.assertEquals(2, clusters.size());
    saveClusters(graph, "clusterTest-solution", clusters);
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.shared.report.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.shared.report.model.MapSymbol) Point(org.activityinfo.shared.report.content.Point) GeneticSolver(org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver) BubbleFitnessFunctor(org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Test(org.junit.Test)

Aggregations

SiteDTO (org.activityinfo.shared.dto.SiteDTO)71 Test (org.junit.Test)32 GetSites (org.activityinfo.shared.command.GetSites)16 SiteResult (org.activityinfo.shared.command.result.SiteResult)11 CreateSite (org.activityinfo.shared.command.CreateSite)9 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)8 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)7 ArrayList (java.util.ArrayList)7 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Date (java.util.Date)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)6 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)5 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)5 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)5 UpdateSite (org.activityinfo.shared.command.UpdateSite)5 LocationDTO (org.activityinfo.shared.dto.LocationDTO)5 PointValue (org.activityinfo.shared.report.model.PointValue)5 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)4