use of org.activityinfo.server.generated.GeneratedResource in project activityinfo by bedatadriven.
the class ExportSitesTask method doPost.
@Override
@Timed(name = "export", kind = "sites")
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String exportId = req.getParameter("exportId");
String locale = req.getParameter("locale");
if (Strings.isNullOrEmpty(locale)) {
locale = Locale.ENGLISH.toLanguageTag();
}
// authenticate this task
authProvider.set(new AuthenticatedUser("", Integer.parseInt(req.getParameter("userId")), req.getParameter("userEmail")));
ThreadLocalLocaleProvider.pushLocale(Locale.forLanguageTag(locale));
try {
// create the workbook
Filter filter = FilterUrlSerializer.fromQueryParameter(req.getParameter("filter"));
TaskContext context = new TaskContext(dispatcher.get(), storageProvider, exportId);
SiteExporter export = new SiteExporter(context).buildExcelWorkbook(filter);
// Save to Export storage
GeneratedResource storage = storageProvider.get(exportId);
try (OutputStream out = storage.openOutputStream()) {
export.getBook().write(out);
}
} finally {
ThreadLocalLocaleProvider.popLocale();
}
}
use of org.activityinfo.server.generated.GeneratedResource in project activityinfo by bedatadriven.
the class GeoDigestModelBuilder method createDatabaseModel.
private void createDatabaseModel(GeoDigestModel model, Database database) throws IOException {
DatabaseModel databaseModel = new DatabaseModel(model, database);
List<Integer> siteIds = findSiteIds(database, model.getUserDigest().getFrom());
LOGGER.finest("rendering geo digest for user " + model.getUserDigest().getUser().getId() + " and database " + database.getId() + " - found " + siteIds.size() + " site(s) that were edited since " + DateFormatter.formatDateTime(model.getUserDigest().getFrom()));
if (!siteIds.isEmpty()) {
MapReportElement reportModel = new MapReportElement();
reportModel.setMaximumZoomLevel(9);
BubbleMapLayer layer = createLayer(siteIds);
reportModel.setLayers(layer);
MapContent content = dispatcher.execute(new GenerateElement<MapContent>(reportModel));
databaseModel.setContent(content);
if (!content.getMarkers().isEmpty()) {
reportModel.setContent(content);
GeneratedResource storage = storageProvider.create("image/png", "map.png");
try (OutputStream outputStream = storage.openOutputStream()) {
imageMapRenderer.render(reportModel, outputStream);
}
databaseModel.setUrl(storage.getDownloadUri());
}
}
}
Aggregations