Fixed issue 13438. Now the import of reference data and translations can be forced with -DforceRefData=true
authorAntonio Moreno <antonio.moreno@openbravo.com>
Thu, 16 Feb 2012 12:11:22 +0100
changeset 15522 459c8c6700f5
parent 15521 eb48f353d1d3
child 15523 60dc2b18fc07
Fixed issue 13438. Now the import of reference data and translations can be forced with -DforceRefData=true
build.xml
src/org/openbravo/erpCommon/modules/ApplyModule.java
src/org/openbravo/erpCommon/modules/ApplyModuleTask.java
src/org/openbravo/erpCommon/modules/ApplyModule_data.xsql
--- a/build.xml	Thu Feb 16 10:46:50 2012 +0100
+++ b/build.xml	Thu Feb 16 12:11:22 2012 +0100
@@ -777,7 +777,7 @@
     <taskdef name="applyModule" classname="org.openbravo.erpCommon.modules.ApplyModuleTask">
       <classpath refid="project.class.path" />
     </taskdef>
-    <applyModule userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties"/>
+    <applyModule userId="0" adminMode="true" forceRefData="${forceRefData}" propertiesFile="${base.config}/Openbravo.properties"/>
   </target>
   
   <target name="compile.apply.module" depends="init">
@@ -794,7 +794,7 @@
   -->
   <target name="apply.module" depends="compile.apply.module">
     <java classname="org.openbravo.erpCommon.modules.ApplyModuleTask" fork="true" maxmemory="${build.maxmemory}" failonerror="true">
-      <arg line="'${base.src}' '${friendlyWarnings}'" />
+      <arg line="'${base.src}' '${friendlyWarnings}' '${forceRefData}'" />
       <classpath refid="apply.module.runtime.classpath" />
     </java>
    <delete includeEmptyDirs="true"  dir="${build.apply.module}" />
--- a/src/org/openbravo/erpCommon/modules/ApplyModule.java	Thu Feb 16 10:46:50 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ApplyModule.java	Thu Feb 16 12:11:22 2012 +0100
@@ -54,6 +54,7 @@
   private static ConnectionProvider pool;
   static Logger log4j = Logger.getLogger(ApplyModule.class);
   private String obDir;
+  private boolean forceRefData = false;
 
   public ApplyModule(ConnectionProvider cp, String dir) {
     pool = cp;
@@ -62,6 +63,14 @@
     log4j = Logger.getLogger(ApplyModule.class);
   }
 
+  public ApplyModule(ConnectionProvider cp, String dir, boolean forceRefData) {
+    pool = cp;
+    obDir = dir;
+    PropertyConfigurator.configure(obDir + "/src/log4j.lcf");
+    log4j = Logger.getLogger(ApplyModule.class);
+    this.forceRefData = forceRefData;
+  }
+
   /**
    * Process the Installed but not applied modules, the treatement for these modules is: Translation
    * modules In case the module contains translations the process will: <br/>
@@ -84,7 +93,12 @@
       // **************** Translation modules ************************
       // Check whether modules to install are translations
       log4j.info("Looking for translation modules");
-      final ApplyModuleData[] data = ApplyModuleData.selectTranslationModules(pool);
+      final ApplyModuleData[] data;
+      if (!forceRefData) {
+        data = ApplyModuleData.selectTranslationModules(pool);
+      } else {
+        data = ApplyModuleData.selectAllTranslationModules(pool);
+      }
 
       if (data != null && data.length > 0) {
         log4j.info(data.length + " translation modules found");
@@ -123,7 +137,12 @@
 
       log4j.info("Looking for reference data modules");
 
-      final ApplyModuleData[] ds = ApplyModuleData.selectClientReferenceModules(pool);
+      final ApplyModuleData[] ds;
+      if (!forceRefData) {
+        ds = ApplyModuleData.selectClientReferenceModules(pool);
+      } else {
+        ds = ApplyModuleData.selectAllClientReferenceModules(pool);
+      }
 
       if (ds != null && ds.length > 0) {
         ModuleUtility.orderModuleByDependency(ds);
--- a/src/org/openbravo/erpCommon/modules/ApplyModuleTask.java	Thu Feb 16 10:46:50 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ApplyModuleTask.java	Thu Feb 16 12:11:22 2012 +0100
@@ -37,18 +37,22 @@
   // private String propertiesFile;
   private String obDir;
   private static final Logger log4j = Logger.getLogger(ApplyModuleTask.class);
+  private Boolean forceRefData = false;
 
   public static void main(String[] args) {
+    Boolean lforceRefData = false;
     final String srcPath = args[0];
     String friendlyWarnings = "false";
     if (args.length >= 2) {
       friendlyWarnings = args[1];
+      lforceRefData = args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("yes");
     }
     final File srcDir = new File(srcPath);
     final File baseDir = srcDir.getParentFile();
     try {
       final AntExecutor antExecutor = new AntExecutor(baseDir.getAbsolutePath());
       antExecutor.setProperty("friendlyWarnings", friendlyWarnings);
+      antExecutor.setProperty("forceRefData", lforceRefData.toString());
       antExecutor.runTask("apply.module.forked");
     } catch (final Exception e) {
       throw new OBException(e);
@@ -65,7 +69,11 @@
     CPStandAlone pool = new CPStandAlone(propertiesFile);
     ApplyModuleData[] ds = null;
     try {
-      ds = ApplyModuleData.selectClientReferenceModules(pool);
+      if (!forceRefData) {
+        ds = ApplyModuleData.selectClientReferenceModules(pool);
+      } else {
+        ds = ApplyModuleData.selectAllClientReferenceModules(pool);
+      }
     } catch (Exception e) {
       log4j.error("Error checking modules with reference data", e);
     }
@@ -74,7 +82,11 @@
       super.execute();
     } else {
       try {
-        ds = ApplyModuleData.selectTranslationModules(pool);
+        if (!forceRefData) {
+          ds = ApplyModuleData.selectTranslationModules(pool);
+        } else {
+          ds = ApplyModuleData.selectAllTranslationModules(pool);
+        }
       } catch (Exception e) {
         log4j.error("Error checking modules with translation data", e);
       }
@@ -101,7 +113,7 @@
         obDir = getProject().getBaseDir().toString();
       if (propertiesFile == null || propertiesFile.equals(""))
         propertiesFile = obDir + "/config/Openbravo.properties";
-      final ApplyModule am = new ApplyModule(new CPStandAlone(propertiesFile), obDir);
+      final ApplyModule am = new ApplyModule(new CPStandAlone(propertiesFile), obDir, forceRefData);
       am.execute();
     } catch (final Exception e) {
       throw new BuildException(e);
@@ -114,4 +126,8 @@
   public void setObDir(String obDir) {
     this.obDir = obDir;
   }
+
+  public void setForceRefData(boolean forceRefData) {
+    this.forceRefData = forceRefData;
+  }
 }
--- a/src/org/openbravo/erpCommon/modules/ApplyModule_data.xsql	Thu Feb 16 10:46:50 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ApplyModule_data.xsql	Thu Feb 16 12:11:22 2012 +0100
@@ -31,6 +31,16 @@
          AND ISTRANSLATIONMODULE = 'Y'
     ]]></Sql>
   </SqlMethod>
+  <SqlMethod name="selectAllTranslationModules" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+    <![CDATA[
+      SELECT M.JAVAPACKAGE, M.NAME, M.AD_LANGUAGE, L.ISSYSTEMLANGUAGE, '' as DS_NAME, '' AS AD_MODULE_ID
+        FROM AD_MODULE M LEFT JOIN AD_LANGUAGE L
+                           ON L.AD_LANGUAGE = M.AD_LANGUAGE
+       WHERE ISTRANSLATIONMODULE = 'Y'
+    ]]></Sql>
+  </SqlMethod>
   
   <SqlMethod name="selectClientReferenceModules" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
@@ -45,6 +55,18 @@
     ]]></Sql>
   </SqlMethod>
   
+  <SqlMethod name="selectAllClientReferenceModules" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+    <![CDATA[
+      SELECT M.JAVAPACKAGE, M.NAME, M.AD_MODULE_ID, D.NAME as DS_NAME
+        FROM AD_MODULE M, AD_DATASET D
+       WHERE M.HASREFERENCEDATA = 'Y'
+         AND D.AD_MODULE_ID = M.AD_MODULE_ID
+         AND D.ACCESSLEVEL = '4'
+    ]]></Sql>
+  </SqlMethod>
+  
   <SqlMethod name="setSystemLanguage" type="preparedStatement" return="rowcount">
     <Sql>
       <![CDATA[