Search in sources :

Example 1 with CsvWriter

use of org.activityinfo.server.endpoint.rest.CsvWriter 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)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)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 ExportResult (org.activityinfo.model.job.ExportResult)1 CsvWriter (org.activityinfo.server.endpoint.rest.CsvWriter)1 GeneratedResource (org.activityinfo.server.generated.GeneratedResource)1