Search in sources :

Example 1 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement in project activityinfo by bedatadriven.

the class ReportJsonFactory method serialize.

@Override
public String serialize(Report report) {
    JsonObject jsonReport = new JsonObject();
    // write custom maker
    jsonReport.addProperty("id", report.getId());
    if (report.getTitle() != null) {
        jsonReport.addProperty("title", report.getTitle());
    }
    if (report.getSheetTitle() != null) {
        jsonReport.addProperty("sheetTitle", report.getSheetTitle());
    }
    if (report.getDescription() != null) {
        jsonReport.addProperty("description", report.getDescription());
    }
    if (report.getFileName() != null) {
        jsonReport.addProperty("fileName", report.getFileName());
    }
    jsonReport.add("filter", encodeFilter(report.getFilter()));
    if (report.getElements() != null) {
        List<ReportElement> reportElements = report.getElements();
        JsonArray jsonElements = new JsonArray();
        for (int i = 0; i < reportElements.size(); i++) {
            ReportElement rp = report.getElement(i);
            if (rp instanceof PivotTableReportElement) {
                jsonElements.add(encodePivotTableReportElement((PivotTableReportElement) rp));
            } else if (rp instanceof PivotChartReportElement) {
                jsonElements.add(encodePivotChartReportElement((PivotChartReportElement) rp));
            } else if (rp instanceof MapReportElement) {
                jsonElements.add(encodeMapReportElement((MapReportElement) rp));
            }
        }
        jsonReport.add("elements", jsonElements);
    }
    return jsonReport.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) JsonObject(com.google.gson.JsonObject) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ReportElement(org.activityinfo.shared.report.model.ReportElement) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 2 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement in project activityinfo by bedatadriven.

the class ExcelMapDataExporter method render.

@Override
public void render(ReportElement element, OutputStream stm) throws IOException {
    if (!(element instanceof MapReportElement)) {
        throw new RuntimeException("ExcelMapDataExporter accepts only MapElements");
    }
    MapContent content = ((MapReportElement) element).getContent();
    Workbook book = new HSSFWorkbook();
    Sheet sheet = book.createSheet();
    Helper helper = new Helper(book);
    Row headerRow = sheet.createRow(0);
    helper.addCell(headerRow, 0, "Latitude");
    helper.addCell(headerRow, 1, "Longitude");
    helper.addCell(headerRow, 2, "Value");
    helper.addCell(headerRow, 3, "Color");
    helper.addCell(headerRow, 4, "Icon");
    int rowIndex = 1;
    for (MapMarker marker : content.getMarkers()) {
        Row dataRow = sheet.createRow(rowIndex++);
        helper.addCell(dataRow, 0, marker.getLat());
        helper.addCell(dataRow, 1, marker.getLng());
        if (marker instanceof BubbleMapMarker) {
            BubbleMapMarker bmarker = (BubbleMapMarker) marker;
            helper.addCell(dataRow, 2, bmarker.getValue());
            helper.addCell(dataRow, 3, bmarker.getColor());
        }
        if (marker instanceof IconMapMarker) {
            IconMapMarker imarker = (IconMapMarker) marker;
            if (imarker.getIcon() != null) {
                helper.addCell(dataRow, 4, imarker.getIcon().getName());
            }
        }
    }
    book.write(stm);
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) MapContent(org.activityinfo.shared.report.content.MapContent) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 3 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement in project activityinfo by bedatadriven.

the class PolygonGeneratorTest method basicTest.

@Test
public void basicTest() throws IOException {
    PolygonMapLayer layer = new PolygonMapLayer();
    layer.addIndicatorId(1);
    layer.setAdminLevelId(1383);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    MapContent content = execute(new GenerateElement<MapContent>(map));
    map.setContent(content);
    FileOutputStream fos = new FileOutputStream("target/report-tests/polygon.pdf");
    PdfReportRenderer pdfr = new PdfReportRenderer(TestGeometry.get(), "");
    pdfr.render(map, fos);
    fos.close();
}
Also used : PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) MapContent(org.activityinfo.shared.report.content.MapContent) PdfReportRenderer(org.activityinfo.server.report.renderer.itext.PdfReportRenderer) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 4 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement in project activityinfo by bedatadriven.

the class ItextReportRendererTest method iconTest.

@Test
public void iconTest() throws IOException {
    IconMapMarker marker1 = new IconMapMarker();
    marker1.setIcon(MapIcon.fromEnum(Icon.Default));
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("//www.activityinfo.org/resources/tile/nordkivu.cd/{z}/{x}/{y}.png");
    IconMapLayer layer3 = new IconMapLayer();
    layer3.setIcon(MapIcon.Icon.Default.name());
    layer3.getIndicatorIds().add(101);
    MapContent mapContent = new MapContent();
    mapContent.setFilterDescriptions(Collections.EMPTY_LIST);
    mapContent.setBaseMap(baseMap);
    mapContent.setZoomLevel(8);
    mapContent.setCenter(new Extents(-2.2, -2.1, 28.85, 28.9).center());
    mapContent.setMarkers(Arrays.asList((MapMarker) marker1));
    MapReportElement map = new MapReportElement();
    map.setTitle("My Map");
    map.setContent(mapContent);
    map.addLayer(layer3);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(map);
    renderToPdf(report, "iconMarker.pdf");
    renderToHtml(report, "iconMarker.html");
    renderToRtf(report, "iconMarker.rtf");
    renderToPpt(map, "iconMarker.ppt");
    renderToImage(map, "iconMarker.png");
}
Also used : MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ReportContent(org.activityinfo.shared.report.content.ReportContent) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) Extents(org.activityinfo.shared.util.mapping.Extents) Test(org.junit.Test)

Example 5 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement in project activityinfo by bedatadriven.

the class ItextReportRendererTest method htmlImages.

@Test
public void htmlImages() throws IOException {
    DummyPivotTableData data = new DummyPivotTableData();
    PivotChartContent chartContent = new PivotChartContent();
    chartContent.setData(data.table);
    chartContent.setYMin(0);
    chartContent.setYStep(100);
    chartContent.setFilterDescriptions(Collections.EMPTY_LIST);
    PivotChartReportElement chart = new PivotChartReportElement(Type.Pie);
    chart.setTitle("My Pie Chart");
    chart.setCategoryDimensions(data.colDims);
    chart.setSeriesDimensions(data.rowDims);
    chart.setContent(chartContent);
    PivotContent tableContent = new PivotContent();
    tableContent.setFilterDescriptions(Collections.EMPTY_LIST);
    tableContent.setData(data.table);
    PivotTableReportElement table = new PivotTableReportElement();
    table.setColumnDimensions(data.colDims);
    table.setRowDimensions(data.rowDims);
    table.setTitle("My Table");
    table.setContent(tableContent);
    BubbleMapMarker marker1 = new BubbleMapMarker();
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    marker1.setRadius(25);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("http://mt{s}.aimaps.net/nordkivu.cd/v1/z{z}/{x}x{y}.png");
    MapContent mapContent = new MapContent();
    mapContent.setFilterDescriptions(Collections.EMPTY_LIST);
    mapContent.setBaseMap(baseMap);
    mapContent.setZoomLevel(8);
    mapContent.setCenter(new Extents(-2.2, -2.1, 28.85, 28.9).center());
    mapContent.setMarkers(Arrays.asList((MapMarker) marker1));
    MapReportElement map = new MapReportElement();
    map.setTitle("My Map");
    map.setContent(mapContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(chart);
    report.addElement(table);
    report.addElement(new TextReportElement("Testing 1..2.3.. français"));
    report.addElement(map);
    renderToPdf(report, "piechart.pdf");
    renderToHtml(report, "piechart.html");
    // renderToHtmlUsingWriter(report, "piechart2.html");
    renderToRtf(report, "piechart.rtf");
}
Also used : ReportContent(org.activityinfo.shared.report.content.ReportContent) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) Extents(org.activityinfo.shared.util.mapping.Extents) TextReportElement(org.activityinfo.shared.report.model.TextReportElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) PivotContent(org.activityinfo.shared.report.content.PivotContent) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotChartContent(org.activityinfo.shared.report.content.PivotChartContent) Test(org.junit.Test)

Aggregations

MapReportElement (org.activityinfo.shared.report.model.MapReportElement)23 Test (org.junit.Test)17 MapContent (org.activityinfo.shared.report.content.MapContent)12 Report (org.activityinfo.shared.report.model.Report)8 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)6 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)6 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)5 MapMarker (org.activityinfo.shared.report.content.MapMarker)5 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)5 FileOutputStream (java.io.FileOutputStream)4 PivotChartReportElement (org.activityinfo.shared.report.model.PivotChartReportElement)4 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)3 ReportContent (org.activityinfo.shared.report.content.ReportContent)3 TableElement (org.activityinfo.shared.report.model.TableElement)3 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)3 Extents (org.activityinfo.shared.util.mapping.Extents)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 PdfReportRenderer (org.activityinfo.server.report.renderer.itext.PdfReportRenderer)2 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)2