Search in sources :

Example 6 with GeneratedResource

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();
    }
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) OutputStream(java.io.OutputStream) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 7 with GeneratedResource

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());
        }
    }
}
Also used : MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) DatabaseModel(org.activityinfo.server.digest.geo.GeoDigestModel.DatabaseModel) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) OutputStream(java.io.OutputStream) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) GeneratedResource(org.activityinfo.server.generated.GeneratedResource)

Aggregations

GeneratedResource (org.activityinfo.server.generated.GeneratedResource)7 OutputStream (java.io.OutputStream)4 Filter (org.activityinfo.legacy.shared.command.Filter)2 ExportResult (org.activityinfo.model.job.ExportResult)2 TaskOptions (com.google.appengine.api.taskqueue.TaskOptions)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Map (java.util.Map)1 EffectiveTableModel (org.activityinfo.analysis.table.EffectiveTableModel)1 TableViewModel (org.activityinfo.analysis.table.TableViewModel)1 XlsTableWriter (org.activityinfo.io.xls.XlsTableWriter)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 UrlResult (org.activityinfo.legacy.shared.command.result.UrlResult)1 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 ReportModelException (org.activityinfo.legacy.shared.exception.ReportModelException)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)1 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)1