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");
}
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());
}
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);
}
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());
}
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);
}
Aggregations