Search in sources :

Example 6 with PivotTableReportElement

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

the class DimensionPrunerTest method test.

@Test
public void test() {
    PivotTableReportElement table = new PivotTableReportElement();
    DimensionPruner pruner = new DimensionPruner(eventBus, dispatcher);
    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));
}
Also used : ReportChangeEvent(org.activityinfo.client.page.report.ReportChangeEvent) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) Test(org.junit.Test)

Example 7 with PivotTableReportElement

use of org.activityinfo.shared.report.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, dispatcher);
    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));
}
Also used : ReportChangeEvent(org.activityinfo.client.page.report.ReportChangeEvent) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) Test(org.junit.Test)

Example 8 with PivotTableReportElement

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

the class DummyPivotTableData method Foobar1612Element.

public PivotTableReportElement Foobar1612Element() {
    PivotTableReportElement element = new PivotTableReportElement();
    element.setTitle("Foobar 1612");
    element.setRowDimensions(rowDims);
    element.setColumnDimensions(colDims);
    element.setContent(new PivotContent(table, new ArrayList<FilterDescription>()));
    return element;
}
Also used : PivotContent(org.activityinfo.shared.report.content.PivotContent) ArrayList(java.util.ArrayList) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 9 with PivotTableReportElement

use of org.activityinfo.shared.report.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, null, 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());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) 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) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 10 with PivotTableReportElement

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

the class DummyPivotTableData2 method testElement.

public PivotTableReportElement testElement() {
    PivotTableReportElement element = new PivotTableReportElement();
    element.setTitle("Foobar 1612");
    element.setRowDimensions(rowDims);
    element.setColumnDimensions(colDims);
    element.setContent(new PivotContent(table, new ArrayList<FilterDescription>()));
    return element;
}
Also used : PivotContent(org.activityinfo.shared.report.content.PivotContent) ArrayList(java.util.ArrayList) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

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