Search in sources :

Example 1 with ReportFormatFactory

use of com.qcadoo.report.internal.util.ReportFormatFactory in project qcadoo by qcadoo.

the class ReportServiceImpl method generateReport.

private byte[] generateReport(final JasperReport template, final ReportType type, final Map<String, Object> parameters, final Locale locale) throws ReportException {
    Session session = null;
    try {
        session = sessionFactory.openSession();
        parameters.put(JRParameter.REPORT_LOCALE, locale);
        parameters.put("Author", pdfHelper.getDocumentAuthor());
        parameters.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session);
        ResourceBundle resourceBundle = new MessageSourceResourceBundle(messageSource, locale);
        parameters.put(JRParameter.REPORT_RESOURCE_BUNDLE, resourceBundle);
        parameters.put(JRParameter.REPORT_FORMAT_FACTORY, new ReportFormatFactory());
        JasperPrint jasperPrint = JasperFillManager.fillReport(template, parameters);
        JRExporter exporter = getExporter(type);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, stream);
        exporter.exportReport();
        return stream.toByteArray();
    } catch (JRException e) {
        throw new ReportException(ReportException.Type.GENERATE_REPORT_EXCEPTION, e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : MessageSourceResourceBundle(org.springframework.context.support.MessageSourceResourceBundle) JRException(net.sf.jasperreports.engine.JRException) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ReportFormatFactory(com.qcadoo.report.internal.util.ReportFormatFactory) ReportException(com.qcadoo.report.api.ReportException) MessageSourceResourceBundle(org.springframework.context.support.MessageSourceResourceBundle) ResourceBundle(java.util.ResourceBundle) JRExporter(net.sf.jasperreports.engine.JRExporter) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Session(org.hibernate.Session)

Aggregations

ReportException (com.qcadoo.report.api.ReportException)1 ReportFormatFactory (com.qcadoo.report.internal.util.ReportFormatFactory)1 ResourceBundle (java.util.ResourceBundle)1 JRException (net.sf.jasperreports.engine.JRException)1 JRExporter (net.sf.jasperreports.engine.JRExporter)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Session (org.hibernate.Session)1 MessageSourceResourceBundle (org.springframework.context.support.MessageSourceResourceBundle)1