Search in sources :

Example 1 with TempStorage

use of org.activityinfo.server.report.output.TempStorage in project activityinfo by bedatadriven.

the class ChartRendererJC method renderToUrl.

public String renderToUrl(PivotChartReportElement element, boolean includeTitle, StorageProvider istorageProvider, int width, int height, int dpi) throws IOException {
    try {
        Chart chart = createChart(element, includeTitle, width, height, dpi);
        TempStorage storage = istorageProvider.allocateTemporaryFile(null, "activityinfo.jpg");
        JPEGEncoder.encode(chart, 0.75f, storage.getOutputStream());
        return storage.getUrl();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : TempStorage(org.activityinfo.server.report.output.TempStorage) AxisChart(org.krysalis.jcharts.axisChart.AxisChart) Chart(org.krysalis.jcharts.Chart) PropertyException(org.krysalis.jcharts.properties.PropertyException) ReportModelException(org.activityinfo.shared.exception.ReportModelException) ChartDataException(org.krysalis.jcharts.chartData.ChartDataException) IOException(java.io.IOException)

Example 2 with TempStorage

use of org.activityinfo.server.report.output.TempStorage 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

TempStorage (org.activityinfo.server.report.output.TempStorage)2 IOException (java.io.IOException)1 Renderer (org.activityinfo.server.report.renderer.Renderer)1 Filter (org.activityinfo.shared.command.Filter)1 UrlResult (org.activityinfo.shared.command.result.UrlResult)1 CommandException (org.activityinfo.shared.exception.CommandException)1 ReportModelException (org.activityinfo.shared.exception.ReportModelException)1 DateRange (org.activityinfo.shared.report.model.DateRange)1 Chart (org.krysalis.jcharts.Chart)1 AxisChart (org.krysalis.jcharts.axisChart.AxisChart)1 ChartDataException (org.krysalis.jcharts.chartData.ChartDataException)1 PropertyException (org.krysalis.jcharts.properties.PropertyException)1