fixed bug 0009407: The login variable @#AD_User_ID@ is not being properly used.
authorAsier Lostalé <asier.lostale@openbravo.com>
Wed, 10 Jun 2009 15:34:15 +0200
changeset 3993 204e71d99682
parent 3992 cf1c6a3cce09
child 3994 b0d067451972
child 4094 930768d5377a
fixed bug 0009407: The login variable @#AD_User_ID@ is not being properly used.
src-wad/src/org/openbravo/wad/Wad.java
src-wad/src/org/openbravo/wad/WadUtility.java
--- a/src-wad/src/org/openbravo/wad/Wad.java	Wed Jun 10 17:01:14 2009 +0530
+++ b/src-wad/src/org/openbravo/wad/Wad.java	Wed Jun 10 15:34:15 2009 +0200
@@ -812,11 +812,11 @@
         if (totalParameters < vecTotalParameters.size()) {
           ArrayList<String> usedParameters = new ArrayList<String>();
           for (int h = totalParameters; h < vecTotalParameters.size(); h++) {
-            String strParam = (String) vecTotalParameters.elementAt(h);
-            vecParameters.addElement(strParam);
+            String strParam = WadUtility.getWhereParameter(vecTotalParameters.elementAt(h), false);
+            vecParameters.addElement(WadUtility.getWhereParameter(vecTotalParameters.elementAt(h),
+                true));
             if (!usedParameters.contains(strParam)) {
               usedParameters.add(strParam);
-              strParam = strParam.substring(17, strParam.lastIndexOf("\""));
               whereClauseParams += ", Utility.getContext(this, vars, \"" + strParam
                   + "\", windowId)";
             }
@@ -867,8 +867,8 @@
         if (vecParametersParent.size() > 0) {
           ArrayList<String> usedParameters = new ArrayList<String>();
           for (int h = 0; h < vecParametersParent.size(); h++) {
-            String strParam = (String) vecParametersParent.elementAt(h);
-            strParam = strParam.substring(17, strParam.lastIndexOf("\""));
+            String strParam = WadUtility.getWhereParameter(vecParametersParent.get(h), false);
+
             if (!usedParameters.contains(strParam)) {
               usedParameters.add(strParam);
               parentwhereclause += ", Utility.getContext(this, vars, \"" + strParam
@@ -2399,8 +2399,7 @@
     while (pos != -1) {
       result.append(strWhere.substring(0, pos));
       strWhere = strWhere.substring(pos + 1);
-      String strParam = (String) vecParameters.elementAt(questNumber);
-      strParam = strParam.substring(17, strParam.lastIndexOf("\""));
+      String strParam = WadUtility.getWhereParameter(vecParameters.elementAt(questNumber), false);
       questNumber++;
       if (strParam.equalsIgnoreCase("paramLanguage"))
         result.append(" '\" + vars.getLanguage() + \"' ");
@@ -2810,7 +2809,7 @@
             vecParametros);
         final StringBuffer parametros = new StringBuffer();
         for (final Enumeration<Object> e = vecParametros.elements(); e.hasMoreElements();) {
-          final String paramsElement = (String) e.nextElement();
+          String paramsElement = WadUtility.getWhereParameter(e.nextElement(), true);
           parametros.append("\n" + paramsElement);
         }
         fieldsAux[i].whereclause = parametros.toString();
@@ -2829,7 +2828,7 @@
               vecParametros);
           final StringBuffer parametros = new StringBuffer();
           for (final Enumeration<Object> e = vecParametros.elements(); e.hasMoreElements();) {
-            final String paramsElement = (String) e.nextElement();
+            String paramsElement = WadUtility.getWhereParameter(e.nextElement(), true);
             parametros.append("\n" + paramsElement);
           }
           fieldsDef[i].whereclause = parametros.toString();
@@ -2984,7 +2983,7 @@
               vecParametros);
           final StringBuffer parametros = new StringBuffer();
           for (final Enumeration<Object> e = vecParametros.elements(); e.hasMoreElements();) {
-            final String paramsElement = (String) e.nextElement();
+            final String paramsElement = WadUtility.getWhereParameter(e.nextElement(), true);
             parametros.append("\n" + paramsElement);
           }
           fieldsAux[i].whereclause = parametros.toString();
--- a/src-wad/src/org/openbravo/wad/WadUtility.java	Wed Jun 10 17:01:14 2009 +0530
+++ b/src-wad/src/org/openbravo/wad/WadUtility.java	Wed Jun 10 15:34:15 2009 +0200
@@ -1691,13 +1691,19 @@
           return "";
 
         token = strValue.substring(0, j);
-        if (token.substring(0, 1).indexOf("#") > -1 || token.substring(0, 1).indexOf("$") > -1)
+
+        String modifier = ""; // holds the modifier (# or $) for the session value
+        if (token.substring(0, 1).indexOf("#") > -1 || token.substring(0, 1).indexOf("$") > -1) {
+          modifier = token.substring(0, 1);
           token = token.substring(1, token.length());
+        }
         if (strAux.equals(""))
           strOut.append("?");
         else
           strOut.append("'" + i + "'");
-        vecParameters.addElement("<Parameter name=\"" + token + "\"" + strAux + "/>");
+        String parameter = "<Parameter name=\"" + token + "\"" + strAux + "/>";
+        String paramElement[] = { parameter, modifier };
+        vecParameters.addElement(paramElement);
         strValue = strValue.substring(j + 1, strValue.length());
         strAux = strValue.trim();
         if (strAux.length() > 0 && strAux.substring(0, 1).indexOf("'") > -1)
@@ -2542,4 +2548,38 @@
   public static String toJavaString(String str) {
     return (str.replace("\n", "\\n").replace("\"", "\\\""));
   }
+
+  /**
+   * Returns a where parameter, this parameter can contain a modifier to decide which level of
+   * session value is (# or $).
+   * <p>
+   * This method returns the parameter applying the modifier if exists. It can return the complete
+   * parameter to be used in xsql files or just the name for the parameter with the modifier.
+   * 
+   * @param parameter
+   *          parameter for the where clause to parse
+   * @param complete
+   *          return the complete parameter or just the name
+   * @return the paresed parameter
+   */
+  public static String getWhereParameter(Object parameter, boolean complete) {
+    String strParam = "";
+    if (parameter instanceof String) {
+      // regular parameter without modifier
+      strParam = (String) parameter;
+      if (!complete) {
+        strParam = strParam.substring(17, strParam.lastIndexOf("\""));
+      }
+    } else {
+      // parameter with modifier, used for session values (#, $)
+      String paramElement[] = (String[]) parameter;
+      if (complete) {
+        strParam = paramElement[0];
+      } else {
+        strParam = paramElement[1]
+            + paramElement[0].substring(17, paramElement[0].lastIndexOf("\""));
+      }
+    }
+    return strParam;
+  }
 }