Search in sources :

Example 1 with AttributeGroupDimension

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

the class DimensionTree method isAttributeDimensionSelected.

private boolean isAttributeDimensionSelected(Dimensions 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.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)

Example 2 with AttributeGroupDimension

use of org.activityinfo.legacy.shared.reports.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, "Location.LocationId", "Location.Name");
        } else if (dimension.getType() == DimensionType.Site) {
            addEntityDimension(dimension, baseTable.getDimensionIdColumn(DimensionType.Site), "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 (dateDim.getUnit() == DateUnit.DAY) {
                String dateAlias = appendDimColumn("date", baseTable.getDateCompleteColumn());
                bundlers.add(new DayBundler(dimension, dateAlias));
            }
        } 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 : 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) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension)

Example 3 with AttributeGroupDimension

use of org.activityinfo.legacy.shared.reports.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, 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 4 with AttributeGroupDimension

use of org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension 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 5 with AttributeGroupDimension

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

the class CalculatedIndicatorsQuery method queryAttributeGroups.

private void queryAttributeGroups() {
    Set<Integer> groupIds = Sets.newHashSet();
    for (Dimension dim : query.getDimensions()) {
        if (dim instanceof AttributeGroupDimension) {
            AttributeGroupDimension groupDim = (AttributeGroupDimension) dim;
            groupIds.add(groupDim.getAttributeGroupId());
        }
    }
    SqlQuery.select().appendColumn("g.attributeGroupId", "groupId").appendColumn("g.name", "groupName").appendColumn("a.attributeId").appendColumn("a.name").appendColumn("a.sortOrder").from(Tables.ATTRIBUTE, "a").leftJoin(Tables.ATTRIBUTE_GROUP, "g").on("a.attributeGroupId=g.attributeGroupId").where("a.attributeGroupId").in(groupIds).execute(queryContext.getExecutionContext().getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            for (SqlResultSetRow row : results.getRows()) {
                int groupId = row.getInt("groupId");
                int attributeId = row.getInt("attributeId");
                int sortOrder = row.getInt("sortOrder");
                String attributeName = row.getString("name");
                attributes.put(groupId, new EntityCategory(attributeId, attributeName, sortOrder));
            }
            querySites();
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) 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) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Aggregations

AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)7 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)5 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)3 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)2 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)2 ReportChangeEvent (org.activityinfo.ui.client.page.report.ReportChangeEvent)2 Test (org.junit.Test)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 HashSet (java.util.HashSet)1 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)1 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)1