Search in sources :

Example 1 with PivotResult

use of org.activityinfo.shared.command.PivotSites.PivotResult in project activityinfo by bedatadriven.

the class PivotGenerator method generateData.

protected PivotTableData generateData(int userId, Locale locale, T element, Filter filter, List<Dimension> rowDims, List<Dimension> colDims) {
    PivotResult result = getDispatcher().execute(new PivotSites(element.allDimensions(), filter));
    PivotTableDataBuilder builder = new PivotTableDataBuilder();
    return builder.build(element, rowDims, colDims, result.getBuckets());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) PivotResult(org.activityinfo.shared.command.PivotSites.PivotResult) PivotTableDataBuilder(org.activityinfo.shared.command.handler.pivot.PivotTableDataBuilder)

Example 2 with PivotResult

use of org.activityinfo.shared.command.PivotSites.PivotResult 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)

Example 3 with PivotResult

use of org.activityinfo.shared.command.PivotSites.PivotResult in project activityinfo by bedatadriven.

the class ProjectTest method deleteProject.

@Test
public void deleteProject() {
    setUser(1);
    long originalDatabaseVersion = lookupDbVersion(1);
    int projectId = 2;
    execute(RequestChange.delete("Project", projectId));
    SchemaDTO schema = execute(new GetSchema());
    assertThat(schema.getProjectById(projectId), nullValue());
    // make sure it's gone from sites
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, 3);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getData().get(0).getProject(), is(nullValue()));
    // and doesn't show up in pivoting...
    PivotSites pivot = new PivotSites();
    Dimension projectDimension = new Dimension(DimensionType.Project);
    pivot.setDimensions(projectDimension);
    pivot.setFilter(filter);
    PivotResult buckets = execute(pivot);
    assertThat(buckets.getBuckets().size(), equalTo(1));
    assertThat(buckets.getBuckets().get(0).getCategory(projectDimension), is(nullValue()));
    // make sure the version number of the database is updated
    assertThat(lookupDbVersion(1), not(equalTo(originalDatabaseVersion)));
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) Filter(org.activityinfo.shared.command.Filter) SiteResult(org.activityinfo.shared.command.result.SiteResult) PivotResult(org.activityinfo.shared.command.PivotSites.PivotResult) GetSites(org.activityinfo.shared.command.GetSites) Dimension(org.activityinfo.shared.report.model.Dimension) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

PivotResult (org.activityinfo.shared.command.PivotSites.PivotResult)3 PivotSites (org.activityinfo.shared.command.PivotSites)2 Filter (org.activityinfo.shared.command.Filter)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 GetSites (org.activityinfo.shared.command.GetSites)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 PivotTableDataBuilder (org.activityinfo.shared.command.handler.pivot.PivotTableDataBuilder)1 Bucket (org.activityinfo.shared.command.result.Bucket)1 SiteResult (org.activityinfo.shared.command.result.SiteResult)1 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)1 Dimension (org.activityinfo.shared.report.model.Dimension)1 Test (org.junit.Test)1