details:   https://code.openbravo.com/erp/devel/pi/rev/112334d02c09
changeset: 31028:112334d02c09
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Wed Dec 21 11:32:24 2016 +0100
summary:   fixes issue 34796: Ability to compile subreports in process 
definition reports

A new method isCompilingSubreports() has been added. This method can be 
overriden by those handlers extending BaseReportActionHandler that need to 
compile sub-reports at runtime. In that case this method must return true.

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java
 |  30 +++++-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
          |  44 +++++-----
 2 files changed, 45 insertions(+), 29 deletions(-)

diffs (142 lines):

diff -r b6cf90d3df89 -r 112334d02c09 
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java
 Wed Dec 21 10:52:39 2016 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java
 Wed Dec 21 11:32:24 2016 +0100
@@ -337,8 +337,7 @@
 
     log.debug("Report: {}. Start export JR process.", report.getId());
     long t1 = System.currentTimeMillis();
-    doJRExport(jrTemplatePath, expType, jrParams, strTmpFileName, 
getReportConnectionProvider(),
-        getReportData(allParametersMap));
+    doJRExport(jrTemplatePath, expType, strTmpFileName, allParametersMap);
     log.debug("Report: {}. Finish export JR process. Elapsed time: {}", 
report.getId(),
         System.currentTimeMillis() - t1);
 
@@ -552,6 +551,7 @@
    *          map that contains the parameters of the HTTP request and the 
parameters that will be
    *          sent to the jasper report
    *
+   * @return a JRDataSource object containing the report data
    */
   protected JRDataSource getReportData(Map<String, Object> parameters) {
     return null;
@@ -561,15 +561,29 @@
    * Get the connection provider to use in report generation. Override this 
method to put logic for
    * getting the connection provider
    *
+   * @return the ConnectionProvider to use during the report generation
    */
   protected ConnectionProvider getReportConnectionProvider() {
     return null;
   }
 
-  private static void doJRExport(String jrTemplatePath, ExportType expType,
-      Map<String, Object> parameters, String strFileName, ConnectionProvider 
connection,
-      JRDataSource data) {
+  /**
+   * Override this method to define if the sub-reports generated with the 
handler must be compiled.
+   * If true, it will compile all sub-report jrxml files placed in the same 
folder as the main
+   * report and whose related parameter name starts with SUBREP_
+   *
+   * @return true if the handler must compile the sub-reports. Otherwise, it 
returns false.
+   */
+  protected boolean isCompilingSubreports() {
+    return false;
+  }
+
+  private void doJRExport(String jrTemplatePath, ExportType expType, String 
strFileName,
+      Map<String, Object> parameters) {
     ReportSemaphoreHandling.getInstance().acquire();
+    @SuppressWarnings("unchecked")
+    Map<String, Object> jrParameters = (Map<String, Object>) parameters
+        .get(JASPER_REPORT_PARAMETERS);
     Map<Object, Object> localExportParameters = null;
     try {
       if (ExportType.HTML.equals(expType)) {
@@ -580,8 +594,10 @@
         localExportParameters.put(ReportingUtils.IMAGES_URI, localAddress
             + "/servlets/image?image={0}");
       }
-      ReportingUtils.exportJR(jrTemplatePath, expType, parameters, 
strFileName, true, connection,
-          data, localExportParameters);
+      ReportingUtils.exportJR(jrTemplatePath, expType, jrParameters,
+          new File(ReportingUtils.getTempFolder(), strFileName), true,
+          getReportConnectionProvider(), getReportData(parameters), 
localExportParameters,
+          isCompilingSubreports());
     } finally {
       ReportSemaphoreHandling.getInstance().release();
     }
diff -r b6cf90d3df89 -r 112334d02c09 
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
  Wed Dec 21 10:52:39 2016 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
  Wed Dec 21 11:32:24 2016 +0100
@@ -36,6 +36,24 @@
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
 
+import org.openbravo.base.ConfigParameters;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.kernel.reference.UIDefinitionController;
+import 
org.openbravo.client.kernel.reference.UIDefinitionController.FormatDefinition;
+import org.openbravo.dal.core.DalContextListener;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.JRFormatFactory;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.model.ad.utility.FileType;
+import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.uiTranslation.TranslationHandler;
+import org.openbravo.utils.Replace;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import net.sf.jasperreports.engine.JRDataSource;
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRParameter;
@@ -68,24 +86,6 @@
 import net.sf.jasperreports.j2ee.servlets.ImageServlet;
 import net.sf.jasperreports.web.util.WebHtmlResourceHandler;
 
-import org.openbravo.base.ConfigParameters;
-import org.openbravo.base.exception.OBException;
-import org.openbravo.base.session.OBPropertiesProvider;
-import org.openbravo.client.kernel.reference.UIDefinitionController;
-import 
org.openbravo.client.kernel.reference.UIDefinitionController.FormatDefinition;
-import org.openbravo.dal.core.DalContextListener;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.database.ConnectionProvider;
-import org.openbravo.erpCommon.utility.JRFormatFactory;
-import org.openbravo.erpCommon.utility.OBMessageUtils;
-import org.openbravo.model.ad.utility.FileType;
-import org.openbravo.service.db.DalConnectionProvider;
-import org.openbravo.uiTranslation.TranslationHandler;
-import org.openbravo.utils.Replace;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /** Utilities to generate jasper reports */
 public class ReportingUtils {
   /**
@@ -192,8 +192,8 @@
    *          Additional export parameters than can be added to configure the 
resulting report.
    * @param compileSubreports
    *          A flag to indicate if the sub-reports should be compiled too. If 
true, the sub-report
-   *          jrxml files should be placed in the same folder as the main 
report and their name
-   *          should start with SUBREP_
+   *          jrxml files should be placed in the same folder as the main 
report and their related
+   *          parameter name should start with SUBREP_
    * @throws OBException
    *           In case there is any error generating the report an exception 
is thrown with the
    *           error message.
@@ -264,8 +264,8 @@
    *          Additional export parameters than can be added to configure the 
resulting report.
    * @param compileSubreports
    *          A flag to indicate if the sub-reports should be compiled too. If 
true, the sub-report
-   *          jrxml files should be placed in the same folder as the main 
report and their name
-   *          should start with SUBREP_
+   *          jrxml files should be placed in the same folder as the main 
report and their related
+   *          parameter name should start with SUBREP_
    * @throws OBException
    *           In case there is any error generating the report an exception 
is thrown with the
    *           error message.

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to