Search in sources :

Example 6 with Dimension

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;
}
Also used : Dimension(org.activityinfo.shared.report.model.Dimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 7 with Dimension

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);
        }
    });
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) Dimension(org.activityinfo.shared.report.model.Dimension) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) Comparator(java.util.Comparator) PivotSites(org.activityinfo.shared.command.PivotSites) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) List(java.util.List) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Example 8 with Dimension

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);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) Bucket(org.activityinfo.shared.command.result.Bucket) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) PointBundler(org.activityinfo.shared.command.handler.pivot.bundler.PointBundler) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) QuarterBundler(org.activityinfo.shared.command.handler.pivot.bundler.QuarterBundler) OrderedEntityBundler(org.activityinfo.shared.command.handler.pivot.bundler.OrderedEntityBundler) PointBundler(org.activityinfo.shared.command.handler.pivot.bundler.PointBundler) Bundler(org.activityinfo.shared.command.handler.pivot.bundler.Bundler) MySqlYearWeekBundler(org.activityinfo.shared.command.handler.pivot.bundler.MySqlYearWeekBundler) YearBundler(org.activityinfo.shared.command.handler.pivot.bundler.YearBundler) MonthBundler(org.activityinfo.shared.command.handler.pivot.bundler.MonthBundler) AttributeBundler(org.activityinfo.shared.command.handler.pivot.bundler.AttributeBundler) SimpleBundler(org.activityinfo.shared.command.handler.pivot.bundler.SimpleBundler) EntityBundler(org.activityinfo.shared.command.handler.pivot.bundler.EntityBundler)

Example 9 with Dimension

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;
    }
}
Also used : DimensionCategory(org.activityinfo.shared.report.content.DimensionCategory) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) Dimension(org.activityinfo.shared.report.model.Dimension)

Example 10 with Dimension

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();
}
Also used : DimensionCategory(org.activityinfo.shared.report.content.DimensionCategory) Dimension(org.activityinfo.shared.report.model.Dimension)

Aggregations

Dimension (org.activityinfo.shared.report.model.Dimension)46 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)31 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)29 DateDimension (org.activityinfo.shared.report.model.DateDimension)28 Test (org.junit.Test)23 Bucket (org.activityinfo.shared.command.result.Bucket)11 OnDataSet (org.activityinfo.server.database.OnDataSet)10 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)10 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)9 ArrayList (java.util.ArrayList)6 PivotSites (org.activityinfo.shared.command.PivotSites)6 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)4 Comparator (java.util.Comparator)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)3 DimensionCategory (org.activityinfo.shared.report.content.DimensionCategory)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 ReportChangeEvent (org.activityinfo.client.page.report.ReportChangeEvent)2