Search in sources :

Example 1 with UrlResult

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

the class ExportDialog method export.

public void export(String filename, ReportElement model, Format format) {
    show();
    bar.updateText(I18N.CONSTANTS.exportProgress());
    bar.auto();
    RenderElement command = new RenderElement(model, format);
    command.setFilename(filename);
    dispatcher.execute(command, new AsyncCallback<UrlResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert(I18N.CONSTANTS.export(), I18N.CONSTANTS.serverError(), new Listener<MessageBoxEvent>() {

                @Override
                public void handleEvent(MessageBoxEvent be) {
                    ExportDialog.this.hide();
                }
            });
        }

        @Override
        public void onSuccess(UrlResult result) {
            if (!canceled) {
                bar.reset();
                bar.updateProgress(1.0, I18N.CONSTANTS.downloadReady());
                button.setText(I18N.CONSTANTS.close());
                tryStartDownloadWithIframe(result.getUrl());
                downloadLink.getElement().setAttribute("href", result.getUrl());
                downloadLink.setVisible(true);
                layout(true);
            }
        }
    });
}
Also used : MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) RenderElement(org.activityinfo.shared.command.RenderElement) Listener(com.extjs.gxt.ui.client.event.Listener) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener) UrlResult(org.activityinfo.shared.command.result.UrlResult)

Example 2 with UrlResult

use of org.activityinfo.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());
        TempStorage storage = storageProvider.allocateTemporaryFile(renderer.getMimeType(), cmd.getFilename() + renderer.getFileSuffix());
        LOGGER.fine("Rendering element: " + cmd + "\nURL: " + storage.getUrl());
        try {
            generator.generateElement(user, cmd.getElement(), new Filter(), new DateRange());
            renderer.render(cmd.getElement(), storage.getOutputStream());
        } finally {
            try {
                storage.getOutputStream().close();
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Exception while closing storage: " + e.getMessage(), e);
            }
        }
        return new UrlResult(storage.getUrl());
    } catch (Exception e) {
        throw new RuntimeException("Exception generating export", e);
    }
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) TempStorage(org.activityinfo.server.report.output.TempStorage) Filter(org.activityinfo.shared.command.Filter) Renderer(org.activityinfo.server.report.renderer.Renderer) CommandException(org.activityinfo.shared.exception.CommandException) UrlResult(org.activityinfo.shared.command.result.UrlResult)

Aggregations

UrlResult (org.activityinfo.shared.command.result.UrlResult)2 Listener (com.extjs.gxt.ui.client.event.Listener)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 TempStorage (org.activityinfo.server.report.output.TempStorage)1 Renderer (org.activityinfo.server.report.renderer.Renderer)1 Filter (org.activityinfo.shared.command.Filter)1 RenderElement (org.activityinfo.shared.command.RenderElement)1 CommandException (org.activityinfo.shared.exception.CommandException)1 DateRange (org.activityinfo.shared.report.model.DateRange)1