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