details: /erp/devel/pi/rev/38d89a46ff8d
changeset: 9100:38d89a46ff8d
user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date: Mon Dec 13 16:39:46 2010 +0100
summary: Added public methods to retrieve the values of Parameters.
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
| 51 ++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diffs (66 lines):
diff -r 4b9f1904c3f4 -r 38d89a46ff8d
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
Mon Dec 13 16:24:28 2010 +0100
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
Mon Dec 13 16:39:46 2010 +0100
@@ -20,6 +20,10 @@
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Expression;
@@ -90,4 +94,51 @@
}
return Collections.emptyList();
}
+
+ /**
+ * Returns an Object with the Value of the Parameter Value. This object can
be a String, a
+ * java.util.Data or a BigDecimal.
+ *
+ * @param parameterValue
+ * the Parameter Value we want to get the Value from.
+ * @return the Value of the Parameter Value.
+ */
+ public static Object getParameterValue(ParameterValue parameterValue) {
+ if (parameterValue.getValueDate() != null) {
+ return parameterValue.getValueDate();
+ } else if (parameterValue.getValueNumber() != null) {
+ return parameterValue.getValueNumber();
+ } else if (parameterValue.getValueString() != null) {
+ return parameterValue.getValueString();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the Fixed value of the given parameter. If the value is a JS
expression it returns the
+ * result of the expression based on the parameters passed in from the
request.
+ *
+ * @param parameters
+ * the parameters passed in from the request
+ * @param parameter
+ * the parameter we want to get the Fixed Value from
+ * @return the Fixed Value of the parameter
+ */
+ public static String getParameterFixedValue(Map<String, String> parameters,
Parameter parameter) {
+ if (parameter.isEvaluateFixedValue()) {
+ try {
+ final ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngine engine = manager.getEngineByName("js");
+
+ engine.put("OB", new OBBindings(OBContext.getOBContext(), parameters));
+
+ return (String) engine.eval(parameter.getFixedValue());
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ } else {
+ return parameter.getFixedValue();
+ }
+ }
}
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits