details:   /erp/devel/pi/rev/7d166747db4d
changeset: 7916:7d166747db4d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Jul 23 14:30:31 2010 +0200
summary:   Fixes issue 13749: CallProcess is not able to handle parameters 
typed other than String

diffstat:

 src-test/org/openbravo/test/dal/IssuesTest.java |  23 +++++++++++++++
 src/org/openbravo/service/db/CallProcess.java   |  38 +++++++++++++++++++++---
 2 files changed, 56 insertions(+), 5 deletions(-)

diffs (134 lines):

diff -r 11d7faf63841 -r 7d166747db4d 
src-test/org/openbravo/test/dal/IssuesTest.java
--- a/src-test/org/openbravo/test/dal/IssuesTest.java   Fri Jul 23 14:26:42 
2010 +0200
+++ b/src-test/org/openbravo/test/dal/IssuesTest.java   Fri Jul 23 14:30:31 
2010 +0200
@@ -24,7 +24,10 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.dom4j.Document;
@@ -44,6 +47,7 @@
 import org.openbravo.model.ad.access.Role;
 import org.openbravo.model.ad.access.User;
 import org.openbravo.model.ad.module.Module;
+import org.openbravo.model.ad.process.ProcessInstance;
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.system.Language;
 import org.openbravo.model.ad.ui.Form;
@@ -54,6 +58,7 @@
 import org.openbravo.model.common.invoice.InvoiceLine;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.plm.Product;
+import org.openbravo.service.db.CallProcess;
 import org.openbravo.service.db.CallStoredProcedure;
 import org.openbravo.test.base.BaseTest;
 
@@ -112,6 +117,24 @@
   private static final Logger log = Logger.getLogger(IssuesTest.class);
 
   /**
+   * https://issues.openbravo.com/view.php?id=13749
+   */
+  public void test13749() {
+    setBigBazaarAdminContext();
+    try {
+      org.openbravo.model.ad.ui.Process process = OBDal.getInstance().get(
+          org.openbravo.model.ad.ui.Process.class, "1004400000"); // Has a 
Date parameter
+      Map<String, Date> params = new HashMap<String, Date>();
+      params.put("DateOrdered", new Date());
+      ProcessInstance pi = CallProcess.getInstance().callProcess(process, 
null, params);
+      log.info("Result: " + pi.getResult());
+      log.info("Error message: " + pi.getErrorMsg());
+    } catch (Exception e) {
+      log.error("Error testing CallProcess: " + e.getMessage(), e);
+    }
+  }
+
+  /**
    * https://issues.openbravo.com/view.php?id=12918
    */
   public void test12918() {
diff -r 11d7faf63841 -r 7d166747db4d 
src/org/openbravo/service/db/CallProcess.java
--- a/src/org/openbravo/service/db/CallProcess.java     Fri Jul 23 14:26:42 
2010 +0200
+++ b/src/org/openbravo/service/db/CallProcess.java     Fri Jul 23 14:30:31 
2010 +0200
@@ -14,13 +14,16 @@
  * All portions are Copyright (C) 2009 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
+ * Modification july 2010 (c) openbravo SLU, based on contribution made by 
iferca
  ************************************************************************
  */
 
 package org.openbravo.service.db;
 
+import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
+import java.util.Date;
 import java.util.Map;
 import java.util.Properties;
 
@@ -85,6 +88,26 @@
     return call(processCriteria.list().get(0), recordID, parameters);
   }
 
+/**
+   * Calls a process. The recordID and parameters can be null. Parameters are 
translated into
+   * {...@link Parameter} instances.
+   * 
+   * @param process
+   *          the process to execute
+   * @param recordID
+   *          the recordID will be set in the {...@link ProcessInstance}, see
+   *          {...@link ProcessInstance#getRecordID()}
+   * @param parameters
+   *          are translated into process parameters, supports only string 
parameters, for support
+   *          of other parameters see the next method: {...@link 
#callProcess(org.openbravo.model.ad.ui.Process, String, Map)
+   * @return the created instance with the result ({...@link 
ProcessInstance#getResult()}) or error (
+   *         {...@link ProcessInstance#getErrorMsg()})
+   */
+  public ProcessInstance call(org.openbravo.model.ad.ui.Process process, 
String recordID,
+      Map<String, String> parameters) {
+    return callProcess(process, recordID, (Map<String, ?>) parameters);
+  }
+
   /**
    * Calls a process. The recordID and parameters can be null. Parameters are 
translated into
    * {...@link Parameter} instances.
@@ -99,9 +122,8 @@
    * @return the created instance with the result ({...@link 
ProcessInstance#getResult()}) or error (
    *         {...@link ProcessInstance#getErrorMsg()})
    */
-  public ProcessInstance call(org.openbravo.model.ad.ui.Process process, 
String recordID,
-      Map<String, String> parameters) {
-
+  public ProcessInstance callProcess(org.openbravo.model.ad.ui.Process 
process, String recordID,
+      Map<String, ?> parameters) {
     OBContext.setAdminMode();
     try {
       // Create the pInstance
@@ -124,11 +146,17 @@
         int index = 0;
         for (String key : parameters.keySet()) {
           index++;
-          final String value = parameters.get(key);
+          final Object value = parameters.get(key);
           final Parameter parameter = 
OBProvider.getInstance().get(Parameter.class);
           parameter.setSequenceNumber(index + "");
           parameter.setParameterName(key);
-          parameter.setString(value);
+          if (value instanceof String) {
+            parameter.setString((String) value);
+          } else if (value instanceof Date) {
+            parameter.setProcessDate((Date) value);
+          } else if (value instanceof BigDecimal) {
+            parameter.setProcessNumber((BigDecimal) value);
+          }
 
           // set both sides of the bidirectional association
           pInstance.getADParameterList().add(parameter);

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to