Search in sources :

Example 1 with UrlResult

use of org.activityinfo.legacy.shared.command.result.UrlResult in project activityinfo by bedatadriven.

the class ExportReportTask method start.

@Override
public void start(final AsyncCallback<ExportDialog.AsyncTaskPoller> callback) {
    RenderElement command = new RenderElement(model, format);
    command.setFilename(filename);
    dispatcher.execute(command, new AsyncCallback<UrlResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(final UrlResult urlResult) {
            callback.onSuccess(new ExportDialog.AsyncTaskPoller() {

                @Override
                public void poll(ExportDialog.ProgressCallback callback) {
                    callback.onDownloadReady(urlResult.getUrl());
                }
            });
        }
    });
}
Also used : RenderElement(org.activityinfo.legacy.shared.command.RenderElement) UrlResult(org.activityinfo.legacy.shared.command.result.UrlResult)

Example 2 with UrlResult

use of org.activityinfo.legacy.shared.command.result.UrlResult 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);
    }
}
Also used : DateRange(org.activityinfo.legacy.shared.reports.model.DateRange) Filter(org.activityinfo.legacy.shared.command.Filter) OutputStream(java.io.OutputStream) Renderer(org.activityinfo.server.report.renderer.Renderer) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) UrlResult(org.activityinfo.legacy.shared.command.result.UrlResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Aggregations

UrlResult (org.activityinfo.legacy.shared.command.result.UrlResult)2 OutputStream (java.io.OutputStream)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 RenderElement (org.activityinfo.legacy.shared.command.RenderElement)1 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)1 GeneratedResource (org.activityinfo.server.generated.GeneratedResource)1 Renderer (org.activityinfo.server.report.renderer.Renderer)1