Search in sources :

Example 1 with TableData

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

the class TableGenerator method generate.

@Override
public void generate(User user, TableElement element, Filter inheritedFilter, DateRange dateRange) {
    Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
    Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
    TableContent content = new TableContent();
    content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
    TableData data = generateData(element, effectiveFilter);
    content.setData(data);
    if (element.getMap() != null) {
        mapGenerator.generate(user, element.getMap(), effectiveFilter, dateRange);
        Map<Integer, String> siteLabels = element.getMap().getContent().siteLabelMap();
        for (SiteDTO row : data.getRows()) {
            row.set("map", siteLabels.get(row.getId()));
        }
    }
    element.setContent(content);
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) Filter(org.activityinfo.shared.command.Filter) SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableData(org.activityinfo.shared.report.content.TableData) TableContent(org.activityinfo.shared.report.content.TableContent)

Example 2 with TableData

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

the class TableGenerator method generateData.

public TableData generateData(TableElement element, Filter filter) {
    GetSites query = new GetSites(filter);
    if (!element.getSortBy().isEmpty()) {
        TableColumn sortBy = element.getSortBy().get(0);
        query.setSortInfo(new SortInfo(sortBy.getSitePropertyName(), sortBy.isOrderAscending() ? SortDir.ASC : SortDir.DESC));
    }
    SiteResult sites = getDispatcher().execute(query);
    return new TableData(element.getRootColumn(), sites.getData());
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

Example 3 with TableData

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

the class ExcelTableRenderer method render.

@Override
public void render(Workbook book, TableElement element) {
    final TableData tableData = element.getContent().getData();
    new BaseExcelTableRenderer<TableElement, TableColumn>(book, element) {

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

        @Override
        public void generate() {
            /* Generate the column headers for the table */
            initColHeaderStyles(element.getRootColumn());
            generateColumnHeaders(0, element.getRootColumn());
            int headerHeight = rowIndex;
            sheet.createFreezePane(element.getFrozenColumns(), headerHeight);
            /* Prepare the generators and indexes */
            List<TableColumn> leaves = element.getRootColumn().getLeaves();
            String[] colIndexes = new String[leaves.size()];
            for (int i = 0; i != leaves.size(); ++i) {
                colIndexes[i] = leaves.get(i).getSitePropertyName();
            }
            for (SiteDTO rowData : tableData.getRows()) {
                Row row = sheet.createRow(rowIndex++);
                for (int i = 0; i != colIndexes.length; ++i) {
                    Object value = null;
                    if (colIndexes[i] != null) {
                        value = rowData.get(colIndexes[i]);
                    }
                    Cell cell = row.createCell(i);
                    if (value instanceof Number) {
                        cell.setCellValue(((Number) value).doubleValue());
                    } else if (value instanceof Date) {
                        cell.setCellValue((Date) value);
                    } else if (value instanceof Boolean) {
                        cell.setCellValue((Boolean) value);
                    } else if (value != null) {
                        cell.setCellValue(factory.createRichTextString(value.toString()));
                    }
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.shared.report.content.FilterDescription) TableColumn(org.activityinfo.shared.report.model.TableColumn) Date(java.util.Date) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Row(org.apache.poi.ss.usermodel.Row) TableData(org.activityinfo.shared.report.content.TableData) Cell(org.apache.poi.ss.usermodel.Cell)

Example 4 with TableData

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

the class ItextTableRenderer method render.

@Override
public void render(DocWriter writer, Document document, TableElement element) throws DocumentException {
    document.add(ThemeHelper.elementTitle(element.getTitle()));
    ItextRendererHelper.addFilterDescription(document, element.getContent().getFilterDescriptions());
    ItextRendererHelper.addDateFilterDescription(document, element.getFilter().getDateRange());
    TableData data = element.getContent().getData();
    if (data.isEmpty()) {
        renderEmptyText(document);
    } else {
        if (element.getMap() != null) {
            mapRenderer.renderMap(writer, element.getMap(), document);
        }
        renderTable(document, data);
    }
}
Also used : TableData(org.activityinfo.shared.report.content.TableData)

Example 5 with TableData

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

the class TableGeneratorTest method simpleTable.

@Test
public void simpleTable() {
    TableElement table = new TableElement();
    TableColumn column = new TableColumn("Location", "location.name");
    table.addColumn(column);
    TableGenerator gtor = new TableGenerator(createDispatcher(), null);
    gtor.generate(user, table, null, null);
    Assert.assertNotNull("content is set", table.getContent());
    TableData data = table.getContent().getData();
    List<SiteDTO> rows = data.getRows();
    Assert.assertEquals("row count", 1, rows.size());
    SiteDTO row = rows.get(0);
    assertThat((String) row.get(column.getSitePropertyName()), equalTo("tampa bay"));
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) Test(org.junit.Test)

Aggregations

TableData (org.activityinfo.shared.report.content.TableData)5 SiteDTO (org.activityinfo.shared.dto.SiteDTO)3 TableColumn (org.activityinfo.shared.report.model.TableColumn)3 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)1 Date (java.util.Date)1 Filter (org.activityinfo.shared.command.Filter)1 GetSites (org.activityinfo.shared.command.GetSites)1 SiteResult (org.activityinfo.shared.command.result.SiteResult)1 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)1 TableContent (org.activityinfo.shared.report.content.TableContent)1 DimensionType (org.activityinfo.shared.report.model.DimensionType)1 TableElement (org.activityinfo.shared.report.model.TableElement)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Test (org.junit.Test)1