related to issue 39229: don't use source path for updating ref data
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 20 Sep 2018 14:52:14 +0200
changeset 34781 484a4cb67c8c
parent 34780 b3ead782e3e7
child 34782 5e148ccda173
related to issue 39229: don't use source path for updating ref data
src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData.java
src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData_data.xsql
src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java
--- a/src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData.java	Wed Sep 12 09:27:14 2018 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData.java	Thu Sep 20 14:52:14 2018 +0200
@@ -11,14 +11,13 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2008-2017 Openbravo SLU
+ * All portions are Copyright (C) 2008-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.ad_forms;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
@@ -31,8 +30,10 @@
 import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.businessUtility.InitialSetupUtility;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.modules.ModuleReferenceDataOrgTree;
 import org.openbravo.erpCommon.modules.ModuleUtiltiy;
@@ -43,6 +44,7 @@
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.module.Module;
 import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.ad.utility.DataSet;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.service.db.DataImportService;
@@ -211,24 +213,27 @@
 
         StringBuffer strError = new StringBuffer("");
         for (int j = 0; j < data.length; j++) {
-          String strPath = vars.getSessionValue("#SOURCEPATH");
-          if (!data[j].javapackage.equals("org.openbravo"))
-            strPath = strPath + "/modules/" + data[j].javapackage;
-          strPath = strPath + "/referencedata/standard";
-          File datasetFile = new File(strPath + "/" + Utility.wikifiedName(data[j].datasetname)
-              + ".xml");
-          if (!datasetFile.exists()) {
-            continue;
-          }
+          String fileName = Utility.wikifiedName(data[j].datasetname);
           if (UpdateReferenceDataData.existsOrgModule(cp, vars.getClient(), strOrganization,
               data[j].adModuleId, data[j].version).equals("0")) {
             // Not installed previously
-            String strXml = Utility.fileToString(datasetFile.getPath());
+            OBContext.setAdminMode(true);
+            String strXml;
+            try {
+              strXml = InitialSetupUtility.getDatasetContent(OBDal.getInstance().get(DataSet.class,
+                  data[j].adDatasetId));
+            } catch (IOException ignore) {
+              log4j.error("Error updating reference data for " + fileName, ignore);
+              continue;
+            } finally {
+              OBContext.restorePreviousMode();
+            }
+
             ImportResult myResult = myData.importDataFromXML(
                 OBDal.getInstance().get(Client.class, vars.getClient()),
                 OBDal.getInstance().get(Organization.class, strOrganization), strXml, OBDal
                     .getInstance().get(Module.class, data[j].adModuleId), true);
-            m_info.append(SALTO_LINEA).append("File: ").append(datasetFile.getName()).append(":")
+            m_info.append(SALTO_LINEA).append("File: ").append(fileName).append(":")
                 .append(SALTO_LINEA);
             if (myResult.getLogMessages() != null && !myResult.getLogMessages().equals("")
                 && !myResult.getLogMessages().equals("null")) {
@@ -262,7 +267,7 @@
                   .append(SALTO_LINEA);
             }
           } else {
-            m_info.append(SALTO_LINEA).append("File: ").append(datasetFile.getName()).append(":")
+            m_info.append(SALTO_LINEA).append("File: ").append(fileName).append(":")
                 .append(SALTO_LINEA);
             m_info
                 .append(SALTO_LINEA)
--- a/src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData_data.xsql	Wed Sep 12 09:27:14 2018 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/UpdateReferenceData_data.xsql	Thu Sep 20 14:52:14 2018 +0200
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2017 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,7 +27,7 @@
     <Sql>
       <![CDATA[
       SELECT '' as id, '' as NAME, '' AS HASCHARTOFACCOUNTS, '' AS  ISTRANSLATIONMODULE,
-      '' AS AD_MODULE_ID, '' AS PATH, '' AS  JAVAPACKAGE, '' AS DATASETNAME, '' AS VERSION, '' AS CHECKSUM
+      '' AS AD_MODULE_ID, '' AS PATH, '' AS  JAVAPACKAGE, '' AS DATASETNAME, '' AS VERSION, '' AS CHECKSUM, '' AS AD_DATASET_ID
       FROM DUAL
       ]]>
     </Sql>
@@ -53,7 +53,7 @@
     <Sql>
       <![CDATA[
       SELECT AD_MODULE.NAME, AD_MODULE.HASCHARTOFACCOUNTS, AD_MODULE.ISTRANSLATIONMODULE, 
-      AD_MODULE.AD_MODULE_ID , AD_MODULE.JAVAPACKAGE, AD_DATASET.NAME AS DATASETNAME, AD_MODULE.VERSION, AD_DATASET.CHECKSUM
+      AD_MODULE.AD_MODULE_ID , AD_MODULE.JAVAPACKAGE, AD_DATASET.NAME AS DATASETNAME, AD_MODULE.VERSION, AD_DATASET.CHECKSUM, AD_DATASET.AD_DATASET_ID
       FROM AD_MODULE, AD_DATASET
       WHERE AD_MODULE.AD_MODULE_ID = AD_DATASET.AD_MODULE_ID      
       AND AD_MODULE.AD_MODULE_ID IN ('1')
--- a/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java	Wed Sep 12 09:27:14 2018 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java	Thu Sep 20 14:52:14 2018 +0200
@@ -1719,7 +1719,7 @@
     return myResult;
   }
 
-  private static String getDatasetContent(DataSet dataset) throws IOException {
+  public static String getDatasetContent(DataSet dataset) throws IOException {
     String fileName = Utility.wikifiedName(dataset.getName()) + ".xml";
     if (SessionFactoryController.isRunningInWebContainer()) {
       String xmlPath = "/WEB-INF/referencedata/standard/" + dataset.getModule().getJavaPackage()