Search in sources :

Example 1 with PivotQueryContext

use of org.activityinfo.shared.command.handler.pivot.PivotQueryContext in project activityinfo by bedatadriven.

the class PivotSitesHandler method execute.

@Override
public void execute(PivotSites command, ExecutionContext context, final AsyncCallback<PivotResult> callback) {
    LOGGER.fine("Pivoting: " + command);
    if (command.getValueType() == ValueType.INDICATOR) {
        if (command.getFilter() == null || command.getFilter().getRestrictions(DimensionType.Indicator).isEmpty()) {
            Log.error("No indicator filter provided to pivot query");
        }
    }
    final PivotQueryContext queryContext = new PivotQueryContext(command, context, dialect);
    final List<PivotQuery> queries = Lists.newArrayList();
    for (BaseTable baseTable : baseTables) {
        if (baseTable.accept(command)) {
            queries.add(new PivotQuery(queryContext, baseTable));
        }
    }
    final List<Bucket> buckets = Lists.newArrayList();
    if (queries.isEmpty()) {
        callback.onSuccess(new PivotResult(buckets));
    }
    final Set<PivotQuery> remaining = Sets.newHashSet(queries);
    final List<Throwable> errors = Lists.newArrayList();
    for (final PivotQuery query : queries) {
        query.execute(new AsyncCallback<Void>() {

            @Override
            public void onSuccess(Void voidResult) {
                if (errors.isEmpty()) {
                    remaining.remove(query);
                    if (remaining.isEmpty()) {
                        callback.onSuccess(new PivotResult(queryContext.getBuckets()));
                    }
                }
            }

            @Override
            public void onFailure(Throwable caught) {
                if (errors.isEmpty()) {
                    callback.onFailure(caught);
                }
                errors.add(caught);
            }
        });
    }
}
Also used : PivotQuery(org.activityinfo.shared.command.handler.pivot.PivotQuery) PivotQueryContext(org.activityinfo.shared.command.handler.pivot.PivotQueryContext) BaseTable(org.activityinfo.shared.command.handler.pivot.BaseTable) Bucket(org.activityinfo.shared.command.result.Bucket) PivotResult(org.activityinfo.shared.command.PivotSites.PivotResult)

Aggregations

PivotResult (org.activityinfo.shared.command.PivotSites.PivotResult)1 BaseTable (org.activityinfo.shared.command.handler.pivot.BaseTable)1 PivotQuery (org.activityinfo.shared.command.handler.pivot.PivotQuery)1 PivotQueryContext (org.activityinfo.shared.command.handler.pivot.PivotQueryContext)1 Bucket (org.activityinfo.shared.command.result.Bucket)1