issue 0009495: retrieve parameters from main window used in validation rule for the action button
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 19 Jun 2009 09:41:25 +0200
changeset 4043 e513eade11c2
parent 4042 5c2e482c554e
child 4044 d7b7924ec0c6
issue 0009495: retrieve parameters from main window used in validation rule for the action button
src-wad/src/org/openbravo/wad/ActionButton_Relation_data.xsql
src-wad/src/org/openbravo/wad/WadActionButton.java
src-wad/src/org/openbravo/wad/javasource.javaxml
src-wad/src/org/openbravo/wad/javasource.xml
src/org/openbravo/erpCommon/utility/FieldProviderFactory.java
--- a/src-wad/src/org/openbravo/wad/ActionButton_Relation_data.xsql	Thu Jun 18 13:10:09 2009 +0200
+++ b/src-wad/src/org/openbravo/wad/ActionButton_Relation_data.xsql	Fri Jun 19 09:41:25 2009 +0200
@@ -29,7 +29,7 @@
       '' AS htmlfields, '' AS htmltext, '' AS htmlfields_Header, AD_COLUMN.AD_TABLE_ID, '' AS javacode, 
       AD_COLUMN.ad_reference_value_id, '' AS process_Params, '' AS process_code, '' AS additional_code, 
       '' AS process_Params_Code, AD_COLUMN.AD_PROCESS_ID AS xmlid, mo.classname, mom.mappingname,
-      '' AS isjasper, '' as total
+      '' AS isjasper, '' as total, '' as comboparacode
       FROM AD_FIELD, AD_COLUMN
             left join ad_model_object mo on ad_column.ad_process_id = mo.ad_process_id 
                           and mo.isactive = 'Y' 
@@ -184,4 +184,29 @@
     </Sql>
     <Parameter name="adProcessId"/>
   </SqlMethod>
+  
+  <SqlMethod name="selectComboParams" type="preparedStatement" return="multiple">
+    <SqlMethodComment>The table references in dictionary</SqlMethodComment>
+    <Sql>
+      <![CDATA[
+              select substr(code, instr(code,'@')+1, instr(code,'@',1,2)-instr(code,'@')-1) as columnname
+            from ad_process_para p, ad_val_rule v, ad_column c, ad_table t, ad_tab tb
+            where p.ad_val_rule_id is not null
+            and t.ad_table_id = c.ad_table_id
+            and c.ad_process_id = p.ad_process_id
+            and v.ad_val_rule_id = p.ad_val_rule_id
+            and code like '%@%'
+            and t.ad_table_id = tb.ad_table_id
+            and tb.ad_tab_id = ?
+            and p.ad_process_id = ? 
+            and exists (select 1 
+                          from ad_column c1, ad_field f
+                        where t.ad_table_id = c1.ad_table_id
+                          and upper(c1.columnname)=upper(substr(code, instr(code,'@')+1, instr(code,'@',1,2)-instr(code,'@')-1))
+                          and f.ad_column_id = c1.ad_column_id)
+              ]]>
+    </Sql>
+    <Parameter name="tabId"/>
+    <Parameter name="processId"/>
+  </SqlMethod>
 </SqlClass>
--- a/src-wad/src/org/openbravo/wad/WadActionButton.java	Thu Jun 18 13:10:09 2009 +0200
+++ b/src-wad/src/org/openbravo/wad/WadActionButton.java	Fri Jun 19 09:41:25 2009 +0200
@@ -117,7 +117,8 @@
         fab[i].columnname = Sqlc.TransformaNombreColumna(fab[i].columnname);
         fab[i].htmltext = getFieldsLoad(fab[i], vecFields, vecTotalFields);
         fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, isSOTrx, window,
-            tabName);
+            tabName, false, fab[i].adProcessId);
+        fab[i].comboparacode = getComboParaCode(conn, fab[i].adProcessId, strTab);
         final StringBuffer fields = new StringBuffer();
         final StringBuffer fieldsHeader = new StringBuffer();
         for (int j = 0; j < vecFields.size(); j++) {
@@ -187,7 +188,8 @@
         fab[i].columnname = Sqlc.TransformaNombreColumna(fab[i].columnname);
         fab[i].htmltext = getFieldsLoad(fab[i], vecFields, vecTotalFields);
         fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, isSOTrx, window,
-            tabName);
+            tabName, false, fab[i].adProcessId);
+        fab[i].comboparacode = getComboParaCode(conn, fab[i].adProcessId, strTab);
         final StringBuffer fields = new StringBuffer();
         final StringBuffer fieldsHeader = new StringBuffer();
         for (int j = 0; j < vecFields.size(); j++) {
@@ -212,6 +214,21 @@
     return fab;
   }
 
+  private static String getComboParaCode(ConnectionProvider conn, String processId, String tabId) {
+    String result = "";
+    ActionButtonRelationData[] params = null;
+    try {
+      params = ActionButtonRelationData.selectComboParams(conn, tabId, processId);
+    } catch (final ServletException e) {
+      return "";
+    }
+    for (ActionButtonRelationData para : params) {
+      result += "p.put(\"" + para.columnname + "\", vars.getStringParameter(\"inp"
+          + Sqlc.TransformaNombreColumna(para.columnname) + "\"));\n";
+    }
+    return result;
+  }
+
   /**
    * Generates the action button call for the java of the menu processes.
    * 
@@ -240,7 +257,8 @@
         fab[i].realname = FormatUtilities.replace(fab[i].realname);
         fab[i].columnname = Sqlc.TransformaNombreColumna(fab[i].columnname);
         fab[i].htmltext = getFieldsLoad(fab[i], vecFields, vecTotalFields);
-        fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, "", "", "");
+        fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, "", "", "",
+            true, "");
         final StringBuffer fields = new StringBuffer();
         final StringBuffer fieldsHeader = new StringBuffer();
         for (int j = 0; j < vecFields.size(); j++) {
@@ -286,7 +304,8 @@
         fab[i].realname = FormatUtilities.replace(fab[i].realname);
         fab[i].columnname = Sqlc.TransformaNombreColumna(fab[i].columnname);
         fab[i].htmltext = getFieldsLoad(fab[i], vecFields, vecTotalFields);
-        fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, "", "", "");
+        fab[i].javacode = getPrintPageJavaCode(conn, fab[i], vecFields, vecParams, "", "", "",
+            true, "");
         final StringBuffer fields = new StringBuffer();
         final StringBuffer fieldsHeader = new StringBuffer();
         for (int j = 0; j < vecFields.size(); j++) {
@@ -390,11 +409,15 @@
    *          Id of the window.
    * @param tabName
    *          Name of the tab.
+   * @param genericActionButton
+   *          Indicates whether it is generic or column action button
+   * @param processId
+   *          Id for the current process
    * @return String with the java code.
    */
   public static String getPrintPageJavaCode(ConnectionProvider conn, ActionButtonRelationData fd,
       Vector<Object> vecFields, Vector<Object> vecParams, String isSOTrx, String window,
-      String tabName) {
+      String tabName, boolean genericActionButton, String processId) {
     if (fd == null)
       return "";
     final StringBuffer html = new StringBuffer();
@@ -450,8 +473,10 @@
 
             html.append("Utility.getContext(this, vars, \"#User_Client\", \"\"), 0");
             html.append(");\n");
-            html.append("    Utility.fillSQLParameters(this, vars, null, comboTableData, \"\", ")
-                .append(strDefault).append(");\n");
+            html.append("    Utility.fillSQLParameters(this, vars, ").append(
+                genericActionButton ? "null" : "(FieldProvider) vars.getSessionObject(\"button"
+                    + processId + ".originalParams\")").append(", comboTableData, \"\", ").append(
+                strDefault).append(");\n");
             html.append("    xmlDocument.setData(\"report");
             // html.append(Sqlc.TransformaNombreColumna(data[i].columnname));
             html.append(data[i].columnname);
--- a/src-wad/src/org/openbravo/wad/javasource.javaxml	Thu Jun 18 13:10:09 2009 +0200
+++ b/src-wad/src/org/openbravo/wad/javasource.javaxml	Fri Jun 19 09:41:25 2009 +0200
@@ -393,6 +393,12 @@
         vars.setSessionValue("button<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>.strProcessing", vars.getStringParameter("inpprocessing", "Y"));
         vars.setSessionValue("button<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>.strOrg", vars.getStringParameter("inpadOrgId"));
         vars.setSessionValue("button<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>.strClient", vars.getStringParameter("inpadClientId"));
+        
+        HashMap&lt;String, String&gt; p = new HashMap&lt;String, String&gt;();
+        <FIELD_TMP id="comboParameters1"></FIELD_TMP>
+        
+        //Save in session needed params for combos if needed
+        vars.setSessionObject("button<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>.originalParams", FieldProviderFactory.getFieldProvider(p));
         printPageButtonFS(response, vars, "<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>", request.getServletPath());    
      } else if (vars.commandIn("BUTTON<FIELD_TMP id="ProcessID1">button</FIELD_TMP>")) {
         String str<KEY_TMP id="key">PosicionAlmacen</KEY_TMP> = vars.getGlobalVariable("inp<KEY_TMP id="keyData">PosicionAlmacen</KEY_TMP>", windowId + "|<KEY_TMP id="key">PosicionAlmacen</KEY_TMP>", "");
@@ -415,6 +421,12 @@
         vars.setSessionValue("button<FIELD_TMP id="ProcessID4">xx</FIELD_TMP>.strProcessing", vars.getStringParameter("inpprocessing", "Y"));
         vars.setSessionValue("button<FIELD_TMP id="ProcessID4">xx</FIELD_TMP>.strOrg", vars.getStringParameter("inpadOrgId"));
         vars.setSessionValue("button<FIELD_TMP id="ProcessID4">xx</FIELD_TMP>.strClient", vars.getStringParameter("inpadClientId"));
+        
+        HashMap&lt;String, String&gt; p = new HashMap&lt;String, String&gt;();
+        <FIELD_TMP id="comboParametersJava1"></FIELD_TMP>
+        
+        //Save in session needed params for combos if needed
+        vars.setSessionObject("button<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>.originalParams", FieldProviderFactory.getFieldProvider(p));
         printPageButtonFS(response, vars, "<FIELD_TMP id="ProcessID4">xx</FIELD_TMP>", request.getServletPath());
       } else if (vars.commandIn("BUTTON<FIELD_TMP id="ProcessID4">button</FIELD_TMP>")) {
         String str<KEY_TMP id="key">PosicionAlmacen</KEY_TMP> = vars.getGlobalVariable("inp<KEY_TMP id="keyData">PosicionAlmacen</KEY_TMP>", windowId + "|<KEY_TMP id="key">PosicionAlmacen</KEY_TMP>", "");
--- a/src-wad/src/org/openbravo/wad/javasource.xml	Thu Jun 18 13:10:09 2009 +0200
+++ b/src-wad/src/org/openbravo/wad/javasource.xml	Fri Jun 19 09:41:25 2009 +0200
@@ -162,6 +162,7 @@
   <FIELD id="ButtonMapping1">mappingname</FIELD>
   <FIELD id="FieldsLoad1">htmltext</FIELD>
   <FIELD id="FieldsLoadName1">htmlfields</FIELD>
+  <FIELD id="comboParameters1">comboparacode</FIELD>
   <SECTION id="sectionActionButtons1"/>
 </structure>
 
--- a/src/org/openbravo/erpCommon/utility/FieldProviderFactory.java	Thu Jun 18 13:10:09 2009 +0200
+++ b/src/org/openbravo/erpCommon/utility/FieldProviderFactory.java	Fri Jun 19 09:41:25 2009 +0200
@@ -19,8 +19,9 @@
 package org.openbravo.erpCommon.utility;
 
 import java.lang.reflect.Method;
-import java.util.Properties;
+import java.util.HashMap;
 
+import org.apache.log4j.Logger;
 import org.openbravo.data.FieldProvider;
 
 /**
@@ -43,7 +44,8 @@
 public class FieldProviderFactory implements FieldProvider {
 
   private Object object;
-  private Properties properties;
+  private HashMap<String, String> properties;
+  private static Logger log4j = Logger.getLogger(Utility.class);
 
   /**
    * Initializes a new FieldProviderFactory for the object
@@ -52,7 +54,11 @@
    */
   public FieldProviderFactory(Object obj) {
     object = obj;
-    properties = new Properties();
+    if (obj instanceof HashMap) {
+      properties = (HashMap<String, String>) obj;
+    } else {
+      properties = new HashMap<String, String>();
+    }
   }
 
   /**
@@ -65,7 +71,7 @@
    */
   public String getField(String fieldName) {
     try {
-      String rt = properties.getProperty(fieldName);
+      String rt = properties.get(fieldName);
       if (rt != null) {
         return rt;
       } else {
@@ -75,13 +81,13 @@
         return (String) method.invoke(object, new Object[] {});
       }
     } catch (Exception e) {
-      e.printStackTrace();
-      return "";
+      log4j.info("Not found field" + fieldName);
+      return null;
     }
   }
 
   private void setProperty(String name, String value) {
-    properties.setProperty(name, value);
+    properties.put(name, value);
   }
 
   /**