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);
}
}
});
}
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);
}
}
Aggregations