Search in sources :

Example 1 with EffectiveTableModel

use of org.activityinfo.analysis.table.EffectiveTableModel in project activityinfo by bedatadriven.

the class ExportFormExecutor method execute.

@Override
public ExportResult execute(ExportFormJob descriptor) throws IOException {
    TableModel tableModel = descriptor.getTableModel();
    GeneratedResource export = storageProvider.create(XlsTableWriter.EXCEL_MIME_TYPE, "Export.xls");
    TableViewModel viewModel = new TableViewModel(formSource, tableModel);
    EffectiveTableModel effectiveTableModel = viewModel.getEffectiveTable().waitFor();
    ColumnSet columnSet = effectiveTableModel.getColumnSet().waitFor();
    XlsTableWriter writer = new XlsTableWriter();
    writer.addSheet(effectiveTableModel, columnSet);
    try (OutputStream out = export.openOutputStream()) {
        writer.write(out);
    }
    return new ExportResult(export.getDownloadUri());
}
Also used : EffectiveTableModel(org.activityinfo.analysis.table.EffectiveTableModel) XlsTableWriter(org.activityinfo.io.xls.XlsTableWriter) TableViewModel(org.activityinfo.analysis.table.TableViewModel) OutputStream(java.io.OutputStream) ColumnSet(org.activityinfo.model.query.ColumnSet) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) EffectiveTableModel(org.activityinfo.analysis.table.EffectiveTableModel) TableModel(org.activityinfo.model.analysis.TableModel) ExportResult(org.activityinfo.model.job.ExportResult)

Example 2 with EffectiveTableModel

use of org.activityinfo.analysis.table.EffectiveTableModel in project activityinfo by bedatadriven.

the class XlsTableWriterTest method export.

private HSSFWorkbook export(TableModel tableModel) throws IOException {
    TableViewModel viewModel = new TableViewModel(formSource, tableModel);
    EffectiveTableModel effectiveTableModel = viewModel.getEffectiveTable().waitFor();
    if (effectiveTableModel.getRootFormState() != FormTree.State.VALID) {
        throw new IllegalStateException("Root Form has state: " + effectiveTableModel.getRootFormState());
    }
    ColumnSet columnSet = effectiveTableModel.getColumnSet().waitFor();
    XlsTableWriter writer = new XlsTableWriter();
    writer.addSheet(effectiveTableModel, columnSet);
    writer.write(new FileOutputStream("build/" + tableModel.getFormId().asString() + ".xls"));
    return writer.getBook();
}
Also used : EffectiveTableModel(org.activityinfo.analysis.table.EffectiveTableModel) TableViewModel(org.activityinfo.analysis.table.TableViewModel) FileOutputStream(java.io.FileOutputStream) ColumnSet(org.activityinfo.model.query.ColumnSet)

Aggregations

EffectiveTableModel (org.activityinfo.analysis.table.EffectiveTableModel)2 TableViewModel (org.activityinfo.analysis.table.TableViewModel)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 XlsTableWriter (org.activityinfo.io.xls.XlsTableWriter)1 TableModel (org.activityinfo.model.analysis.TableModel)1 ExportResult (org.activityinfo.model.job.ExportResult)1 GeneratedResource (org.activityinfo.server.generated.GeneratedResource)1