Search in sources :

Example 31 with SiteDTO

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

the class IconLayerGenerator method generate.

@Override
public void generate(TiledMap map, MapContent content) {
    List<PointValue> points = new ArrayList<PointValue>();
    IconRectCalculator rectCalculator = new IconRectCalculator(icon);
    IntersectionCalculator intersectionCalculator = new IntersectionCalculator() {

        @Override
        public boolean intersects(Node a, Node b) {
            return a.getPointValue().getIconRect().intersects(b.getPointValue().getIconRect());
        }
    };
    Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), rectCalculator, intersectionCalculator);
    for (SiteDTO site : sites) {
        if (meetsCriteria(site)) {
            AiLatLng geoPoint = getPoint(site);
            if (geoPoint != null || clusterer.isMapped(site)) {
                Point point = null;
                if (geoPoint != null) {
                    point = map.fromLatLngToPixel(geoPoint);
                }
                points.add(new PointValue(site, point, point == null ? null : rectCalculator.iconRect(point), getValue(site, layer.getIndicatorIds())));
            } else {
                content.getUnmappedSites().add(site.getId());
            }
        }
    }
    List<Cluster> clusters = clusterer.cluster(map, points);
    createMarkersFrom(clusters, map, content);
    IconLayerLegend legend = new IconLayerLegend();
    legend.setDefinition(layer);
    content.addLegend(legend);
}
Also used : PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) Node(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node) ArrayList(java.util.ArrayList) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) Point(org.activityinfo.legacy.shared.reports.content.Point) Clusterer(org.activityinfo.server.report.generator.map.cluster.Clusterer) IntersectionCalculator(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) IconLayerLegend(org.activityinfo.legacy.shared.reports.content.IconLayerLegend)

Example 32 with SiteDTO

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

the class GeoDigestRenderer method renderSites.

private void renderSites(StringBuilder html, DatabaseModel databaseModel, Collection<Integer> siteIds) {
    if (!siteIds.isEmpty()) {
        for (Integer siteId : siteIds) {
            SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
            SiteDTO siteDTO = siteResult.getData().get(0);
            ActivityDTO activityDTO = databaseModel.getModel().getSchemaDTO().getActivityById(siteDTO.getActivityId());
            // Check to see if this activity is visible to the user...
            if (activityDTO != null) {
                List<SiteHistory> histories = findSiteHistory(siteId, databaseModel.getModel().getUserDigest().getFrom());
                for (SiteHistory history : histories) {
                    html.append("<span class='geo-site' style='margin-left:10px;'>&bull; ");
                    html.append(I18N.MESSAGES.geoDigestSiteMsg(history.getUser().getEmail(), history.getUser().getName(), activityDTO.getName(), siteDTO.getLocationName()));
                    Date targetDate = databaseModel.getModel().getUserDigest().getDate();
                    Date creationDate = new Date(history.getTimeCreated());
                    if (DateCalc.isOnToday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateToday(creationDate));
                    } else if (DateCalc.isOnYesterday(targetDate, creationDate)) {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateYesterday(creationDate));
                    } else {
                        html.append(I18N.MESSAGES.geoDigestSiteMsgDateOther(creationDate));
                    }
                    html.append("</span><br>");
                }
            }
        }
    }
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) SiteHistory(org.activityinfo.server.database.hibernate.entity.SiteHistory) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 33 with SiteDTO

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

the class KmlDataServlet method writeDocument.

protected void writeDocument(PrintWriter out, int activityId) throws SAXException, TransformerConfigurationException {
    XmlBuilder xml = new XmlBuilder(new StreamResult(out));
    List<SiteDTO> sites = querySites(activityId);
    xml.startDocument();
    KMLNamespace kml = new KMLNamespace(xml);
    kml.startKml();
    ActivityFormDTO activity = dispatcher.execute(new GetActivityForm(activityId));
    kml.startDocument();
    kml.startStyle().at("id", "noDirectionsStyle");
    kml.startBalloonStyle();
    kml.text("$[description]");
    xml.close();
    xml.close();
    for (SiteDTO pm : sites) {
        if (pm.hasLatLong()) {
            kml.startPlaceMark();
            kml.styleUrl("#noDirectionsStyle");
            kml.name(pm.getLocationName());
            kml.startSnippet();
            xml.cdata(renderSnippet(activity, pm));
            // Snippet
            xml.close();
            kml.startDescription();
            xml.cdata(renderDescription(activity, pm));
            // Description
            xml.close();
            kml.startTimeSpan();
            if (pm.getDate1() != null) {
                kml.begin(pm.getDate1().atMidnightInMyTimezone());
                kml.end(pm.getDate2().atMidnightInMyTimezone());
                // Timespan
                xml.close();
            }
            kml.startPoint();
            kml.coordinates(pm.getLongitude(), pm.getLatitude());
            // Point
            xml.close();
            // Placemark
            xml.close();
        }
    }
    // Document
    xml.close();
    // kml
    xml.close();
    xml.endDocument();
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) XmlBuilder(org.activityinfo.server.endpoint.kml.xml.XmlBuilder) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm)

Example 34 with SiteDTO

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

the class PieMapMarkerTest method testPies.

@Test
public void testPies() {
    Dimension dimension = new Dimension(DimensionType.Indicator);
    dimension.setCategoryColor(101, 255);
    dimension.setCategoryColor(102, 0x00FF00);
    dimension.setCategoryColor(103, 0x0000FF);
    SiteDTO site1 = new SiteDTO();
    site1.setId(1);
    site1.setX(0d);
    site1.setY(0d);
    site1.setIndicatorValue(101, 50d);
    site1.setIndicatorValue(102, 40d);
    site1.setIndicatorValue(103, 10d);
    List<SiteDTO> sites = new ArrayList<SiteDTO>();
    sites.add(site1);
    PiechartMapLayer layer = new PiechartMapLayer();
    layer.addIndicatorId(101);
    layer.addIndicatorId(102);
    layer.addIndicatorId(103);
    // layer.getColorDimensions().add(dimension);
    MapReportElement mapElement = new MapReportElement();
    mapElement.addLayer(layer);
    MapContent content = new MapContent();
    TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(101, new Indicator());
    indicators.put(102, new Indicator());
    indicators.put(103, new Indicator());
    PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
    generator.setSites(sites);
    generator.generate(map, content);
    Assert.assertEquals(1, content.getMarkers().size());
    PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
    Assert.assertEquals(3, marker.getSlices().size());
}
Also used : MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) 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) Test(org.junit.Test)

Example 35 with SiteDTO

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

the class UpdateSiteTest method testUpdatePreservesAdminMemberships.

@Test
public void testUpdatePreservesAdminMemberships() throws CommandException {
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("comments", "new comments");
    execute(new UpdateSite(1, changes));
    // retrieve the old one
    SiteResult result = execute(GetSites.byId(1));
    SiteDTO secondRead = result.getData().get(0);
    assertThat(secondRead.getAdminEntity(1).getId(), equalTo(2));
    assertThat(secondRead.getAdminEntity(2).getId(), equalTo(12));
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) 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