Search in sources :

Example 1 with AttributeGroupDimension

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

the class DimensionTree method isAttributeDimensionSelected.

private boolean isAttributeDimensionSelected(SchemaDTO schema, List<Dimension> dims, AttributeGroupDimension dim) {
    String name = schema.getAttributeGroupNameSafe(dim.getAttributeGroupId());
    for (Dimension selectedDim : dims) {
        if (selectedDim instanceof AttributeGroupDimension) {
            int selectedId = ((AttributeGroupDimension) selectedDim).getAttributeGroupId();
            String selectedName = schema.getAttributeGroupNameSafe(selectedId);
            if (selectedName.equalsIgnoreCase(name)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension)

Example 2 with AttributeGroupDimension

use of org.activityinfo.shared.report.model.AttributeGroupDimension 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 3 with AttributeGroupDimension

use of org.activityinfo.shared.report.model.AttributeGroupDimension 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 4 with AttributeGroupDimension

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

the class DimensionPruner method pruneModel.

private void pruneModel(SchemaDTO schema) {
    Set<ActivityDTO> activityIds = getSelectedActivities(schema);
    Set<AttributeGroupDimension> dimensions = getSelectedAttributes(schema);
    boolean dirty = false;
    for (AttributeGroupDimension dim : dimensions) {
        if (!isApplicable(schema, activityIds, dim)) {
            LOGGER.fine("Removing attribute group " + dim.getAttributeGroupId());
            model.getRowDimensions().remove(dim);
            model.getColumnDimensions().remove(dim);
            dirty = true;
        }
    }
    if (dirty) {
        reportEventBus.fireChange();
    }
}
Also used : ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension)

Example 5 with AttributeGroupDimension

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

the class PivotQuery method addDimensionBundlers.

private void addDimensionBundlers() {
    /* Now add any other dimensions */
    for (Dimension dimension : dimensions) {
        if (dimension == null) {
            Log.error("NULL dimension provided to pivot query: dimensions = " + dimensions);
        } else if (dimension.getType() == DimensionType.Activity) {
            addOrderedEntityDimension(dimension, "Activity.ActivityId", "Activity.Name", "Activity.SortOrder");
        } else if (dimension.getType() == DimensionType.ActivityCategory) {
            addSimpleDimension(dimension, "Activity.Category");
        } else if (dimension.getType() == DimensionType.Database) {
            addEntityDimension(dimension, "Activity.DatabaseId", "UserDatabase.Name");
        } else if (dimension.getType() == DimensionType.Partner) {
            addEntityDimension(dimension, "Partner.PartnerId", "Partner.Name");
        } else if (dimension.getType() == DimensionType.Project) {
            addEntityDimension(dimension, "Project.ProjectId", "Project.Name");
        } else if (dimension.getType() == DimensionType.Location) {
            addEntityDimension(dimension, "Site.LocationId", "Location.Name");
        } else if (dimension.getType() == DimensionType.Indicator) {
            addOrderedEntityDimension(dimension, "Indicator.IndicatorId", "Indicator.Name", "Indicator.SortOrder");
        } else if (dimension.getType() == DimensionType.IndicatorCategory) {
            addSimpleDimension(dimension, "Indicator.Category");
        } else if (dimension instanceof DateDimension) {
            DateDimension dateDim = (DateDimension) dimension;
            if (dateDim.getUnit() == DateUnit.YEAR) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new YearBundler(dimension, yearAlias));
            } else if (dateDim.getUnit() == DateUnit.MONTH) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                String monthAlias = appendDimColumn("month", dialect.monthFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new MonthBundler(dimension, yearAlias, monthAlias));
            } else if (dateDim.getUnit() == DateUnit.QUARTER) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                String quarterAlias = appendDimColumn("quarter", dialect.quarterFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new QuarterBundler(dimension, yearAlias, quarterAlias));
            } else if (dateDim.getUnit() == DateUnit.WEEK_MON) {
                // http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
                if (dialect.isMySql()) {
                    String weekAlias = appendDimColumn("yearweek", "YEARWEEK(" + baseTable.getDateCompleteColumn() + ", 3)");
                    bundlers.add(new MySqlYearWeekBundler(dimension, weekAlias));
                }
            // TODO: sqlite
            }
        } else if (dimension instanceof AdminDimension) {
            AdminDimension adminDim = (AdminDimension) dimension;
            String tableAlias = "AdminLevel" + adminDim.getLevelId();
            query.from(new StringBuilder(" LEFT JOIN " + "(SELECT L.LocationId, E.AdminEntityId, E.Name " + "FROM locationadminlink L " + "LEFT JOIN adminentity E ON (L.AdminEntityId=E.AdminEntityID) " + "WHERE E.AdminLevelId=").append(adminDim.getLevelId()).append(") AS ").append(tableAlias).append(" ON (").append(baseTable.getDimensionIdColumn(DimensionType.Location)).append(" =").append(tableAlias).append(".LocationId)").toString());
            addEntityDimension(dimension, tableAlias + ".AdminEntityId", tableAlias + ".Name");
        } else if (dimension.getType() == DimensionType.Attribute) {
            addEntityDimension(dimension, "AttributeValue.AttributeId", "Attribute.Name");
        } else if (dimension.getType() == DimensionType.AttributeGroup) {
            if (dimension instanceof AttributeGroupDimension) {
                // specific attributegroup
                defineAttributeDimension((AttributeGroupDimension) dimension);
            } else {
                // pivot on attributegroups
                addEntityDimension(dimension, "Attribute.AttributeGroupId", "AttributeGroup.name");
            }
        }
    }
}
Also used : MonthBundler(org.activityinfo.shared.command.handler.pivot.bundler.MonthBundler) MySqlYearWeekBundler(org.activityinfo.shared.command.handler.pivot.bundler.MySqlYearWeekBundler) QuarterBundler(org.activityinfo.shared.command.handler.pivot.bundler.QuarterBundler) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) YearBundler(org.activityinfo.shared.command.handler.pivot.bundler.YearBundler) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension)

Aggregations

AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)6 Dimension (org.activityinfo.shared.report.model.Dimension)5 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)3 Test (org.junit.Test)3 ReportChangeEvent (org.activityinfo.client.page.report.ReportChangeEvent)2 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)2 MonthBundler (org.activityinfo.shared.command.handler.pivot.bundler.MonthBundler)1 MySqlYearWeekBundler (org.activityinfo.shared.command.handler.pivot.bundler.MySqlYearWeekBundler)1 QuarterBundler (org.activityinfo.shared.command.handler.pivot.bundler.QuarterBundler)1 YearBundler (org.activityinfo.shared.command.handler.pivot.bundler.YearBundler)1 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)1 DateDimension (org.activityinfo.shared.report.model.DateDimension)1