related to issue 0011431:
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 11 Dec 2009 09:39:03 +0100
changeset 5681 687f1bb51956
parent 5680 51f8743bf57c
child 5682 e55979c65024
related to issue 0011431:
Added check for auxiliar input name
src-db/database/model/triggers/AD_AUXILIARINPUT_TRG.xml
src-wad/src/org/openbravo/wad/validation/WADValidationResult.java
src-wad/src/org/openbravo/wad/validation/WADValidator.java
src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/model/triggers/AD_AUXILIARINPUT_TRG.xml	Fri Dec 11 09:39:03 2009 +0100
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+  <database name="TRIGGER AD_AUXILIARINPUT_TRG">
+    <trigger name="AD_AUXILIARINPUT_TRG" table="AD_AUXILIARINPUT" fires="before" insert="true" update="true" delete="false" foreach="row">
+      <body><![CDATA[
+/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SL
+* All portions are Copyright (C) 2009 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+ v_aux NUMBER;
+    
+BEGIN
+    
+    IF AD_isTriggerEnabled()='N' THEN RETURN;
+    END IF;
+
+
+  IF :new.AD_Module_ID != '0' THEN
+    SELECT COUNT(*)
+      INTO v_Aux
+      FROM AD_MODULE_DBPREFIX
+     WHERE AD_MODULE_ID = :new.AD_Module_ID
+       AND instr(upper(:new.NAME), upper(name)||'_') = 1;
+    
+    IF v_Aux = 0 THEN
+      RAISE_APPLICATION_ERROR(-20536, 'Messages must start with its module DB prefix') ;
+    END IF;
+  END IF;
+
+
+END AD_AUXILIARINPUT_TRG
+]]></body>
+    </trigger>
+  </database>
--- a/src-wad/src/org/openbravo/wad/validation/WADValidationResult.java	Fri Dec 11 14:06:34 2009 +0530
+++ b/src-wad/src/org/openbravo/wad/validation/WADValidationResult.java	Fri Dec 11 09:39:03 2009 +0100
@@ -39,7 +39,8 @@
    */
   public enum WADValidationType {
     SQL("SQL"), MISSING_IDENTIFIER("Missing Identifier"), MISSING_KEY("Missing Key Column"), MODEL_OBJECT(
-        "Model Object"), MODEL_OBJECT_MAPPING("HTML Mapping"), COLUMN_NAME("Column Naming");
+        "Model Object"), MODEL_OBJECT_MAPPING("HTML Mapping"), COLUMN_NAME("Column Naming"), AUXILIARINPUT(
+        "Auxiliary Input Name");
 
     private String description;
 
--- a/src-wad/src/org/openbravo/wad/validation/WADValidator.java	Fri Dec 11 14:06:34 2009 +0530
+++ b/src-wad/src/org/openbravo/wad/validation/WADValidator.java	Fri Dec 11 09:39:03 2009 +0100
@@ -59,6 +59,7 @@
     validateModelObject(result);
     validateModelObjectMapping(result);
     validateColumnNaming(result);
+    validateAuxiliarInput(result);
     return result;
   }
 
@@ -144,4 +145,20 @@
           "Error when executing query for validating moel object: " + e.getMessage());
     }
   }
+
+  /**
+   * Validates names of auxiliar inputs columns
+   */
+  private void validateAuxiliarInput(WADValidationResult result) {
+    try {
+      WADValidatorData data[] = WADValidatorData.checkAuxiliarInput(conn, modules, checkAll);
+      for (WADValidatorData issue : data) {
+        result.addError(WADValidationType.AUXILIARINPUT, issue.objectname
+            + " does not start by its module's DBPrefix: " + issue.expectedvalue);
+      }
+    } catch (Exception e) {
+      result.addWarning(WADValidationType.SQL,
+          "Error when executing query for validating moel object: " + e.getMessage());
+    }
+  }
 }
--- a/src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql	Fri Dec 11 14:06:34 2009 +0530
+++ b/src-wad/src/org/openbravo/wad/validation/WADValidator_data.xsql	Fri Dec 11 09:39:03 2009 +0100
@@ -228,4 +228,23 @@
     <Parameter name="checkAll"/>
   </SqlMethod>
   
+  <SqlMethod name="checkAuxiliarInput" type="preparedStatement" return="multiple">
+    <Sql>
+      <![CDATA[
+        select i.name as objectName, p.name as expectedvalue
+          from ad_auxiliarInput i, AD_Module_DBPrefix p, AD_Module m
+         where p.AD_Module_ID = i.AD_Module_ID
+           and i.ad_module_id != '0'
+           and m.ad_module_id = i.ad_module_id
+           and instr(upper(i.NAME), upper(p.name)||'_') != 1
+           and (m.javapackage in ('1') or to_char('Y')=to_char(?))
+      ]]>
+    </Sql>
+    <Field name="objecttype" value=""/>
+    <Field name="currentvalue" value=""/>
+    <Field name="expectedvalue" value=""/>
+    <Parameter name="module" optional="true" type="replace" after="m.javapackage in (" text="'1'"/>
+    <Parameter name="checkAll"/>
+  </SqlMethod>
+  
 </SqlClass>