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;
}
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));
}
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));
}
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();
}
}
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");
}
}
}
}
Aggregations