# HG changeset patch
# User Augusto Mauch <augusto.mauch@openbravo.com>
# Date 1349956284 -7200
# Node ID 3d78647ce44e4232020b003ed18b9bf797d35977
# Parent  9b0c261d48cb1839d41caa047338bcc46408af8b
Fixes issue 21669: Validation when exporting Database not working properly

There was a validation that was only being done to the tables that belonged to the module being validated, but not to the tables modified by that module. Now, if a module adds a column to a table that belongs to another module but forgets to add it to the application dictionary, the validation will detect the error, the same way it has been working for the columns defined in tables that belonged to the module being validated.

diff --git a/src/org/openbravo/service/system/DatabaseValidator.java b/src/org/openbravo/service/system/DatabaseValidator.java
--- a/src/org/openbravo/service/system/DatabaseValidator.java
+++ b/src/org/openbravo/service/system/DatabaseValidator.java
@@ -168,11 +168,17 @@
     // 2) table present in db, not in ad
     // 3) table present on both sides, column match check
 
+    final Map<String, org.apache.ddlutils.model.Table> dbTablesByName = new HashMap<String, org.apache.ddlutils.model.Table>();
+
     final org.apache.ddlutils.model.Table[] dbTables = getDatabase().getTables();
-    final Map<String, org.apache.ddlutils.model.Table> dbTablesByName = new HashMap<String, org.apache.ddlutils.model.Table>();
     for (org.apache.ddlutils.model.Table dbTable : dbTables) {
       dbTablesByName.put(dbTable.getName().toUpperCase(), dbTable);
     }
+
+    final org.apache.ddlutils.model.Table[] dbModifiedTables = getDatabase().getModifiedTables();
+    for (org.apache.ddlutils.model.Table dbModifiedTable : dbModifiedTables) {
+      dbTablesByName.put(dbModifiedTable.getName().toUpperCase(), dbModifiedTable);
+    }
     final Map<String, org.apache.ddlutils.model.Table> tmpDBTablesByName = new HashMap<String, org.apache.ddlutils.model.Table>(
         dbTablesByName);
 
@@ -464,14 +470,14 @@
       }
     }
 
-    if (moduleId == null
-        || (adTable.getDataPackage().getModule() != null && adTable.getDataPackage().getModule()
-            .getId().equals(moduleId))) {
-      for (org.apache.ddlutils.model.Column dbColumn : dbColumnsByName.values()) {
-        result.addError(SystemValidationResult.SystemValidationType.NOT_EXIST_IN_AD, "Column "
-            + dbTable.getName() + "." + dbColumn.getName() + " present in the database "
-            + " but not defined in the Application Dictionary.");
-      }
+    // The columns in dbColumnsByName belong either to the tables defined in the module being
+    // validated, or
+    // to its modified tables, so they have to be checked always at this point
+
+    for (org.apache.ddlutils.model.Column dbColumn : dbColumnsByName.values()) {
+      result.addError(SystemValidationResult.SystemValidationType.NOT_EXIST_IN_AD, "Column "
+          + dbTable.getName() + "." + dbColumn.getName() + " present in the database "
+          + " but not defined in the Application Dictionary.");
     }
   }
 
