Class ReportingUtils


  • public class ReportingUtils
    extends Object
    Utilities to generate jasper reports
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ReportingUtils.ExportType
      enum with the supported Export Outputs.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String IMAGES_URI
      Used to set the parameter with the URI to retrieve images in HTML reports.
      static String JASPER_PARAM_HBSESSION
      Used to set a report parameter with an org.hibernate.Session object with the current hibernate.
      static String JASPER_PARAM_OBCONTEXT
      Used to set a report parameter with a org.openbravo.dal.core.OBContext which contains the OBContext that has launched the report.
      static String PDF_JAVASCRIPT
      Used to set Javascript content inside a PDF report.
    • Constructor Summary

      Constructors 
      Constructor Description
      ReportingUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static net.sf.jasperreports.engine.JasperReport compileReport​(String jasperFilePath)
      Compiles a jrxml file generating a JasperReport object.
      static void concatPDFReport​(List<net.sf.jasperreports.engine.JasperPrint> jasperPrintList, boolean createBookmarks, OutputStream outputStream)  
      static void concatPDFReport​(List<net.sf.jasperreports.engine.JasperPrint> jasperPrintList, boolean createBookmarks, OutputStream outputStream, net.sf.jasperreports.export.SimplePdfExporterConfiguration reportConfiguration)
      Returns a PDF file into an output stream as result of the concatenation of the JasperPrint objects list passed as parameter.
      static void concatPDFReportEncrypted​(List<net.sf.jasperreports.engine.JasperPrint> jasperPrintList, boolean createBookmarks, String userPassword, String ownerPassword, OutputStream outputStream)
      Returns an encrypted PDF file into an output stream as result of the concatenation of the JasperPrint objects list passed as parameter.
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, File target, boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data, Map<Object,​Object> additionalExportParameters)
      Exports the report to a file.
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, File target, boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data, Map<Object,​Object> additionalExportParameters, boolean compileSubreports)
      Deprecated.
      The compileSubreports parameter has no effect.
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, OutputStream outputStream, boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data, Map<Object,​Object> additionalExportParameters)
      Exports the report to an output stream.
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, OutputStream outputStream, boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data, Map<Object,​Object> additionalExportParameters, boolean compileSubreports)
      Deprecated.
      The compileSubreports parameter has no effect.
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, String strFileName)  
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, String strFileName, boolean addProcessDefinitionParameters)  
      static void exportJR​(String jasperFilePath, ReportingUtils.ExportType expType, Map<String,​Object> parameters, String strFileName, boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data, Map<Object,​Object> additionalExportParameters)  
      static net.sf.jasperreports.engine.JasperPrint generateJasperPrint​(String jasperFilePath, Map<String,​Object> parameters, boolean compileSubreports, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data)
      Deprecated.
      The compileSubreports parameter has no effect.
      static net.sf.jasperreports.engine.JasperPrint generateJasperPrint​(String jasperFilePath, Map<String,​Object> parameters, ConnectionProvider connectionProvider, net.sf.jasperreports.engine.JRDataSource data)
      Generates a compiled, translated and filled report into a JasperPrint object.
      static String getBaseDesign()
      Returns the relative path to the default design sub-folder within the context's base design folder.
      static ReportingUtils.ExportType getExcelExportType()
      Returns the format to be used when exporting Excel reports.
      static String getRealBaseDesignPath()  
      static String getTempFolder()
      Returns temporary directory to save generated reports.
      static net.sf.jasperreports.engine.JasperReport getTranslatedJasperReport​(ConnectionProvider conn, String reportName, String language)
      Generates a compiled and translated report to the language passed as parameter.
      static net.sf.jasperreports.engine.JasperReport getTranslatedJasperReport​(ConnectionProvider conn, String reportName, String language, String baseDesignPath)
      static void saveCsvReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput, net.sf.jasperreports.export.SimpleWriterExporterOutput exporterOutput, net.sf.jasperreports.export.SimpleCsvReportConfiguration exportConfiguration)
      Generates a CSV report using the SimpleExporterInput, SimpleWriterExporterOutput and SimpleCsvReportConfiguration received as parameters.
      static void saveExcelReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput, net.sf.jasperreports.export.SimpleOutputStreamExporterOutput exporterOutput, net.sf.jasperreports.export.SimpleXlsReportConfiguration exportConfiguration)
      Generates an XLS report using the SimpleExporterInput, SimpleOutputStreamExporterOutput and SimpleXlsReportConfiguration received as parameters.
      static void saveExcelReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput, net.sf.jasperreports.export.SimpleOutputStreamExporterOutput exporterOutput, net.sf.jasperreports.export.SimpleXlsxReportConfiguration exportConfiguration)
      Generates an XLSX report using the SimpleExporterInput, SimpleOutputStreamExporterOutput and SimpleXlsxReportConfiguration received as parameters.
      static void saveHTMLReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput, net.sf.jasperreports.export.SimpleHtmlExporterOutput exporterOutput, net.sf.jasperreports.export.SimpleHtmlReportConfiguration exportConfiguration)
      Generates an HTML report using the SimpleExporterInput, SimpleHtmlExporterOutput and SimpleHtmlReportConfiguration received as parameters.
      static void savePDFReportToOutputStream​(net.sf.jasperreports.engine.JasperPrint jasperPrint, Map<Object,​Object> exportParameters, OutputStream outputStream)
      Generates a PDF report from a pre-compiled report and returns it into an output stream.
      static void saveReport​(net.sf.jasperreports.engine.JasperPrint jasperPrint, ReportingUtils.ExportType expType, Map<Object,​Object> exportParameters, File target)
      Saves a pre-compiled report into a file.
      static void saveReport​(net.sf.jasperreports.engine.JasperPrint jasperPrint, ReportingUtils.ExportType expType, Map<Object,​Object> exportParameters, OutputStream outputStream)
      Returns a pre-compiled report into an Output Stream.
      static void saveTxtReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput, net.sf.jasperreports.export.SimpleWriterExporterOutput exporterOutput, net.sf.jasperreports.export.SimpleTextExporterConfiguration textExporterConfiguration, net.sf.jasperreports.export.SimpleTextReportConfiguration textReportConfiguration)
      Generates a plain text report using the SimpleExporterInput, SimpleWriterExporterOutput, SimpleTextExporterConfiguration and SimpleTextReportConfiguration received as parameters.
    • Field Detail

      • JASPER_PARAM_OBCONTEXT

        public static final String JASPER_PARAM_OBCONTEXT
        Used to set a report parameter with a org.openbravo.dal.core.OBContext which contains the OBContext that has launched the report.
        See Also:
        Constant Field Values
      • JASPER_PARAM_HBSESSION

        public static final String JASPER_PARAM_HBSESSION
        Used to set a report parameter with an org.hibernate.Session object with the current hibernate. session.
        See Also:
        Constant Field Values
      • IMAGES_URI

        public static final String IMAGES_URI
        Used to set the parameter with the URI to retrieve images in HTML reports.
        See Also:
        Constant Field Values
      • PDF_JAVASCRIPT

        public static final String PDF_JAVASCRIPT
        Used to set Javascript content inside a PDF report.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ReportingUtils

        public ReportingUtils()
    • Method Detail

      • exportJR

        public static void exportJR​(String jasperFilePath,
                                    ReportingUtils.ExportType expType,
                                    Map<String,​Object> parameters,
                                    File target,
                                    boolean addProcessDefinitionParameters,
                                    ConnectionProvider connectionProvider,
                                    net.sf.jasperreports.engine.JRDataSource data,
                                    Map<Object,​Object> additionalExportParameters)
                             throws OBException
        Exports the report to a file. This method will try to compile the sub-reports (if any). Note that the sub-reports to be compiled will be the .jrxml files placed in the same folder as the main report and whose related parameter name starts with SUBREP_.
        Parameters:
        jasperFilePath - The path to the JR template of the report.
        expType - The desired output type of the report.
        parameters - The parameters to be sent to Jasper Report.
        target - The file used to return the report.
        addProcessDefinitionParameters - A flag to indicate if the parameters needed to print a report from a Process Definition should be added.
        connectionProvider - A connection provider in case the report needs it.
        data - The data to be used in the report, if required.
        additionalExportParameters - Additional export parameters than can be added to configure the resulting report.
        Throws:
        OBException - In case there is any error generating the report an exception is thrown with the error message.
      • exportJR

        public static void exportJR​(String jasperFilePath,
                                    ReportingUtils.ExportType expType,
                                    Map<String,​Object> parameters,
                                    OutputStream outputStream,
                                    boolean addProcessDefinitionParameters,
                                    ConnectionProvider connectionProvider,
                                    net.sf.jasperreports.engine.JRDataSource data,
                                    Map<Object,​Object> additionalExportParameters)
                             throws OBException
        Exports the report to an output stream. This method will try to compile the sub-reports (if any). Note that the sub-reports to be compiled will be the .jrxml files placed in the same folder as the main report and whose related parameter name starts with SUBREP_.
        Parameters:
        jasperFilePath - The path to the JR template of the report.
        expType - The desired output type of the report.
        parameters - The parameters to be sent to Jasper Report.
        outputStream - An output stream used to return the report.
        addProcessDefinitionParameters - A flag to indicate if the parameters needed to print a report from a Process Definition should be added.
        connectionProvider - A connection provider in case the report needs it.
        data - The data to be used in the report, if required.
        additionalExportParameters - Additional export parameters than can be added to configure the resulting report.
        Throws:
        OBException - In case there is any error generating the report an exception is thrown with the error message.
      • saveReport

        public static void saveReport​(net.sf.jasperreports.engine.JasperPrint jasperPrint,
                                      ReportingUtils.ExportType expType,
                                      Map<Object,​Object> exportParameters,
                                      File target)
                               throws net.sf.jasperreports.engine.JRException
        Saves a pre-compiled report into a file.
        Parameters:
        jasperPrint - JasperPrint object which contains a compiled report.
        expType - The desired output type of the report.
        exportParameters - Export parameters than can be added to configure the resulting report.
        target - The file used to return the report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error saving the report an exception is thrown with the error message.
      • saveReport

        public static void saveReport​(net.sf.jasperreports.engine.JasperPrint jasperPrint,
                                      ReportingUtils.ExportType expType,
                                      Map<Object,​Object> exportParameters,
                                      OutputStream outputStream)
                               throws net.sf.jasperreports.engine.JRException
        Returns a pre-compiled report into an Output Stream.
        Parameters:
        jasperPrint - JasperPrint object which contains a compiled report.
        expType - The desired output type of the report.
        exportParameters - Export parameters than can be added to configure the resulting report.
        outputStream - The output stream used to return the report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • saveHTMLReport

        public static void saveHTMLReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput,
                                          net.sf.jasperreports.export.SimpleHtmlExporterOutput exporterOutput,
                                          net.sf.jasperreports.export.SimpleHtmlReportConfiguration exportConfiguration)
                                   throws net.sf.jasperreports.engine.JRException
        Generates an HTML report using the SimpleExporterInput, SimpleHtmlExporterOutput and SimpleHtmlReportConfiguration received as parameters.
        Parameters:
        exporterInput - SimpleExporterInput object with the input data.
        exporterOutput - SimpleHtmlExporterOutput object with the output data.
        exportConfiguration - SimpleHtmlReportConfiguration with the configuration data.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • savePDFReportToOutputStream

        public static void savePDFReportToOutputStream​(net.sf.jasperreports.engine.JasperPrint jasperPrint,
                                                       Map<Object,​Object> exportParameters,
                                                       OutputStream outputStream)
                                                throws net.sf.jasperreports.engine.JRException
        Generates a PDF report from a pre-compiled report and returns it into an output stream.
        Parameters:
        jasperPrint - JasperPrint object which contains a compiled report.
        exportParameters - Export parameters than can be added to configure the resulting report.
        outputStream - The output stream used to return the report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • saveExcelReport

        public static void saveExcelReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput,
                                           net.sf.jasperreports.export.SimpleOutputStreamExporterOutput exporterOutput,
                                           net.sf.jasperreports.export.SimpleXlsReportConfiguration exportConfiguration)
                                    throws net.sf.jasperreports.engine.JRException
        Generates an XLS report using the SimpleExporterInput, SimpleOutputStreamExporterOutput and SimpleXlsReportConfiguration received as parameters.
        Parameters:
        exporterInput - SimpleExporterInput object with the input data.
        exporterOutput - SimpleOutputStreamExporterOutput object with the output data.
        exportConfiguration - SimpleXlsReportConfiguration with the configuration data.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • saveExcelReport

        public static void saveExcelReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput,
                                           net.sf.jasperreports.export.SimpleOutputStreamExporterOutput exporterOutput,
                                           net.sf.jasperreports.export.SimpleXlsxReportConfiguration exportConfiguration)
                                    throws net.sf.jasperreports.engine.JRException
        Generates an XLSX report using the SimpleExporterInput, SimpleOutputStreamExporterOutput and SimpleXlsxReportConfiguration received as parameters.
        Parameters:
        exporterInput - SimpleExporterInput object with the input data.
        exporterOutput - SimpleOutputStreamExporterOutput object with the output data.
        exportConfiguration - SimpleXlsxReportConfiguration with the configuration data.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • saveCsvReport

        public static void saveCsvReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput,
                                         net.sf.jasperreports.export.SimpleWriterExporterOutput exporterOutput,
                                         net.sf.jasperreports.export.SimpleCsvReportConfiguration exportConfiguration)
                                  throws net.sf.jasperreports.engine.JRException
        Generates a CSV report using the SimpleExporterInput, SimpleWriterExporterOutput and SimpleCsvReportConfiguration received as parameters.
        Parameters:
        exporterInput - SimpleExporterInput object with the input data.
        exporterOutput - SimpleWriterExporterOutput object with the output data.
        exportConfiguration - SimpleCsvReportConfiguration with the configuration data.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • saveTxtReport

        public static void saveTxtReport​(net.sf.jasperreports.export.SimpleExporterInput exporterInput,
                                         net.sf.jasperreports.export.SimpleWriterExporterOutput exporterOutput,
                                         net.sf.jasperreports.export.SimpleTextExporterConfiguration textExporterConfiguration,
                                         net.sf.jasperreports.export.SimpleTextReportConfiguration textReportConfiguration)
                                  throws net.sf.jasperreports.engine.JRException
        Generates a plain text report using the SimpleExporterInput, SimpleWriterExporterOutput, SimpleTextExporterConfiguration and SimpleTextReportConfiguration received as parameters.
        Parameters:
        exporterInput - SimpleExporterInput object with the input data.
        exporterOutput - SimpleWriterExporterOutput object with the output data.
        textExporterConfiguration - SimpleTextExporterConfiguration with the configuration data.
        textReportConfiguration - SimpleTextReportConfiguration with the item configuration data.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the report an exception is thrown with the error message.
      • generateJasperPrint

        public static net.sf.jasperreports.engine.JasperPrint generateJasperPrint​(String jasperFilePath,
                                                                                  Map<String,​Object> parameters,
                                                                                  ConnectionProvider connectionProvider,
                                                                                  net.sf.jasperreports.engine.JRDataSource data)
                                                                           throws OBException
        Generates a compiled, translated and filled report into a JasperPrint object.
        Parameters:
        jasperFilePath - The path to the JR template of the report.
        parameters - The parameters to be sent to Jasper Report.
        connectionProvider - A connection provider in case the report needs it.
        data - The data to be used in the report, if required.
        Returns:
        A JasperPrint object with the compiled, translated and filled report.
        Throws:
        OBException - In case there is any error processing the report an exception is thrown with the error message.
      • getTranslatedJasperReport

        public static net.sf.jasperreports.engine.JasperReport getTranslatedJasperReport​(ConnectionProvider conn,
                                                                                         String reportName,
                                                                                         String language)
                                                                                  throws net.sf.jasperreports.engine.JRException
        Generates a compiled and translated report to the language passed as parameter.
        Parameters:
        conn - The connection provider used to get the translations.
        reportName - The path to the JR template of the report.
        language - Language to be used when generating the report.
        Returns:
        A JasperReport object with the compiled and translated report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error generating the translated report an exception is thrown with the error message.
      • compileReport

        public static net.sf.jasperreports.engine.JasperReport compileReport​(String jasperFilePath)
                                                                      throws net.sf.jasperreports.engine.JRException
        Compiles a jrxml file generating a JasperReport object.
        Parameters:
        jasperFilePath - The path to the JR template of the report.
        Returns:
        A JasperReport object with the compiled report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error compiling the report an exception is thrown with the error message.
      • concatPDFReport

        public static void concatPDFReport​(List<net.sf.jasperreports.engine.JasperPrint> jasperPrintList,
                                           boolean createBookmarks,
                                           OutputStream outputStream,
                                           net.sf.jasperreports.export.SimplePdfExporterConfiguration reportConfiguration)
                                    throws net.sf.jasperreports.engine.JRException
        Returns a PDF file into an output stream as result of the concatenation of the JasperPrint objects list passed as parameter.
        Parameters:
        jasperPrintList - A list of JasperPrint objects.
        createBookmarks - A flag to indicate if the document should contain bookmarks, to mark the beginning of each individual document that was part of the initial document list.
        outputStream - The output stream used for returning the report.
        reportConfiguration - An optional configuration for the report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error compiling the report an exception is thrown with the error message.
      • concatPDFReportEncrypted

        public static void concatPDFReportEncrypted​(List<net.sf.jasperreports.engine.JasperPrint> jasperPrintList,
                                                    boolean createBookmarks,
                                                    String userPassword,
                                                    String ownerPassword,
                                                    OutputStream outputStream)
                                             throws net.sf.jasperreports.engine.JRException
        Returns an encrypted PDF file into an output stream as result of the concatenation of the JasperPrint objects list passed as parameter.
        Parameters:
        jasperPrintList - A list of JasperPrint objects.
        createBookmarks - A flag to indicate if the document should contain bookmarks, to mark the beginning of each individual document that was part of the initial document list.
        userPassword - A String that contains the user password of the resulting document.
        ownerPassword - A String that contains the owner password of the resulting document.
        outputStream - The output stream used for returning the report.
        Throws:
        net.sf.jasperreports.engine.JRException - In case there is any error compiling the report an exception is thrown with the error message.
      • getExcelExportType

        public static ReportingUtils.ExportType getExcelExportType()
        Returns the format to be used when exporting Excel reports.
        Returns:
        a ExportType with the default Excel format (XLS or XLSX).
      • getTempFolder

        public static String getTempFolder()
        Returns temporary directory to save generated reports.
        Returns:
        a String with the temporary directory location.
      • getBaseDesign

        public static String getBaseDesign()
        Returns the relative path to the default design sub-folder within the context's base design folder.
        Returns:
        a String with the relative path to the default design sub-folder.
      • getRealBaseDesignPath

        public static String getRealBaseDesignPath()
        Returns:
        a String with the real path to the design sub-folder.