Search in sources :

Example 1 with PivotTableReportElement

use of org.activityinfo.shared.report.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class ReportJsonFactory method serialize.

@Override
public String serialize(Report report) {
    JsonObject jsonReport = new JsonObject();
    // write custom maker
    jsonReport.addProperty("id", report.getId());
    if (report.getTitle() != null) {
        jsonReport.addProperty("title", report.getTitle());
    }
    if (report.getSheetTitle() != null) {
        jsonReport.addProperty("sheetTitle", report.getSheetTitle());
    }
    if (report.getDescription() != null) {
        jsonReport.addProperty("description", report.getDescription());
    }
    if (report.getFileName() != null) {
        jsonReport.addProperty("fileName", report.getFileName());
    }
    jsonReport.add("filter", encodeFilter(report.getFilter()));
    if (report.getElements() != null) {
        List<ReportElement> reportElements = report.getElements();
        JsonArray jsonElements = new JsonArray();
        for (int i = 0; i < reportElements.size(); i++) {
            ReportElement rp = report.getElement(i);
            if (rp instanceof PivotTableReportElement) {
                jsonElements.add(encodePivotTableReportElement((PivotTableReportElement) rp));
            } else if (rp instanceof PivotChartReportElement) {
                jsonElements.add(encodePivotChartReportElement((PivotChartReportElement) rp));
            } else if (rp instanceof MapReportElement) {
                jsonElements.add(encodeMapReportElement((MapReportElement) rp));
            }
        }
        jsonReport.add("elements", jsonElements);
    }
    return jsonReport.toString();
}
Also used : JsonArray(com.google.gson.JsonArray) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) JsonObject(com.google.gson.JsonObject) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ReportElement(org.activityinfo.shared.report.model.ReportElement) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 2 with PivotTableReportElement

use of org.activityinfo.shared.report.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class ReportJsonFactory method decodePivotTableReportElement.

public PivotTableReportElement decodePivotTableReportElement(JsonObject element) {
    PivotTableReportElement pivotTableElement = new PivotTableReportElement();
    JsonElement title = element.get("title");
    if (title != null) {
        pivotTableElement.setTitle(title.getAsString());
    }
    JsonElement sheetTitle = element.get("sheetTitle");
    if (sheetTitle != null) {
        pivotTableElement.setSheetTitle(sheetTitle.getAsString());
    }
    JsonObject filter = element.get("filter").getAsJsonObject();
    pivotTableElement.setFilter(decodeFilter(filter));
    JsonArray colDims = element.get("columnDimensions").getAsJsonArray();
    if (colDims.size() > 0) {
        pivotTableElement.setColumnDimensions(decodeDimensionList(colDims));
    }
    JsonArray rowDims = element.get("rowDimensions").getAsJsonArray();
    if (rowDims.size() > 0) {
        pivotTableElement.setRowDimensions(decodeDimensionList(rowDims));
    }
    return pivotTableElement;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 3 with PivotTableReportElement

use of org.activityinfo.shared.report.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class PivotTableTemplate method createElement.

@Override
public void createElement(AsyncCallback<ReportElement> callback) {
    PivotTableReportElement table = new PivotTableReportElement();
    table.addColDimension(new DateDimension(DateUnit.YEAR));
    table.addColDimension(new DateDimension(DateUnit.MONTH));
    table.addRowDimension(new Dimension(DimensionType.Partner));
    callback.onSuccess(table);
}
Also used : Dimension(org.activityinfo.shared.report.model.Dimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension)

Example 4 with PivotTableReportElement

use of org.activityinfo.shared.report.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class SearchHandler method processFilter.

private void processFilter(final ExecutionContext context, final AsyncCallback<SearchResult> callback, final Filter resultFilter) {
    final SearchResult searchResult = new SearchResult();
    if (resultFilter.getRestrictedDimensions().size() > 0) {
        // pivot data query
        final PivotTableReportElement pivotTable = createSearchPivotTableElement();
        pivotTable.setFilter(resultFilter);
        GenerateElement<PivotContent> zmd = new GenerateElement<PivotContent>(pivotTable);
        context.execute(zmd, new AsyncCallback<PivotContent>() {

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }

            @Override
            public void onSuccess(PivotContent content) {
                content.setEffectiveFilter(resultFilter);
                searchResult.setPivotTabelData(content);
                // recent sites query
                GetSites getSites = createGetSitesCommand(resultFilter);
                context.execute(getSites, new AsyncCallback<SiteResult>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(SiteResult resultSites) {
                        searchResult.setRecentAdditions(resultSites.getData());
                        callback.onSuccess(searchResult);
                    }
                });
            }
        });
    } else {
        // Return empty searchresult when no filtered entities found
        callback.onSuccess(searchResult);
    }
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) PivotContent(org.activityinfo.shared.report.content.PivotContent) GetSites(org.activityinfo.shared.command.GetSites) GenerateElement(org.activityinfo.shared.command.GenerateElement) SearchResult(org.activityinfo.shared.command.result.SearchResult) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Example 5 with PivotTableReportElement

use of org.activityinfo.shared.report.model.PivotTableReportElement in project activityinfo by bedatadriven.

the class SearchHandler method createSearchPivotTableElement.

private PivotTableReportElement createSearchPivotTableElement() {
    final PivotTableReportElement pivotTable = new PivotTableReportElement();
    pivotTable.addRowDimension(new Dimension(DimensionType.Database));
    pivotTable.addRowDimension(new Dimension(DimensionType.Activity));
    pivotTable.addRowDimension(new Dimension(DimensionType.Indicator));
    return pivotTable;
}
Also used : Dimension(org.activityinfo.shared.report.model.Dimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement)

Aggregations

PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)23 Test (org.junit.Test)15 Dimension (org.activityinfo.shared.report.model.Dimension)10 Report (org.activityinfo.shared.report.model.Report)7 PivotContent (org.activityinfo.shared.report.content.PivotContent)6 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)5 PivotChartReportElement (org.activityinfo.shared.report.model.PivotChartReportElement)5 ArrayList (java.util.ArrayList)4 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)4 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)4 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)3 ReportContent (org.activityinfo.shared.report.content.ReportContent)3 DateDimension (org.activityinfo.shared.report.model.DateDimension)3 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2