use of org.activityinfo.shared.report.model.AdminDimension in project activityinfo by bedatadriven.
the class ItextReportRendererTest method nestedColumns.
@Test
public void nestedColumns() throws IOException {
Dimension province = new AdminDimension(1);
Dimension partner = new Dimension(DimensionType.Partner);
Dimension year = new DateDimension(DateUnit.YEAR);
Dimension month = new DateDimension(DateUnit.MONTH);
EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
PivotTableData data = new PivotTableData();
Axis sudKivu = data.getRootColumn().addChild(province, new EntityCategory(1, "Sud Kivu"), "Sud Kivu", comparator);
Axis y2010 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
Axis y2011 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
Axis jan2010 = y2010.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
Axis feb2010 = y2010.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
Axis jan2011 = y2011.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
Axis feb2011 = y2011.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
avsiRow.setValue(jan2010, 1d);
avsiRow.setValue(feb2010, 2d);
avsiRow.setValue(jan2011, 3d);
avsiRow.setValue(feb2011, 4d);
PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
PivotTableReportElement table = new PivotTableReportElement();
table.addRowDimension(partner);
table.addColDimension(province);
table.addColDimension(year);
table.addColDimension(month);
table.setContent(tableContent);
ReportContent content = new ReportContent();
content.setFilterDescriptions(Collections.EMPTY_LIST);
Report report = new Report();
report.setContent(content);
report.addElement(table);
renderToPdf(report, "nestedColumns.pdf");
renderToRtf(report, "nestedColumns.rtf");
renderToXls(report, "nestedColumns.xls");
}
use of org.activityinfo.shared.report.model.AdminDimension in project activityinfo by bedatadriven.
the class PivotSitesHandlerLocalTest method init.
@Before
public void init() throws Exception {
dimensions = new HashSet<Dimension>();
filter = new Filter();
provinceDim = new AdminDimension(OWNER_USER_ID);
territoireDim = new AdminDimension(2);
synchronizeFirstTime();
}
use of org.activityinfo.shared.report.model.AdminDimension in project activityinfo by bedatadriven.
the class ReportJsonFactory method decodeDimensionList.
public List<Dimension> decodeDimensionList(JsonArray dimensions) {
Iterator<JsonElement> it = dimensions.iterator();
List<Dimension> dimensionsList = new ArrayList<Dimension>();
while (it.hasNext()) {
JsonObject dim = it.next().getAsJsonObject();
String type = dim.get("type").getAsString();
if (type.equals(DimensionType.Date.toString())) {
String dateUnit = dim.get("dateUnit").getAsString();
DateDimension dimension = new DateDimension(DateUnit.valueOf(dateUnit));
JsonElement categories = dim.get("categories");
if (categories != null) {
dimension.setCategories(decodeCategories(categories));
}
dimensionsList.add(dimension);
} else if (type.equals(DimensionType.AdminLevel.toString())) {
Integer level = dim.get("level").getAsInt();
AdminDimension dimension = new AdminDimension(level);
JsonElement categories = dim.get("categories");
if (categories != null) {
dimension.setCategories(decodeCategories(categories));
}
dimensionsList.add(dimension);
} else {
Dimension dimension = new Dimension(DimensionType.valueOf(dim.get("type").getAsString()));
JsonElement color = dim.get("color");
if (color != null) {
dimension.setColor(color.getAsString());
}
JsonElement categories = dim.get("categories");
if (categories != null) {
dimension.setCategories(decodeCategories(categories));
}
dimensionsList.add(dimension);
}
}
return dimensionsList;
}
use of org.activityinfo.shared.report.model.AdminDimension 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");
}
}
}
}
use of org.activityinfo.shared.report.model.AdminDimension in project activityinfo by bedatadriven.
the class PivotSitesHandlerTest method setUp.
@Before
public void setUp() throws Exception {
dimensions = new HashSet<Dimension>();
filter = new Filter();
provinceDim = new AdminDimension(OWNER_USER_ID);
territoireDim = new AdminDimension(2);
}
Aggregations