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);
}
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());
}
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()));
}
}
}
}
};
}
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);
}
}
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"));
}
Aggregations