Search in sources :

Example 1 with ExportResult

use of org.activityinfo.model.job.ExportResult in project activityinfo by bedatadriven.

the class ExportAuditLogExecutor method execute.

@Override
public ExportResult execute(ExportAuditLog descriptor) throws IOException {
    UserDatabaseDTO db = dispatcher.execute(new GetSchema()).getDatabaseById(descriptor.getDatabaseId());
    GeneratedResource export = storageProvider.create("text/csv;charset=UTF-8", String.format("AuditLog_%d_%s.csv", db.getId(), Filenames.timestamp()));
    try (CsvWriter writer = new CsvWriter(new OutputStreamWriter(export.openOutputStream(), Charsets.UTF_8))) {
        AuditLogWriter logWriter = new AuditLogWriter(entityManager.get(), db, writer);
        for (ActivityDTO activityDTO : db.getActivities()) {
            logWriter.writeForm(catalog, activityDTO.getFormId());
        }
    }
    return new ExportResult(export.getDownloadUri());
}
Also used : CsvWriter(org.activityinfo.server.endpoint.rest.CsvWriter) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) OutputStreamWriter(java.io.OutputStreamWriter) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) ExportResult(org.activityinfo.model.job.ExportResult)

Example 2 with ExportResult

use of org.activityinfo.model.job.ExportResult 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)

Aggregations

ExportResult (org.activityinfo.model.job.ExportResult)2 GeneratedResource (org.activityinfo.server.generated.GeneratedResource)2 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 EffectiveTableModel (org.activityinfo.analysis.table.EffectiveTableModel)1 TableViewModel (org.activityinfo.analysis.table.TableViewModel)1 XlsTableWriter (org.activityinfo.io.xls.XlsTableWriter)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1 TableModel (org.activityinfo.model.analysis.TableModel)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 CsvWriter (org.activityinfo.server.endpoint.rest.CsvWriter)1