Search in sources :

Example 1 with PivotResult

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

the class PolygonLayerGenerator method queryBuckets.

private void queryBuckets(DispatcherSync dispatcher, Filter layerFilter) {
    PivotSites query = new PivotSites();
    query.setFilter(layerFilter);
    AdminDimension adminDimension = new AdminDimension(layer.getAdminLevelId());
    query.setDimensions(adminDimension);
    MagnitudeScaleBuilder scaleBuilder = new MagnitudeScaleBuilder(layer);
    this.pivotResult = query.isTooBroad() ? new PivotResult() : dispatcher.execute(query);
    for (Bucket bucket : pivotResult.getBuckets()) {
        EntityCategory category = (EntityCategory) bucket.getCategory(adminDimension);
        if (category != null) {
            int adminEntityId = category.getId();
            AdminMarker polygon = overlay.getPolygon(adminEntityId);
            if (polygon != null) {
                polygon.setValue(bucket.doubleValue());
                scaleBuilder.addValue(bucket.doubleValue());
            }
        }
    }
    colorScale = scaleBuilder.build();
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) PivotResult(org.activityinfo.legacy.shared.command.PivotSites.PivotResult) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) AdminMarker(org.activityinfo.legacy.shared.reports.content.AdminMarker) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 2 with PivotResult

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

the class OldPivotSitesHandler method execute.

@Override
public void execute(PivotSites command, ExecutionContext context, final AsyncCallback<PivotResult> callback) {
    LOGGER.fine("Pivoting: " + command);
    if (command.getFilter() == null || filterIsToBroad(command.getFilter())) {
        Log.error("Filter is to broad: " + command.getFilter());
        PivotResult emptyResult = new PivotResult();
        emptyResult.setBuckets(Lists.<Bucket>newArrayList());
        callback.onSuccess(emptyResult);
        return;
    }
    final PivotQueryContext queryContext = new PivotQueryContext(command, context, dialect);
    final List<WorkItem> workList = Lists.newArrayList();
    for (BaseTable baseTable : baseTables) {
        if (baseTable.accept(command)) {
            workList.add(new PivotQuery(queryContext, baseTable));
        }
    }
    if (command.getValueType() == PivotSites.ValueType.INDICATOR) {
        workList.add(new ErrorLoggingWorkItem(new CalculatedIndicatorsQuery(queryContext)));
    }
    if (workList.isEmpty()) {
        callback.onSuccess(new PivotResult(Lists.<Bucket>newArrayList()));
    }
    final Set<WorkItem> remaining = Sets.newHashSet(workList);
    final List<Throwable> errors = Lists.newArrayList();
    for (final WorkItem workItem : workList) {
        workItem.execute(new AsyncCallback<Void>() {

            @Override
            public void onSuccess(Void voidResult) {
                if (errors.isEmpty()) {
                    remaining.remove(workItem);
                    if (remaining.isEmpty()) {
                        try {
                            callback.onSuccess(new PivotResult(queryContext.getBuckets()));
                        } catch (Throwable e) {
                            callback.onFailure(e);
                        }
                    }
                }
            }

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

Example 3 with PivotResult

use of org.activityinfo.legacy.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) {
    PivotSites command = new PivotSites(element.allDimensions(), filter);
    PivotResult result = command.isTooBroad() ? new PivotResult() : getDispatcher().execute(command);
    PivotTableDataBuilder builder = new PivotTableDataBuilder();
    return builder.build(rowDims, colDims, result.getBuckets());
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) PivotResult(org.activityinfo.legacy.shared.command.PivotSites.PivotResult) PivotTableDataBuilder(org.activityinfo.legacy.shared.impl.pivot.PivotTableDataBuilder)

Example 4 with PivotResult

use of org.activityinfo.legacy.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.Activity, 1);
    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 : SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) PivotResult(org.activityinfo.legacy.shared.command.PivotSites.PivotResult) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Aggregations

PivotResult (org.activityinfo.legacy.shared.command.PivotSites.PivotResult)4 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)2 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 PivotTableDataBuilder (org.activityinfo.legacy.shared.impl.pivot.PivotTableDataBuilder)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 AdminMarker (org.activityinfo.legacy.shared.reports.content.AdminMarker)1 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)1 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)1 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)1 Test (org.junit.Test)1