Search in sources :

Example 1 with PivotSites

use of org.activityinfo.shared.command.PivotSites 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 = 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.shared.command.PivotSites) Bucket(org.activityinfo.shared.command.result.Bucket) AdminMarker(org.activityinfo.shared.report.content.AdminMarker) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Example 2 with PivotSites

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

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

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

the class GetPartnersDimensionHandler method execute.

@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> 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 PartnerResult());
        return;
    }
    final Dimension dimension = new Dimension(DimensionType.Partner);
    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) {
            Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
            for (Bucket bucket : result.getBuckets()) {
                EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
                if (category == null) {
                    Log.debug("Partner is null: " + bucket.toString());
                } else {
                    PartnerDTO partner = new PartnerDTO();
                    partner.setId(category.getId());
                    partner.setName(category.getLabel());
                    partners.add(partner);
                }
            }
            // sort partners by name (fallback on id)
            List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
            Collections.sort(list, new Comparator<PartnerDTO>() {

                @Override
                public int compare(PartnerDTO p1, PartnerDTO p2) {
                    int result = p1.getName().compareToIgnoreCase(p2.getName());
                    if (result != 0) {
                        return result;
                    } else {
                        return ((Integer) p1.getId()).compareTo(p2.getId());
                    }
                }
            });
            callback.onSuccess(new PartnerResult(list));
        }

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) Dimension(org.activityinfo.shared.report.model.Dimension) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension) Comparator(java.util.Comparator) PivotSites(org.activityinfo.shared.command.PivotSites) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) List(java.util.List) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PartnerResult(org.activityinfo.shared.command.result.PartnerResult)

Example 5 with PivotSites

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

PivotSites (org.activityinfo.shared.command.PivotSites)5 Bucket (org.activityinfo.shared.command.result.Bucket)3 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)3 Dimension (org.activityinfo.shared.report.model.Dimension)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 PivotResult (org.activityinfo.shared.command.PivotSites.PivotResult)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Filter (org.activityinfo.shared.command.Filter)1 GetAttributeGroupsDimension (org.activityinfo.shared.command.GetAttributeGroupsDimension)1 GetPartnersDimension (org.activityinfo.shared.command.GetPartnersDimension)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 GetSites (org.activityinfo.shared.command.GetSites)1 PivotTableDataBuilder (org.activityinfo.shared.command.handler.pivot.PivotTableDataBuilder)1 AttributeGroupResult (org.activityinfo.shared.command.result.AttributeGroupResult)1 PartnerResult (org.activityinfo.shared.command.result.PartnerResult)1 SiteResult (org.activityinfo.shared.command.result.SiteResult)1 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)1