use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class SearchHandler method createSearchPivotTableElement.
private PivotTableReportElement createSearchPivotTableElement() {
final PivotTableReportElement pivotTable = new PivotTableReportElement();
pivotTable.addRowDimension(new Dimension(DimensionType.Database));
pivotTable.addRowDimension(new Dimension(DimensionType.Activity));
pivotTable.addRowDimension(new Dimension(DimensionType.Indicator));
return pivotTable;
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class GetAttributeGroupsDimensionHandler method execute.
@Override
public void execute(GetAttributeGroupsDimension cmd, final ExecutionContext context, final AsyncCallback<AttributeGroupResult> callback) {
// if the filter doesn't contain any activity, database or indicator values, just return an empty list
if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
callback.onSuccess(new AttributeGroupResult());
return;
}
final Dimension dimension = new Dimension(DimensionType.AttributeGroup);
final PivotSites query = new PivotSites();
query.setFilter(cmd.getFilter());
query.setDimensions(dimension);
query.setValueType(ValueType.DIMENSION);
context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {
@Override
public void onSuccess(PivotSites.PivotResult result) {
final List<AttributeGroupDTO> list = new ArrayList<AttributeGroupDTO>();
// populate the resultlist
for (Bucket bucket : result.getBuckets()) {
EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
if (category != null) {
AttributeGroupDTO attributeGroup = new AttributeGroupDTO();
attributeGroup.setId(category.getId());
attributeGroup.setName(category.getLabel());
list.add(attributeGroup);
}
}
// sort the groups in the list by name (fallback on id)
Collections.sort(list, new Comparator<AttributeGroupDTO>() {
@Override
public int compare(AttributeGroupDTO g1, AttributeGroupDTO g2) {
int result = g1.getName().compareToIgnoreCase(g2.getName());
if (result != 0) {
return result;
} else {
return ((Integer) g1.getId()).compareTo(g2.getId());
}
}
});
callback.onSuccess(new AttributeGroupResult(list));
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class PivotQuery method execute.
public void execute(final AsyncCallback<Void> callback) {
baseTable.setupQuery(command, query);
if (command.isPivotedBy(DimensionType.Location) || command.isPointRequested()) {
query.leftJoin(Tables.LOCATION, "Location").on("Location.LocationId=" + baseTable.getDimensionIdColumn(DimensionType.Location));
}
if (command.isPivotedBy(DimensionType.Partner)) {
query.leftJoin(Tables.PARTNER, "Partner").on("Partner.PartnerId=" + baseTable.getDimensionIdColumn(DimensionType.Partner));
}
if (command.isPivotedBy(DimensionType.Project)) {
SqlQuery activeProjects = SqlQuery.selectAll().from(Tables.PROJECT, "AllProjects").where("AllProjects.dateDeleted").isNull();
query.leftJoin(activeProjects, "Project").on("Project.ProjectId=" + baseTable.getDimensionIdColumn(DimensionType.Project));
}
if (command.isPointRequested()) {
if (command.isPivotedBy(DimensionType.Location)) {
query.appendColumn("Location.X", "LX");
query.appendColumn("Location.Y", "LY");
} else {
query.appendColumn("AVG(Location.X)", "LX");
query.appendColumn("AVG(Location.Y)", "LY");
}
// Build the derived table that identifies the MBR for each
// location using the admin MBRs
SqlQuery adminBoundsQuery = SqlQuery.select().appendColumn("link.LocationId", "LocationId").appendColumn("(MAX(X1)+MIN(X2))/2.0", "AX").appendColumn("(MAX(Y1)+MIN(Y2))/2.0", "AY").from(Tables.LOCATION_ADMIN_LINK, "link").leftJoin(Tables.ADMIN_ENTITY, "e").on("link.adminentityid=e.adminentityid").groupBy("link.locationid");
query.leftJoin(adminBoundsQuery, "ambr").on("Location.LocationId=ambr.LocationId");
query.appendColumn("ambr.AX", "AX");
query.appendColumn("ambr.AY", "AY");
System.out.println(adminBoundsQuery.sql());
bundlers.add(new PointBundler());
}
addDimensionBundlers();
// otherwise permissions have already been taken into account during synchronization
if (isRemote()) {
appendVisibilityFilter();
}
if (filter.getMinDate() != null) {
query.where(baseTable.getDateCompleteColumn()).greaterThanOrEqualTo(filter.getMinDate());
}
if (filter.getMaxDate() != null) {
query.where(baseTable.getDateCompleteColumn()).lessThanOrEqualTo(filter.getMaxDate());
}
appendDimensionRestrictions();
if (Log.isDebugEnabled()) {
Log.debug("PivotQuery (" + baseTable.getClass() + ") executing query: " + query.sql());
}
query.execute(tx, new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
for (SqlResultSetRow row : results.getRows()) {
Bucket bucket = new Bucket();
bucket.setAggregationMethod(row.getInt(ValueFields.AGGREGATION));
bucket.setCount(row.getInt(ValueFields.COUNT));
if (!row.isNull(ValueFields.SUM)) {
bucket.setSum(row.getDouble(ValueFields.SUM));
}
bucket.setCategory(new Dimension(DimensionType.Target), baseTable.getTargetCategory());
for (Bundler bundler : bundlers) {
bundler.bundle(row, bucket);
}
context.addBucket(bucket);
}
callback.onSuccess(null);
}
});
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class PivotTableDataBuilder method find.
protected PivotTableData.Axis find(PivotTableData.Axis axis, Iterator<Dimension> dimensionIterator, Map<Dimension, Comparator<PivotTableData.Axis>> comparators, Bucket result) {
Dimension childDimension = dimensionIterator.next();
DimensionCategory category = result.getCategory(childDimension);
PivotTableData.Axis child = null;
child = axis.getChild(category);
if (child == null) {
String categoryLabel;
if (category == null) {
categoryLabel = I18N.CONSTANTS.emptyDimensionCategory();
} else {
categoryLabel = childDimension.getLabel(category);
if (categoryLabel == null) {
categoryLabel = category.getLabel();
}
}
child = axis.addChild(childDimension, result.getCategory(childDimension), categoryLabel, comparators.get(childDimension));
}
if (dimensionIterator.hasNext()) {
return find(child, dimensionIterator, comparators, result);
} else {
return child;
}
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class Bucket method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" { Value: ").append(doubleValue());
for (Dimension dim : dimensions()) {
DimensionCategory cat = getCategory(dim);
sb.append("\n ").append(dim.toString()).append(": ");
sb.append(cat.toString());
}
sb.append("\n }");
return sb.toString();
}
Aggregations