Search in sources :

Example 16 with PivotTableReportElement

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

the class ItextReportRendererTest method nestedColumns.

@Test
public void nestedColumns() throws IOException {
    Dimension province = new AdminDimension(1);
    Dimension partner = new Dimension(DimensionType.Partner);
    Dimension year = new DateDimension(DateUnit.YEAR);
    Dimension month = new DateDimension(DateUnit.MONTH);
    EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
    PivotTableData data = new PivotTableData();
    Axis sudKivu = data.getRootColumn().addChild(province, new EntityCategory(1, "Sud Kivu"), "Sud Kivu", comparator);
    Axis y2010 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis y2011 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis jan2010 = y2010.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2010 = y2010.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis jan2011 = y2011.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2011 = y2011.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
    avsiRow.setValue(jan2010, 1d);
    avsiRow.setValue(feb2010, 2d);
    avsiRow.setValue(jan2011, 3d);
    avsiRow.setValue(feb2011, 4d);
    PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
    PivotTableReportElement table = new PivotTableReportElement();
    table.addRowDimension(partner);
    table.addColDimension(province);
    table.addColDimension(year);
    table.addColDimension(month);
    table.setContent(tableContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(table);
    renderToPdf(report, "nestedColumns.pdf");
    renderToRtf(report, "nestedColumns.rtf");
    renderToXls(report, "nestedColumns.xls");
}
Also used : SimpleCategory(org.activityinfo.shared.report.content.SimpleCategory) ReportContent(org.activityinfo.shared.report.content.ReportContent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Report(org.activityinfo.shared.report.model.Report) PivotContent(org.activityinfo.shared.report.content.PivotContent) DateDimension(org.activityinfo.shared.report.model.DateDimension) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension) Axis(org.activityinfo.shared.report.content.PivotTableData.Axis) Test(org.junit.Test)

Example 17 with PivotTableReportElement

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

the class GeneratePivotTableHandlerTest method serverSide.

@Test
public void serverSide() throws CommandException {
    PivotTableReportElement element = new PivotTableReportElement();
    element.setRowDimensions(Arrays.asList(new Dimension(DimensionType.Indicator)));
    element.setColumnDimensions(Arrays.asList(new Dimension(DimensionType.Partner)));
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, Arrays.asList(1, 2, 103));
    element.setFilter(filter);
    execute(new GeneratePivotTable(element));
// TODO real test
// System.out.println(content.getData());
}
Also used : Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) Test(org.junit.Test)

Example 18 with PivotTableReportElement

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

the class ExcelReportRenderer method render.

@Override
public void render(ReportElement element, OutputStream os) throws IOException {
    HSSFWorkbook book = new HSSFWorkbook();
    if (element instanceof Report) {
        render(book, (Report) element);
    } else if (element instanceof PivotTableReportElement) {
        pivotTableRenderer.render(book, (PivotTableReportElement) element);
    } else if (element instanceof TableElement) {
        tableRenderer.render(book, (TableElement) element);
    } else if (element instanceof PivotChartReportElement) {
        chartRenderer.render(book, (PivotChartReportElement) element);
    }
    book.write(os);
}
Also used : Report(org.activityinfo.shared.report.model.Report) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) TableElement(org.activityinfo.shared.report.model.TableElement)

Example 19 with PivotTableReportElement

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

the class PivotTableGeneratorTest method testIndicatorSortOrder.

@Test
public void testIndicatorSortOrder() {
    // test input data: user
    User user = new User();
    user.setLocale("fr");
    // test input data: PivotTableElement
    PivotTableReportElement element = new PivotTableReportElement();
    Dimension indicatorDim = new Dimension(DimensionType.Indicator);
    element.addRowDimension(indicatorDim);
    // test input data: aggregated results
    List<Bucket> buckets = new ArrayList<Bucket>();
    buckets.add(newBucket(300, category(indicatorDim, 1, "Nb. menages", 3)));
    buckets.add(newBucket(400, category(indicatorDim, 2, "Nb. personnes", 1)));
    buckets.add(newBucket(600, category(indicatorDim, 3, "Nb. deplaces", 2)));
    // collaborator : PivotDAO
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
    replay(dispatcher);
    // CLASS UNDER TEST!!
    PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
    generator.generate(user, element, null, null);
    Assert.assertNotNull("element content", element.getContent());
    List<PivotTableData.Axis> rows = element.getContent().getData().getRootRow().getChildren();
    Assert.assertEquals(2, ((EntityCategory) rows.get(0).getCategory()).getId());
    Assert.assertEquals(3, ((EntityCategory) rows.get(1).getCategory()).getId());
    Assert.assertEquals(1, ((EntityCategory) rows.get(2).getCategory()).getId());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 20 with PivotTableReportElement

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

the class JaxbParseTest method testElements.

@Test
public void testElements() throws JAXBException {
    Report report = parseXml("report-elements.xml");
    dumpXml(report);
    Assert.assertEquals("element count", 7, report.getElements().size());
    Assert.assertTrue("pivotTable", report.getElements().get(0) instanceof PivotTableReportElement);
    Assert.assertTrue("pivotChart", report.getElements().get(1) instanceof PivotChartReportElement);
    Assert.assertTrue("table", report.getElements().get(2) instanceof TableElement);
    Assert.assertTrue("map", report.getElements().get(3) instanceof MapReportElement);
    Assert.assertTrue("static", report.getElements().get(4) instanceof TextReportElement);
    Assert.assertTrue("static", report.getElements().get(5) instanceof TextReportElement);
    Assert.assertTrue("static", report.getElements().get(6) instanceof ImageReportElement);
}
Also used : MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ImageReportElement(org.activityinfo.shared.report.model.ImageReportElement) Report(org.activityinfo.shared.report.model.Report) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) TableElement(org.activityinfo.shared.report.model.TableElement) TextReportElement(org.activityinfo.shared.report.model.TextReportElement) Test(org.junit.Test)

Aggregations

PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)23 Test (org.junit.Test)15 Dimension (org.activityinfo.shared.report.model.Dimension)10 Report (org.activityinfo.shared.report.model.Report)7 PivotContent (org.activityinfo.shared.report.content.PivotContent)6 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)5 PivotChartReportElement (org.activityinfo.shared.report.model.PivotChartReportElement)5 ArrayList (java.util.ArrayList)4 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)4 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)4 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)3 ReportContent (org.activityinfo.shared.report.content.ReportContent)3 DateDimension (org.activityinfo.shared.report.model.DateDimension)3 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2