Add getTranslatedJasperReport method into the ReportingUtils class
authorCarlos Aristu <carlos.aristu@openbravo.com>
Mon, 11 May 2015 19:39:15 +0200
changeset 26743 05633081f012
parent 26742 308acb16ee13
child 26744 94b4b48800a5
Add getTranslatedJasperReport method into the ReportingUtils class
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_reports/ReportReconciliation.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
src/org/openbravo/erpCommon/ad_reports/ReportTaxInvoiceJR.java
src/org/openbravo/erpCommon/ad_reports/ReportWorkRequirementDaily.java
src/org/openbravo/erpCommon/utility/Utility.java
src/org/openbravo/erpReports/RptC_Remittance.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_reports/ReportReconciliation.java	Mon May 11 13:33:21 2015 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_reports/ReportReconciliation.java	Mon May 11 19:39:15 2015 +0200
@@ -39,10 +39,10 @@
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.financialmgmt.payment.FIN_BankStatement;
 import org.openbravo.model.financialmgmt.payment.FIN_BankStatementLine;
 import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
@@ -107,15 +107,15 @@
     JasperReport subReportOutstandingDeposit;
     JasperReport subReportUnreconciledBankStatementLines;
     try {
-      subReportOutstandingPayment = Utility.getTranslatedJasperReport(this, strBaseDesign
+      subReportOutstandingPayment = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/advpaymentmngt/ad_reports/OutstandingPayment.jrxml",
           vars.getLanguage(), strBaseDesign);
 
-      subReportOutstandingDeposit = Utility.getTranslatedJasperReport(this, strBaseDesign
+      subReportOutstandingDeposit = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/advpaymentmngt/ad_reports/OutstandingDeposit.jrxml",
           vars.getLanguage(), strBaseDesign);
 
-      subReportUnreconciledBankStatementLines = Utility.getTranslatedJasperReport(this,
+      subReportUnreconciledBankStatementLines = ReportingUtils.getTranslatedJasperReport(this,
           strBaseDesign
               + "/org/openbravo/advpaymentmngt/ad_reports/UnreconciledBankStatement.jrxml",
           vars.getLanguage(), strBaseDesign);
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java	Mon May 11 13:33:21 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java	Mon May 11 19:39:15 2015 +0200
@@ -76,9 +76,9 @@
 import org.openbravo.erpCommon.utility.JRFormatFactory;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.ReportDesignBO;
-import org.openbravo.erpCommon.utility.Utility;
 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;
@@ -849,7 +849,7 @@
 
       if (jasperFilePath.endsWith("jrxml")) {
         String strBaseDesign = DalContextListener.getServletContext().getRealPath("");
-        JasperReport jReport = Utility.getTranslatedJasperReport(new DalConnectionProvider(false),
+        JasperReport jReport = getTranslatedJasperReport(new DalConnectionProvider(false),
             jasperFilePath, language, strBaseDesign);
         if (connectionProvider != null) {
           if (compileSubreports) {
@@ -966,7 +966,7 @@
       String baseDesignPath, ConnectionProvider connectionProvider, String language) {
     JasperReport jasperReportLines = null;
     try {
-      jasperReportLines = Utility.getTranslatedJasperReport(connectionProvider, templateLocation
+      jasperReportLines = getTranslatedJasperReport(connectionProvider, templateLocation
           + subReportFileName, language, baseDesignPath);
     } catch (final JRException e1) {
       log.error(e1.getMessage());
@@ -976,6 +976,49 @@
   }
 
   /**
+   * Generates a compiled and translated report.
+   * 
+   * @param conn
+   *          The connection provider used to get the translations.
+   * @param reportName
+   *          The path to the JR template of the report.
+   * @param language
+   *          Language to be used when generating the report.
+   * @param baseDesignPath
+   *          Base design path.
+   * @return A JasperReport object with the compiled and translated report.
+   * @throws JRException
+   *           In case there is any error generating the translated report an exception is thrown
+   *           with the error message.
+   */
+  public static JasperReport getTranslatedJasperReport(ConnectionProvider conn, String reportName,
+      String language, String baseDesignPath) throws JRException {
+
+    log.debug("translate report: " + reportName + " for language: " + language);
+
+    File reportFile = new File(reportName);
+
+    InputStream reportInputStream = null;
+    if (reportFile.exists()) {
+      TranslationHandler handler = new TranslationHandler(conn);
+      handler.prepareFile(reportName, language, reportFile, baseDesignPath);
+      reportInputStream = handler.getInputStream();
+    }
+    JasperDesign jasperDesign;
+    if (reportInputStream != null) {
+      log.debug("Jasper report being created with inputStream.");
+      jasperDesign = JRXmlLoader.load(reportInputStream);
+    } else {
+      log.debug("Jasper report being created with strReportName.");
+      jasperDesign = JRXmlLoader.load(reportName);
+    }
+
+    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
+
+    return jasperReport;
+  }
+
+  /**
    * Compiles a jrxml file generating a JasperReport object.
    * 
    * @param jasperFilePath
--- a/src/org/openbravo/erpCommon/ad_reports/ReportTaxInvoiceJR.java	Mon May 11 13:33:21 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportTaxInvoiceJR.java	Mon May 11 19:39:15 2015 +0200
@@ -32,6 +32,7 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.businessUtility.Tree;
 import org.openbravo.erpCommon.businessUtility.TreeData;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
@@ -173,16 +174,16 @@
     String strLanguage = vars.getLanguage();
     String strBaseDesign = getBaseDesignPath(strLanguage);
     try {
-      jasperSale = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperSale = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportTaxInvoiceSale.jrxml", vars.getLanguage(),
           strBaseDesign);
-      jasperSaleForeign = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperSaleForeign = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportTaxInvoiceSaleForeign.jrxml",
           vars.getLanguage(), strBaseDesign);
-      jasperPurchase = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperPurchase = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportTaxInvoicePurchase.jrxml",
           vars.getLanguage(), strBaseDesign);
-      jasperPurchaseForeign = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperPurchaseForeign = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportTaxInvoicePurchaseForeign.jrxml",
           vars.getLanguage(), strBaseDesign);
 
--- a/src/org/openbravo/erpCommon/ad_reports/ReportWorkRequirementDaily.java	Mon May 11 13:33:21 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportWorkRequirementDaily.java	Mon May 11 19:39:15 2015 +0200
@@ -31,6 +31,7 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.LeftTabsBar;
@@ -94,7 +95,7 @@
     String strBaseDesign = getBaseDesignPath(strLanguage);
     JasperReport jasperReportProducts;
     try {
-      jasperReportProducts = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperReportProducts = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/SubreportWorkRequirementDaily.jrxml",
           vars.getLanguage(), strBaseDesign);
     } catch (JRException e) {
@@ -104,7 +105,7 @@
 
     JasperReport jasperReportProducts2;
     try {
-      jasperReportProducts2 = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperReportProducts2 = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/SubreportWorkRequirementDaily2.jrxml",
           vars.getLanguage(), strBaseDesign);
     } catch (JRException e) {
--- a/src/org/openbravo/erpCommon/utility/Utility.java	Mon May 11 13:33:21 2015 +0200
+++ b/src/org/openbravo/erpCommon/utility/Utility.java	Mon May 11 19:39:15 2015 +0200
@@ -31,7 +31,6 @@
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
@@ -60,10 +59,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.log4j.Logger;
@@ -74,6 +70,7 @@
 import org.openbravo.base.secureApp.OrgTree;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
@@ -94,7 +91,6 @@
 import org.openbravo.model.common.enterprise.OrganizationInformation;
 import org.openbravo.model.common.geography.Country;
 import org.openbravo.model.common.geography.Location;
-import org.openbravo.uiTranslation.TranslationHandler;
 import org.openbravo.utils.FileUtility;
 import org.openbravo.utils.FormatUtilities;
 
@@ -1792,29 +1788,7 @@
 
   public static JasperReport getTranslatedJasperReport(ConnectionProvider conn, String reportName,
       String language, String baseDesignPath) throws JRException {
-
-    log4j.debug("translate report: " + reportName + " for language: " + language);
-
-    File reportFile = new File(reportName);
-
-    InputStream reportInputStream = null;
-    if (reportFile.exists()) {
-      TranslationHandler handler = new TranslationHandler(conn);
-      handler.prepareFile(reportName, language, reportFile, baseDesignPath);
-      reportInputStream = handler.getInputStream();
-    }
-    JasperDesign jasperDesign;
-    if (reportInputStream != null) {
-      log4j.debug("Jasper report being created with inputStream.");
-      jasperDesign = JRXmlLoader.load(reportInputStream);
-    } else {
-      log4j.debug("Jasper report being created with strReportName.");
-      jasperDesign = JRXmlLoader.load(reportName);
-    }
-
-    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
-
-    return jasperReport;
+    return ReportingUtils.getTranslatedJasperReport(conn, reportName, language, baseDesignPath);
   }
 
   /**
--- a/src/org/openbravo/erpReports/RptC_Remittance.java	Mon May 11 13:33:21 2015 +0200
+++ b/src/org/openbravo/erpReports/RptC_Remittance.java	Mon May 11 19:39:15 2015 +0200
@@ -31,6 +31,7 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.utility.Utility;
 
 public class RptC_Remittance extends HttpSecureAppServlet {
@@ -75,7 +76,7 @@
 
     JasperReport jasperReportLines;
     try {
-      jasperReportLines = Utility.getTranslatedJasperReport(this, strBaseDesign
+      jasperReportLines = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
           + "/org/openbravo/erpReports/RptC_Remittance_Lines.jrxml", vars.getLanguage(),
           strBaseDesign);
     } catch (JRException e) {