Search in sources :

Example 1 with FilterDescription

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

the class BaseGenerator method generateFilterDescriptions.

protected List<FilterDescription> generateFilterDescriptions(Filter filter, Set<DimensionType> excludeDims, User user) {
    List<FilterDescription> list = new ArrayList<FilterDescription>();
    Set<DimensionType> filterDims = filter.getRestrictedDimensions();
    filterDims.removeAll(excludeDims);
    for (DimensionType type : filterDims) {
        DimensionLabels labels = dispatcher.execute(new GetDimensionLabels(type, filter.getRestrictions(type)));
        list.add(new FilterDescription(type, labels.getLabels()));
    }
    return list;
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) ArrayList(java.util.ArrayList) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) DimensionLabels(org.activityinfo.shared.command.GetDimensionLabels.DimensionLabels)

Example 2 with FilterDescription

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

the class ExcelChartRenderer method render.

@Override
public void render(Workbook book, PivotChartReportElement element) {
    /* Generate the actual pivot table data */
    element.getContent().getData();
    /* Generate the excel sheet */
    new BaseExcelRenderer<PivotChartReportElement>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        @Override
        public void generate() {
            PivotTableData data = this.element.getContent().getData();
            List<PivotTableData.Axis> rows = data.getRootRow().getLeaves();
            List<PivotTableData.Axis> cols = data.getRootColumn().getLeaves();
            Row headerRow = sheet.createRow(rowIndex++);
            for (int i = 0; i != cols.size(); ++i) {
                Cell colHeaderCell = headerRow.createCell(i + 1);
                colHeaderCell.setCellValue(factory.createRichTextString(cols.get(i).flattenLabel()));
            }
            for (int i = 0; i != rows.size(); ++i) {
                Row row = sheet.createRow(rowIndex++);
                // header
                Cell rowHeaderCell = row.createCell(0);
                rowHeaderCell.setCellValue(factory.createRichTextString(rows.get(i).flattenLabel()));
                // values
                for (int j = 0; j != cols.size(); ++j) {
                    Cell valueCell = row.createCell(j + 1);
                    valueCell.setCellValue(rows.get(i).getCell(cols.get(j)).getValue());
                }
            }
        }
    };
}
Also used : PivotTableData(org.activityinfo.shared.report.content.PivotTableData) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with FilterDescription

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

the class StaticElementRenderTest method getStatic.

public Report getStatic() throws JAXBException {
    Report r = parseXml("static.xml");
    r.setContent(new ReportContent());
    r.getContent().setFilterDescriptions(new ArrayList<FilterDescription>());
    return r;
}
Also used : ReportContent(org.activityinfo.shared.report.content.ReportContent) Report(org.activityinfo.shared.report.model.Report) FilterDescription(org.activityinfo.shared.report.content.FilterDescription)

Example 4 with FilterDescription

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

the class SearchPresenter method onSearch.

@Override
public void onSearch(SearchEvent searchEvent) {
    if (!Strings.isNullOrEmpty(searchEvent.getQuery())) {
        view.setSearchQuery(searchEvent.getQuery());
        view.getLoadingMonitor().beforeRequest();
        service.execute(new Search(searchEvent.getQuery()), view.getLoadingMonitor(), new AsyncCallback<SearchResult>() {

            @Override
            public void onFailure(Throwable caught) {
                // TODO handle failure
                view.getLoadingMonitor().onServerError();
            }

            @Override
            public void onSuccess(SearchResult result) {
                view.setSearchResults(result.getPivotTabelData());
                Filter filter = result.getPivotTabelData() == null ? null : result.getPivotTabelData().getEffectiveFilter();
                view.setFilter(createFilter(filter, result.getPivotTabelData()));
                view.getLoadingMonitor().onCompleted();
                view.setSitePoints(SitePointList.fromSitesList(result.getRecentAdditions()));
                view.setSites(fromSitesList(result.getRecentAdditions()));
            }

            private Map<DimensionType, List<SearchResultEntity>> createFilter(Filter effectiveFilter, PivotContent pivotContent) {
                Map<DimensionType, List<SearchResultEntity>> newFilter = new HashMap<DimensionType, List<SearchResultEntity>>();
                if (effectiveFilter != null) {
                    for (DimensionType type : effectiveFilter.getRestrictedDimensions()) {
                        List<SearchResultEntity> entities = new ArrayList<SearchResultEntity>();
                        for (Integer entityId : effectiveFilter.getRestrictions(type)) {
                            String name = getName(entityId, type, pivotContent);
                            String link = GWT.getHostPageBaseURL() + "#search/" + type.toString() + ":" + name;
                            SearchResultEntity entity = new SearchResultEntity(entityId, name, link, type);
                            entities.add(entity);
                        }
                        newFilter.put(type, entities);
                    }
                }
                return newFilter;
            }

            private String getName(Integer entityId, DimensionType type, PivotContent pivotTable) {
                for (FilterDescription fd : pivotTable.getFilterDescriptions()) {
                    if (fd.getDimensionType() == type) {
                        return fd.getLabels().get(entityId);
                    }
                }
                return "noName";
            }
        });
    }
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) SearchResult(org.activityinfo.shared.command.result.SearchResult) Filter(org.activityinfo.shared.command.Filter) Search(org.activityinfo.shared.command.Search) PivotContent(org.activityinfo.shared.report.content.PivotContent) SitePointList(org.activityinfo.shared.command.result.SitePointList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with FilterDescription

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

the class ExcelPivotTableRenderer method render.

@Override
public void render(Workbook book, PivotTableReportElement element) {
    /* Generate the actual pivot table data */
    final PivotTableData table = element.getContent().getData();
    /* Generate the excel sheet */
    new BaseExcelTableRenderer<PivotTableReportElement, PivotTableData.Axis>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        private CellStyle[] rowHeaderStyles;

        @Override
        public void generate() {
            /* Initialize Cell Styles */
            initColHeaderStyles(table.getRootColumn());
            initRowHeaderStyles();
            /* Generate the column headers */
            generateColumnHeaders(1, table.getRootColumn());
            int headerHeight = rowIndex;
            /* Create the rows */
            // row headers are in column 1
            sheet.setColumnWidth(0, 40 * 256);
            generateRows(table.getRootRow().getChildList(), 0);
            /* Finalize the sheet */
            sheet.setRowSumsBelow(false);
            sheet.createFreezePane(1, headerHeight);
        }

        protected void initRowHeaderStyles() {
            int depth = table.getRootRow().getDepth();
            rowHeaderStyles = new CellStyle[depth];
            for (int i = 0; i != depth; ++i) {
                CellStyle style = book.createCellStyle();
                style.setIndention((short) i);
                style.setWrapText(true);
                Font font = createBaseFont();
                if (i + 1 != depth) {
                    /* Has sub headers */
                    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
                } else {
                    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
                }
                style.setFont(font);
                rowHeaderStyles[i] = style;
            }
        }

        protected void generateRows(List<PivotTableData.Axis> rows, int indent) {
            for (PivotTableData.Axis pivotRow : rows) {
                Row row = sheet.createRow(rowIndex++);
                Cell headerCell = row.createCell(0);
                headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel()));
                headerCell.setCellStyle(rowHeaderStyles[indent]);
                if (pivotRow.isLeaf()) {
                    for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) {
                        PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey());
                        if (pivotCell != null) {
                            Cell cell = row.createCell(entry.getValue());
                            cell.setCellValue(pivotCell.getValue());
                        }
                    }
                } else {
                    int groupStart = rowIndex;
                    generateRows(pivotRow.getChildList(), indent + 1);
                    int groupEnd = rowIndex;
                    sheet.groupRow(groupStart, groupEnd);
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.shared.report.content.FilterDescription) Font(org.apache.poi.ss.usermodel.Font) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) List(java.util.List) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

FilterDescription (org.activityinfo.shared.report.content.FilterDescription)8 Cell (org.apache.poi.ss.usermodel.Cell)3 Row (org.apache.poi.ss.usermodel.Row)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)2 DimensionType (org.activityinfo.shared.report.model.DimensionType)2 Test (org.junit.Test)2 FileOutputStream (java.io.FileOutputStream)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DummyPivotTableData2 (org.activityinfo.server.report.DummyPivotTableData2)1 PdfReportRenderer (org.activityinfo.server.report.renderer.itext.PdfReportRenderer)1 Filter (org.activityinfo.shared.command.Filter)1 GetDimensionLabels (org.activityinfo.shared.command.GetDimensionLabels)1 DimensionLabels (org.activityinfo.shared.command.GetDimensionLabels.DimensionLabels)1 Search (org.activityinfo.shared.command.Search)1 SearchResult (org.activityinfo.shared.command.result.SearchResult)1 SitePointList (org.activityinfo.shared.command.result.SitePointList)1