Search in sources :

Example 36 with SiteDTO

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

the class UpdateSiteTest method testUpdate.

@Test
public void testUpdate() 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
    modified.setComments("NEW <b>Commentaire</b>");
    modified.setAttributeValue(1, true);
    modified.setAttributeValue(2, null);
    modified.setAttributeValue(3, true);
    modified.setAttributeValue(4, false);
    modified.setIndicatorValue(2, 995.0);
    modified.setAdminEntity(2, null);
    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
    Assert.assertEquals("site.comments", modified.getComments(), secondRead.getComments());
    Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 995, ((Double) secondRead.getIndicatorValue(2)).intValue());
    Assert.assertEquals("site.attribute[1]", true, modified.getAttributeValue(1));
    Assert.assertEquals("site.attribute[3]", true, modified.getAttributeValue(3));
    Assert.assertEquals("site.attribute[4]", false, modified.getAttributeValue(4));
}
Also used : SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) Test(org.junit.Test)

Example 37 with SiteDTO

use of org.activityinfo.legacy.shared.model.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.legacy.shared.model.SiteDTO) TableData(org.activityinfo.legacy.shared.reports.content.TableData) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) Test(org.junit.Test)

Example 38 with SiteDTO

use of org.activityinfo.legacy.shared.model.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.legacy.shared.reports.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) CircledMapLayer(org.activityinfo.legacy.shared.reports.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 39 with SiteDTO

use of org.activityinfo.legacy.shared.model.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.legacy.shared.reports.model.PointValue) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) MapSymbol(org.activityinfo.legacy.shared.reports.model.MapSymbol) Point(org.activityinfo.legacy.shared.reports.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.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 40 with SiteDTO

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

the class GetSitesTest method testDatabasePaged.

@Test
public void testDatabasePaged() throws CommandException {
    setUser(DATABASE_OWNER);
    GetSites cmd = new GetSites();
    cmd.getFilter().addRestriction(DimensionType.Database, 1);
    cmd.setLimit(2);
    PagingLoadResult<SiteDTO> result = execute(cmd);
    Assert.assertEquals("rows", 2, result.getData().size());
}
Also used : GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) 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