Fixes issue 0012628: When clicking Linked Items in Business Partner window, Accounting Transaction Details show database IDs
authorAdrián Romero <adrianromero@openbravo.com>
Fri, 23 Apr 2010 17:32:58 +0200
changeset 7139 ade5b974f0db
parent 7138 cb15f7a33252
child 7140 650e5e995461
Fixes issue 0012628: When clicking Linked Items in Business Partner window, Accounting Transaction Details show database IDs
src-core/src/org/openbravo/data/Parameter.java
src-core/src/org/openbravo/data/Sql.java
src-core/src/org/openbravo/data/Sqlc.java
src-core/src/org/openbravo/data/UtilSql.java
src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-core/src/org/openbravo/data/Parameter.java	Fri Apr 23 16:11:53 2010 +0200
+++ b/src-core/src/org/openbravo/data/Parameter.java	Fri Apr 23 17:32:58 2010 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2009 Openbravo S.L.U.
+ * Copyright (C) 2001-2010 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -23,9 +23,10 @@
   String strText;
   String strIgnoreValue;
   boolean boolOptional = false;
+  String filter;
 
   public Parameter(boolean sequence, String strName, String strDefault, String strInOut,
-      String strOptional, String strAfter, String strText, String strIgnoreValue) {
+      String strOptional, String strAfter, String strText, String strIgnoreValue, String filter) {
     boolSequence = sequence;
     this.strName = strName;
     this.strDefault = strDefault;
@@ -36,6 +37,7 @@
     this.strAfter = strAfter;
     this.strText = strText;
     this.strIgnoreValue = strIgnoreValue;
+    this.filter = filter;
   }
 
 }
--- a/src-core/src/org/openbravo/data/Sql.java	Fri Apr 23 16:11:53 2010 +0200
+++ b/src-core/src/org/openbravo/data/Sql.java	Fri Apr 23 17:32:58 2010 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2009 Openbravo S.L.U.
+ * Copyright (C) 2001-2010 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -41,7 +41,7 @@
   }
 
   public Parameter addParameter(boolean sequence, String strName, String strDefault,
-      String strInOut, String strOptional, String strAfter, String strText, String strIgnoreValue) {
+      String strInOut, String strOptional, String strAfter, String strText, String strIgnoreValue, String filter) {
     if (log4j.isDebugEnabled())
       log4j.debug("addParameter sequence: " + sequence + " name: " + strName);
     if (strOptional != null)
@@ -49,7 +49,7 @@
     if (log4j.isDebugEnabled())
       log4j.debug("previous new Parameter");
     Parameter parameterNew = new Parameter(sequence, strName, strDefault, strInOut, strOptional,
-        strAfter, strText, strIgnoreValue);
+        strAfter, strText, strIgnoreValue, filter);
     if (log4j.isDebugEnabled())
       log4j.debug("called new Parameter");
     for (Enumeration<Parameter> e = vecParameter.elements(); e.hasMoreElements();) {
--- a/src-core/src/org/openbravo/data/Sqlc.java	Fri Apr 23 16:11:53 2010 +0200
+++ b/src-core/src/org/openbravo/data/Sqlc.java	Fri Apr 23 17:32:58 2010 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2009 Openbravo S.L.U.
+ * Copyright (C) 2001-2010 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -456,6 +456,7 @@
       String strAfter = null;
       String strText = null;
       String strIgnoreValue = null;
+      String filter = null;
       final int size = amap.getLength();
       for (int i = 0; i < size; i++) {
         if (amap.getQName(i).equals("name")) {
@@ -472,12 +473,14 @@
           strText = amap.getValue(i);
         } else if (amap.getQName(i).equals("ignoreValue")) {
           strIgnoreValue = amap.getValue(i);
+        } else if (amap.getQName(i).equals("filter")) {
+          filter = amap.getValue(i);
         }
       }
       if (log4j.isDebugEnabled())
         log4j.debug("Configuration: call to addParameter ");
       parameterSql = sql.addParameter(false, strName, strDefault, strInOut, strOptional, strAfter,
-          strText, strIgnoreValue);
+          strText, strIgnoreValue, filter);
     } else if (name.equals("Field")) {
       FieldAdded field = null;
       final int size = amap.getLength();
@@ -497,7 +500,7 @@
         }
       }
       parameterSql = sql
-          .addParameter(true, sql.strSequenceName, null, null, null, null, null, null);
+          .addParameter(true, sql.strSequenceName, null, null, null, null, null, null, null);
     }
   }
 
@@ -895,6 +898,16 @@
     out2.append("  }\n");
   }
 
+  private void appendFilterSQLParameter(Parameter parameter) {
+      if (parameter.filter != null && !parameter.filter.equals("")) {
+        out2.append("  UtilSql.filterSQLParameter(SqlcFilters.get");
+        out2.append(parameter.filter);
+        out2.append(", ");
+        out2.append(parameter.strName);
+        out2.append(");\n");
+      }
+  }
+
   private void printSQLBody() throws IOException {
     // codigo para imprimir trozos de Sql opcionales
     int posSQL = 0;
@@ -919,6 +932,7 @@
               out2.append("    strSql = strSql + ((" + parameter.strName + ".equals(\""
                   + parameter.strName + "\"))?\" " + parameter.strText + " \":\"\");\n");
             } else if (parameter.strInOut.equals("argument")) {
+              appendFilterSQLParameter(parameter);
               out2.append("    strSql = strSql + ((" + parameter.strName + "==null || "
                   + parameter.strName + ".equals(\"\")");
               if (parameter.strIgnoreValue != null) {
@@ -927,6 +941,7 @@
               }
               out2.append(")?\"\":\" " + parameter.strText + "\" + " + parameter.strName + ");\n");
             } else if (parameter.strInOut.equals("replace")) {
+              appendFilterSQLParameter(parameter);
               out2.append("    strSql = strSql + ((" + parameter.strName + "==null || "
                   + parameter.strName + ".equals(\"\")");
               if (parameter.strIgnoreValue != null) {
--- a/src-core/src/org/openbravo/data/UtilSql.java	Fri Apr 23 16:11:53 2010 +0200
+++ b/src-core/src/org/openbravo/data/UtilSql.java	Fri Apr 23 17:32:58 2010 +0200
@@ -17,9 +17,21 @@
 import java.sql.ResultSet;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import javax.servlet.ServletException;
+import org.openbravo.base.filter.RequestFilter;
 
 public class UtilSql {
 
+    public static void filterSQLParameter (String value, String filter) throws ServletException {
+        if (value != null && !value.equals("")) {
+            RequestFilter reqfilter = null;
+            if (!reqfilter.accept(value)) {
+              // log4j.error("Exception in query: " + strSql + "Exception:"+ ex);
+              throw new ServletException("@CODE=@Query parameter error" );
+            }
+        }
+    }
+
   // setValue and getValue method to be used in sqlc
 
   public static boolean setValue(PreparedStatement ps, int posicion, int tipo, String strDefault,
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Fri Apr 23 16:11:53 2010 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Fri Apr 23 17:32:58 2010 +0200
@@ -46727,7 +46727,7 @@
 <!--3001-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--3001-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
 <!--3001-->  <ISUPDATEABLE><![CDATA[N]]></ISUPDATEABLE>
-<!--3001-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
+<!--3001-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
 <!--3001-->  <SEQNO><![CDATA[1]]></SEQNO>
 <!--3001-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--3001-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -96415,7 +96415,7 @@
 <!--5855-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--5855-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
 <!--5855-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
-<!--5855-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--5855-->  <ISIDENTIFIER><![CDATA[Y]]></ISIDENTIFIER>
 <!--5855-->  <SEQNO><![CDATA[0]]></SEQNO>
 <!--5855-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
 <!--5855-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>