Search in sources :

Example 1 with EntityCategory

use of org.activityinfo.shared.report.content.EntityCategory 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 EntityCategory

use of org.activityinfo.shared.report.content.EntityCategory 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 EntityCategory

use of org.activityinfo.shared.report.content.EntityCategory in project activityinfo by bedatadriven.

the class Dimension method setCategoryColor.

public void setCategoryColor(int id, int color) {
    EntityCategory cat = new EntityCategory(id);
    CategoryProperties props = categories.get(cat);
    if (props == null) {
        props = new CategoryProperties();
        categories.put(cat, props);
    }
    props.setColor(color);
}
Also used : EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Example 4 with EntityCategory

use of org.activityinfo.shared.report.content.EntityCategory in project activityinfo by bedatadriven.

the class ItextReportRendererTest method manyColumns.

@Test
public void manyColumns() throws IOException {
    PivotTableData data = new PivotTableData();
    Dimension partner = new Dimension(DimensionType.Partner);
    Dimension year = new DateDimension(DateUnit.YEAR);
    EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
    Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
    for (int y = 2011; y < 2030; ++y) {
        Axis col = data.getRootColumn().addChild(year, new SimpleCategory("" + y), "" + y, comparator);
        avsiRow.setValue(col, (double) y);
    }
    PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
    PivotTableReportElement table = new PivotTableReportElement();
    table.addRowDimension(partner);
    table.addColDimension(year);
    table.setContent(tableContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(table);
    renderToPdf(report, "narrowColumns.pdf");
    renderToRtf(report, "narrowColumns.rtf");
}
Also used : SimpleCategory(org.activityinfo.shared.report.content.SimpleCategory) ReportContent(org.activityinfo.shared.report.content.ReportContent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Report(org.activityinfo.shared.report.model.Report) PivotContent(org.activityinfo.shared.report.content.PivotContent) DateDimension(org.activityinfo.shared.report.model.DateDimension) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension) Axis(org.activityinfo.shared.report.content.PivotTableData.Axis) Test(org.junit.Test)

Example 5 with EntityCategory

use of org.activityinfo.shared.report.content.EntityCategory in project activityinfo by bedatadriven.

the class ItextReportRendererTest method nestedColumns.

@Test
public void nestedColumns() throws IOException {
    Dimension province = new AdminDimension(1);
    Dimension partner = new Dimension(DimensionType.Partner);
    Dimension year = new DateDimension(DateUnit.YEAR);
    Dimension month = new DateDimension(DateUnit.MONTH);
    EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
    PivotTableData data = new PivotTableData();
    Axis sudKivu = data.getRootColumn().addChild(province, new EntityCategory(1, "Sud Kivu"), "Sud Kivu", comparator);
    Axis y2010 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis y2011 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis jan2010 = y2010.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2010 = y2010.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis jan2011 = y2011.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2011 = y2011.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
    avsiRow.setValue(jan2010, 1d);
    avsiRow.setValue(feb2010, 2d);
    avsiRow.setValue(jan2011, 3d);
    avsiRow.setValue(feb2011, 4d);
    PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
    PivotTableReportElement table = new PivotTableReportElement();
    table.addRowDimension(partner);
    table.addColDimension(province);
    table.addColDimension(year);
    table.addColDimension(month);
    table.setContent(tableContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(table);
    renderToPdf(report, "nestedColumns.pdf");
    renderToRtf(report, "nestedColumns.rtf");
    renderToXls(report, "nestedColumns.xls");
}
Also used : SimpleCategory(org.activityinfo.shared.report.content.SimpleCategory) ReportContent(org.activityinfo.shared.report.content.ReportContent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Report(org.activityinfo.shared.report.model.Report) PivotContent(org.activityinfo.shared.report.content.PivotContent) DateDimension(org.activityinfo.shared.report.model.DateDimension) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension) Axis(org.activityinfo.shared.report.content.PivotTableData.Axis) Test(org.junit.Test)

Aggregations

EntityCategory (org.activityinfo.shared.report.content.EntityCategory)15 Bucket (org.activityinfo.shared.command.result.Bucket)9 Dimension (org.activityinfo.shared.report.model.Dimension)9 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)8 Test (org.junit.Test)8 DateDimension (org.activityinfo.shared.report.model.DateDimension)7 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)5 OnDataSet (org.activityinfo.server.database.OnDataSet)4 PivotSites (org.activityinfo.shared.command.PivotSites)3 Axis (org.activityinfo.shared.report.content.PivotTableData.Axis)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)2 PivotContent (org.activityinfo.shared.report.content.PivotContent)2 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)2 ReportContent (org.activityinfo.shared.report.content.ReportContent)2 SimpleCategory (org.activityinfo.shared.report.content.SimpleCategory)2 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)2 Report (org.activityinfo.shared.report.model.Report)2