Search in sources :

Example 11 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class CustomerCalcIndicatorTest method fullPivot.

private PivotSites fullPivot(int activityId) {
    PivotSites pivot = new PivotSites();
    pivot.setDimensions(new Dimension(DimensionType.Indicator));
    pivot.setFilter(Filter.filter().onActivity(activityId));
    List<Bucket> buckets = execute(pivot).getBuckets();
    System.out.println(Joiner.on("\n").join(buckets));
    assertThat(buckets, hasItem(total("Expenditure", 225000)));
    assertThat(buckets, hasItem(total("Expenditure on water programme", 48500)));
    assertThat(buckets, hasItem(total("Value of Initial Cost - Not specified", 24250)));
    assertThat(buckets, hasItem(total("Value of Initial Cost - Cap Hard", 9700)));
    assertThat(buckets, hasItem(total("Value of Initial Cost – Cap Soft", 14550)));
    assertThat(buckets, hasItem(total("Total Value of Initial Cost", 48500)));
    return pivot;
}
Also used : Bucket(org.activityinfo.legacy.shared.command.result.Bucket) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 12 with Dimension

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

Example 13 with Dimension

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

Example 14 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension 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());
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) PivotTableReportElement(org.activityinfo.legacy.shared.reports.model.PivotTableReportElement) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 15 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class CalculatedIndicatorsQuery method querySites.

private void querySites() {
    GetSites sitesQuery = new GetSites(composeSiteFilter());
    sitesQuery.setFetchAdminEntities(query.isPivotedBy(DimensionType.AdminLevel));
    sitesQuery.setFetchAttributes(query.isPivotedBy(DimensionType.AttributeGroup));
    sitesQuery.setFetchAllIndicators(true);
    sitesQuery.setFetchLocation(query.isPivotedBy(DimensionType.Location) || query.isPivotedBy(DimensionType.Site));
    sitesQuery.setFetchPartner(query.isPivotedBy(DimensionType.Partner));
    sitesQuery.setFetchComments(false);
    sitesQuery.setFetchDates(query.isPivotedBy(DimensionType.Date));
    sitesQuery.setFetchLinks(false);
    sitesQuery.setFetchAllReportingPeriods(true);
    sitesQuery.setLimit(-1);
    for (Dimension dim : query.getDimensions()) {
        if (dim.getType() != DimensionType.Indicator) {
            dimAccessors.add(createAccessor(dim));
        }
    }
    queryContext.getExecutionContext().execute(sitesQuery, new AsyncCallback<SiteResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(SiteResult result) {
            try {
                aggregateSites(result);
                callback.onSuccess(null);
            } catch (Throwable caught) {
                callback.onFailure(caught);
            }
        }
    });
}
Also used : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) GetSites(org.activityinfo.legacy.shared.command.GetSites) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Aggregations

Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)26 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)11 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)10 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)9 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)7 Test (org.junit.Test)7 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)6 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)5 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)3 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)3 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2