Package.module does now validate modules (and not validate.database)
authorMartin Taal <martin.taal@openbravo.com>
Tue, 10 Feb 2009 07:44:26 +0000
changeset 3038 ad93ada3056b
parent 3037 770422973b02
child 3039 19ac91e5c2f7
Package.module does now validate modules (and not validate.database)
export.database validates database (and not anymore the module itself)
Cleaned up getter/setter of data in BaseOBObject
Solved NPE in validate modules
build.xml
src-db/database/lib/dbsourcemanager.jar
src-test/org/openbravo/test/xml/ClientExportTest.java
src/org/openbravo/base/model/ModelProvider.java
src/org/openbravo/base/structure/BaseOBObject.java
src/org/openbravo/service/db/DataExportService.java
src/org/openbravo/service/system/ModuleValidator.java
src/org/openbravo/service/system/SystemService.java
--- a/build.xml	Tue Feb 10 02:42:43 2009 +0000
+++ b/build.xml	Tue Feb 10 07:44:26 2009 +0000
@@ -103,10 +103,10 @@
 
   <available file=".svn/entries" property="is.svn" />
 
- 
 
 
- 
+
+
   <condition property="deploy.mode" value="class">
     <not>
       <isset property="${deploy.mode}" />
@@ -221,56 +221,56 @@
   </target>
 
   <target name="smartbuild" depends="init">
-    <property name="smart.mode" value="true"/>
+    <property name="smart.mode" value="true" />
     <property name="onlyIfModified" value="true" />
-    <antcall target="core.lib"/>
-    <antcall target="wad.lib"/>
-    
-      <checksum file="${base.src.wad}/lib/openbravo-wad.jar" algorithm="MD5" property="test.md5.wad"/>
+    <antcall target="core.lib" />
+    <antcall target="wad.lib" />
 
-       <condition property="new.wad">
-         <not>
-           <equals arg1="${test.md5.wad}" arg2="${md5.wad}" />
-         </not>
-       </condition>
-    
-    <antcall target="trl.lib"/>
-    
-    
+    <checksum file="${base.src.wad}/lib/openbravo-wad.jar" algorithm="MD5" property="test.md5.wad" />
+
+    <condition property="new.wad">
+      <not>
+        <equals arg1="${test.md5.wad}" arg2="${md5.wad}" />
+      </not>
+    </condition>
+
+    <antcall target="trl.lib" />
+
+
     <condition property="no.local">
       <not>
-        <istrue value="${local}"/>
+        <istrue value="${local}" />
       </not>
     </condition>
     <antcall target="update.database.if.no.local" />
 
     <ant dir="${base.src}" target="smartbuild" inheritAll="true" inheritRefs="true" />
-    
-    <antcall target="build.deploy"/>
+
+    <antcall target="build.deploy" />
     <!-- only restart tomcat if the restart prop was set to true -->
     <condition property="dorestart">
       <istrue value="${restart}" />
     </condition>
     <antcall target="if.restart.tomcat" />
   </target>
-  
+
   <target name="update.database.if.no.local" if="no.local">
     <antcall target="update.database" />
   </target>
 
   <target name="build.deploy">
-    <antcall target="build.deploy.war"/>
-    <antcall target="build.deploy.class"/>
+    <antcall target="build.deploy.war" />
+    <antcall target="build.deploy.class" />
   </target>
-    
+
   <target name="build.deploy.class" if="mode.class">
     <ant dir="${base.src}" target="copy.files" inheritAll="true" inheritRefs="true" />
     <mkdir dir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib" />
-    <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib" file="${build.core.lib}/openbravo-core.jar" encoding="UTF-8"/>
+    <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib" file="${build.core.lib}/openbravo-core.jar" encoding="UTF-8" />
   </target>
-    
+
   <target name="build.deploy.war" if="mode.war">
-    <antcall target="war"/>
+    <antcall target="war" />
   </target>
 
   <target name="if.restart.tomcat" if="dorestart">
@@ -690,6 +690,13 @@
       <classpath refid="project.class.path" />
     </taskdef>
 
+    <taskdef name="validateModules" classname="org.openbravo.service.system.SystemValidationTask">
+      <classpath refid="project.class.path" />
+    </taskdef>
+
+    <echo message="Validating Module..." />
+    <validateModules moduleJavaPackage="${module}" failOnError="false" userId="0" propertiesFile="${base.config}/Openbravo.properties" type="module" />
+
     <antcall target="obx.export.database" />
     <antcall target="obx.export.config.script" />
 
@@ -701,7 +708,7 @@
     <ant dir="src-diagnostics" target="check.all" />
   </target>
 
-   <target name="setup.check.os">
+  <target name="setup.check.os">
     <condition property="osname" value="linux">
       <equals arg1="${os.name}" arg2="Linux" />
     </condition>
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src-test/org/openbravo/test/xml/ClientExportTest.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src-test/org/openbravo/test/xml/ClientExportTest.java	Tue Feb 10 07:44:26 2009 +0000
@@ -19,7 +19,6 @@
 
 package org.openbravo.test.xml;
 
-import java.io.FileWriter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -52,9 +51,9 @@
     final Map<String, Object> params = new HashMap<String, Object>();
     params.put(DataExportService.CLIENT_ID_PARAMETER_NAME, "1000000");
     final String xml = DataExportService.getInstance().exportClientToXML(params, false);
-    final FileWriter fw = new FileWriter("/home/mtaal/mytmp/raltec.xml");
-    fw.write(xml);
-    fw.close();
+    // final FileWriter fw = new FileWriter("/home/mtaal/mytmp/raltec.xml");
+    // fw.write(xml);
+    // fw.close();
     setErrorOccured(false);
   }
 
--- a/src/org/openbravo/base/model/ModelProvider.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src/org/openbravo/base/model/ModelProvider.java	Tue Feb 10 07:44:26 2009 +0000
@@ -166,11 +166,6 @@
       for (final Table t : tables) {
         // tables are stored case insensitive!
         tablesByTableName.put(t.getTableName().toLowerCase(), t);
-
-        if (t.getName().contains("_")) {
-          System.err.println(t.getName());
-        }
-
       }
 
       log.debug("Setting referencetypes for columns");
--- a/src/org/openbravo/base/structure/BaseOBObject.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src/org/openbravo/base/structure/BaseOBObject.java	Tue Feb 10 07:44:26 2009 +0000
@@ -71,22 +71,22 @@
       log.error(ve.getMessage());
     }
     Check.isNotNull(value, "Null default values are not allowed");
-    setData(propName, value);
+    setDataValue(propName, value);
   }
 
   private Object getData(String propName) {
-    return getData(getEntity().getProperty(propName));
+    return getDataValue(getEntity().getProperty(propName));
   }
 
-  private Object getData(Property p) {
+  private Object getDataValue(Property p) {
     if (data == null) {
-      data = new Object[getEntity().getProperties().size()];
+      // nothing set in this case anyway
       return null;
     }
     return data[p.getIndexInEntity()];
   }
 
-  private void setData(String propName, Object value) {
+  private void setDataValue(String propName, Object value) {
     if (data == null) {
       data = new Object[getEntity().getProperties().size()];
     }
@@ -119,7 +119,7 @@
   public Object get(String propName) {
     final Property p = getEntity().getProperty(propName);
     checkDerivedReadable(p);
-    return getData(p);
+    return getDataValue(p);
   }
 
   /**
@@ -168,7 +168,7 @@
    * @param value
    */
   public void setValue(String propName, Object value) {
-    setData(propName, value);
+    setDataValue(propName, value);
   }
 
   /**
--- a/src/org/openbravo/service/db/DataExportService.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src/org/openbravo/service/db/DataExportService.java	Tue Feb 10 07:44:26 2009 +0000
@@ -188,12 +188,16 @@
     Collections.sort(dts, new DatasetTableComparator());
 
     final Set<BaseOBObject> toExport = new LinkedHashSet<BaseOBObject>();
+    System.err.println("Total dts " + dts.size());
+    int i = 0;
     for (final DataSetTable dt : dts) {
       final Boolean isbo = dt.isBusinessObject();
       exc.setOptionIncludeChildren(isbo != null && isbo.booleanValue());
+      System.err.println(i++ + " Reading " + dt.getTable().getName() + "...");
       final List<BaseOBObject> list = DataSetService.getInstance().getExportableObjects(dt,
           moduleId, parameters);
       toExport.addAll(list);
+      System.err.println("Read total " + list.size() + " records ");
     }
 
     if (toExport.size() > 0) {
--- a/src/org/openbravo/service/system/ModuleValidator.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src/org/openbravo/service/system/ModuleValidator.java	Tue Feb 10 07:44:26 2009 +0000
@@ -126,15 +126,16 @@
     final String[] paths = javaPackage.split("\\.");
     for (String part : paths) {
       final File partDir = new File(curDir, part);
-      if (!partDir.exists()) {
+      if (curDir.listFiles() == null || !partDir.exists()) {
         result.addError(SystemValidationType.MODULE_ERROR, "The source directory of the Module "
-            + module.getName() + " is invalid, it should follow the "
-            + "javaPackage of the module: " + javaPackage);
-      }
-      if (curDir.listFiles().length > 1) {
+            + module.getName()
+            + " is invalid, the source directory structure does not correspond to the "
+            + "javaPackage of the module (" + javaPackage + ").");
+        return;
+      } else if (curDir.listFiles().length > 1) {
         result.addError(SystemValidationType.MODULE_ERROR, "The source directory of the Module "
-            + module.getName() + " is invalid, it contains directories "
-            + "which are not part of the javaPackage of the module: " + javaPackage);
+            + module.getName() + " is invalid, it contains directories which are not part of "
+            + "the javaPackage of the module: " + javaPackage);
 
       }
       curDir = partDir;
@@ -188,7 +189,8 @@
 
   private void checkJavaPackages(Module module, SystemValidationResult result) {
     for (org.openbravo.model.ad.module.DataPackage pckg : module.getDataPackageList()) {
-      if (!pckg.getJavaPackage().startsWith(module.getJavaPackage())) {
+      if (pckg.getJavaPackage() != null
+          && !pckg.getJavaPackage().startsWith(module.getJavaPackage())) {
         result.addError(SystemValidationType.MODULE_ERROR, "Data package " + pckg.getName()
             + " has a java package which is not within the java package of its module "
             + module.getName());
--- a/src/org/openbravo/service/system/SystemService.java	Tue Feb 10 02:42:43 2009 +0000
+++ b/src/org/openbravo/service/system/SystemService.java	Tue Feb 10 07:44:26 2009 +0000
@@ -76,7 +76,8 @@
   }
 
   /**
-   * Validates a specific module, both the database model as the module data itself
+   * Validates a specific module, checks the javapackage, dependency on core etc. The database
+   * changes of the module are not checked. This is a separate task.
    * 
    * @param module
    *          the module to validate
@@ -85,15 +86,25 @@
    * @return the validation result
    */
   public SystemValidationResult validateModule(Module module, Database database) {
+    final ModuleValidator moduleValidator = new ModuleValidator();
+    moduleValidator.setValidateModule(module);
+    return moduleValidator.validate();
+  }
+
+  /**
+   * Validates the database for a specific module.
+   * 
+   * @param module
+   *          the module to validate
+   * @param database
+   *          the database to read the dbschema from
+   * @return the validation result
+   */
+  public SystemValidationResult validateDatabase(Module module, Database database) {
     final DatabaseValidator databaseValidator = new DatabaseValidator();
     databaseValidator.setValidateModule(module);
     databaseValidator.setDatabase(database);
-    final SystemValidationResult result = databaseValidator.validate();
-
-    final ModuleValidator moduleValidator = new ModuleValidator();
-    moduleValidator.setValidateModule(module);
-    result.addAll(moduleValidator.validate());
-    return result;
+    return databaseValidator.validate();
   }
 
   /**