use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.
the class PivotTableBinder method generateElement.
private PivotContent generateElement() {
PivotTableReportElement model = (PivotTableReportElement) getModel();
PivotTableDataBuilder builder = new PivotTableDataBuilder();
PivotTableData data = builder.build(model.getRowDimensions(), model.getColumnDimensions(), cachedResult.getBuckets());
PivotContent content = new PivotContent();
content.setEffectiveFilter(cachedFilter);
content.setData(data);
return content;
}
use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.
the class DimensionPrunerTest method testMergedAttributes.
@Test
public void testMergedAttributes() {
PivotTableReportElement table = new PivotTableReportElement();
DimensionPruner pruner = new DimensionPruner(eventBus, getDispatcher());
pruner.bind(table);
table.getFilter().addRestriction(DimensionType.Indicator, Arrays.asList(NB_MENAGES_INDICATOR_ID, VOUCHER_INDICATOR_ID));
table.addColDimension(new Dimension(DimensionType.Indicator));
eventBus.fireEvent(new ReportChangeEvent(this, table));
AttributeGroupDimension groupDim = new AttributeGroupDimension(NFI_FUNDING_GROUP_ID);
table.addColDimension(groupDim);
eventBus.fireEvent(new ReportChangeEvent(this, table));
// now remove the first indicator and verify that the attribute group
// has NOT been removed, because it shares a name with the other attrib group
table.getFilter().clearRestrictions(DimensionType.Indicator);
table.getFilter().addRestriction(DimensionType.Indicator, VOUCHER_INDICATOR_ID);
eventBus.fireEvent(new ReportChangeEvent(this, table));
assertTrue(table.getColumnDimensions().contains(groupDim));
}
use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.
the class DimensionPrunerTest method test.
//
// @Before
// public void setupData() {
//
// ActivityFormDTO dist = new ActivityFormDTO(1, "Distribution");
// IndicatorDTO nbMenages = new IndicatorDTO();
// nbMenages.setId(NB_MENAGES_INDICATOR_ID);
// nbMenages.setName("Nb Menages");
// dist.getIndicators().add(nbMenages);
//
// AttributeGroupDTO distFunding = new AttributeGroupDTO(NFI_FUNDING_GROUP_ID);
// distFunding.setName("Funding Source");
// dist.getAttributeGroups().add(distFunding);
//
//
// ActivityFormDTO fairs = new ActivityFormDTO(2, "Faire");
//
// AttributeGroupDTO fairFunding = new AttributeGroupDTO(FAIR_FUNDING_GROUP_ID);
// fairFunding.setName("Funding Source");
// fairs.getAttributeGroups().add(fairFunding);
//
// IndicatorDTO voucherValue = new IndicatorDTO();
// voucherValue.setId(VOUCHER_INDICATOR_ID);
// voucherValue.setName("Voucher Value");
// fairs.getIndicators().add(voucherValue);
//
// UserDatabaseDTO nfi = new UserDatabaseDTO(1, "NFI");
// nfi.addActivity(dist);
// nfi.addActivity(fairs);
//
// this.schema = new SchemaDTO();
// schema.getDatabases().add(nfi);
//
// dispatcher.setResult(GetSchema.class, schema);
// }
@Test
public void test() {
PivotTableReportElement table = new PivotTableReportElement();
DimensionPruner pruner = new DimensionPruner(eventBus, getDispatcher());
pruner.bind(table);
table.getFilter().addRestriction(DimensionType.Indicator, NB_MENAGES_INDICATOR_ID);
table.addColDimension(new Dimension(DimensionType.Indicator));
eventBus.fireEvent(new ReportChangeEvent(this, table));
AttributeGroupDimension groupDim = new AttributeGroupDimension(NFI_FUNDING_GROUP_ID);
table.addColDimension(groupDim);
eventBus.fireEvent(new ReportChangeEvent(this, table));
assertTrue(table.getColumnDimensions().contains(groupDim));
// now remove the indicator and verify that the attribute group has been
// removed
table.getFilter().clearRestrictions(DimensionType.Indicator);
eventBus.fireEvent(new ReportChangeEvent(this, table));
assertFalse(table.getColumnDimensions().contains(groupDim));
}
use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.
the class PivotTableRendererTest method test.
@Test
public void test() {
// input test data : element + content
DummyPivotTableData testData = new DummyPivotTableData();
PivotTableReportElement element = testData.Foobar1612Element();
// Destination book
HSSFWorkbook book = new HSSFWorkbook();
// CLASS under test
ExcelPivotTableRenderer renderer = new ExcelPivotTableRenderer();
renderer.render(book, element);
// VERIFY output
Sheet sheet = book.getSheetAt(0);
Assert.assertEquals("title cell", element.getTitle(), sheet.getRow(0).getCell(0).getRichStringCellValue().getString());
Assert.assertEquals("last column header", "Abri", sheet.getRow(4).getCell(5).getRichStringCellValue().getString());
Assert.assertEquals("columns headers indentation", (short) 0, sheet.getRow(4).getCell(3).getCellStyle().getIndention());
// Write output to disk
try {
File outputFile = new File("build/report-tests");
outputFile.mkdirs();
OutputStream out = new FileOutputStream(new File(outputFile, "PivotTableRendererTest.xls"));
book.write(out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.activityinfo.legacy.shared.reports.model.PivotTableReportElement in project activityinfo by bedatadriven.
the class PivotTableGeneratorTest method test2x2.
@Test
public void test2x2() {
// test input data: user
User user = new User();
user.setLocale("fr");
// test input data: PivotTableElement
PivotTableReportElement element = new PivotTableReportElement();
AdminDimension provinceDim = new AdminDimension(1);
element.addRowDimension(provinceDim);
Dimension partnerDim = new Dimension(DimensionType.Partner);
element.addColDimension(partnerDim);
// test input data: aggregated results
List<Bucket> buckets = new ArrayList<Bucket>();
buckets.add(newBucket(433, category(provinceDim, 2, "Sud Kivu"), category(partnerDim, 1, "IRC")));
buckets.add(newBucket(1032, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 2, "Solidarites")));
buckets.add(newBucket(310, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 1, "IRC")));
buckets.add(newBucket(926, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 3, "AVSI")));
// 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, dummyFilter(), null);
Assert.assertNotNull("element content", element.getContent());
PivotTableData data = element.getContent().getData();
Assert.assertEquals("rows", 2, data.getRootRow().getChildCount());
Assert.assertEquals("rows sorted", "Nord Kivu", data.getRootRow().getChildren().get(0).getLabel());
Assert.assertEquals("cols", 3, data.getRootColumn().getChildCount());
}
Aggregations