use of org.activityinfo.server.generated.GeneratedResource 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());
}
use of org.activityinfo.server.generated.GeneratedResource 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());
}
use of org.activityinfo.server.generated.GeneratedResource in project activityinfo by bedatadriven.
the class ChartRendererJC method renderToUrl.
public String renderToUrl(PivotChartReportElement element, boolean includeTitle, StorageProvider istorageProvider, int width, int height, int dpi) throws IOException {
try {
Chart chart = createChart(element, includeTitle, width, height, dpi);
GeneratedResource storage = istorageProvider.create(null, "activityinfo.jpg");
JPEGEncoder.encode(chart, 0.75f, storage.openOutputStream());
return storage.getDownloadUri();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.activityinfo.server.generated.GeneratedResource in project activityinfo by bedatadriven.
the class RenderElementHandler method execute.
@Override
public CommandResult execute(RenderElement cmd, User user) throws CommandException {
try {
Renderer renderer = rendererFactory.get(cmd.getFormat());
GeneratedResource storage = storageProvider.create(renderer.getMimeType(), cmd.getFilename() + renderer.getFileSuffix());
LOGGER.fine("Rendering element: " + cmd + "\nURL: " + storage.getDownloadUri());
try (OutputStream out = storage.openOutputStream()) {
generator.generateElement(user, cmd.getElement(), new Filter(), new DateRange());
renderer.render(cmd.getElement(), out);
}
return new UrlResult(storage.getDownloadUri());
} catch (Exception e) {
throw new RuntimeException("Exception generating export", e);
}
}
use of org.activityinfo.server.generated.GeneratedResource in project activityinfo by bedatadriven.
the class ExportSitesServlet method doPost.
/**
* Initiates an export to Excel task. A token is send back to the client as plain text
* that can be use to poll the status of the export and retrieve the result.
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Create a unique key from which the user can retrieve the file from GCS
GeneratedResource export = storageProvider.create(XlsTableWriter.EXCEL_MIME_TYPE, fileName());
TaskOptions options = TaskOptions.Builder.withUrl(ExportSitesTask.END_POINT);
for (Map.Entry<String, String[]> entry : req.getParameterMap().entrySet()) {
options.param(entry.getKey(), entry.getValue()[0]);
}
options.param("userId", Integer.toString(authenticatedUserProvider.get().getId()));
options.param("userEmail", authenticatedUserProvider.get().getEmail());
options.param("exportId", export.getId());
options.param("filename", fileName());
options.retryOptions(RetryOptions.Builder.withTaskRetryLimit(3));
QueueFactory.getDefaultQueue().add(options);
LOGGER.info("Enqueued export with id " + export.getId() + " on behalf of " + authenticatedUserProvider.get().getEmail());
resp.setStatus(HttpServletResponse.SC_ACCEPTED);
resp.getOutputStream().print(export.getId());
}
Aggregations