details:   /erp/devel/pi/rev/1e06cf360a62
changeset: 9463:1e06cf360a62
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Wed Dec 29 19:35:07 2010 +0100
summary:   [OBUIAPP] Move methods to ParameterUtils, improvements on 
getParameterValue method.

details:   /erp/devel/pi/rev/636e7cd39d7f
changeset: 9464:636e7cd39d7f
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Wed Dec 29 19:35:12 2010 +0100
summary:   [OBKMO] Get parameter values using ParameterUtils method.

details:   /erp/devel/pi/rev/ee13c8bcb509
changeset: 9465:ee13c8bcb509
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Wed Dec 29 20:00:25 2010 +0100
summary:   [OBCQL] Removed unneeded code. Set showAll option. Use parameter 
DBColumnName instead of name.

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
    |  61 -------
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/JSExpressionCallout.java
 |   2 +-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ParameterUtils.java
      |  78 +++++++++-
 
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java
                    |  19 +-
 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
     |   9 +-
 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListWidgetProvider.java
 |  18 +--
 
modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
    |  31 ++-
 7 files changed, 104 insertions(+), 114 deletions(-)

diffs (truncated from 433 to 300 lines):

diff -r a265147dd5ae -r ee13c8bcb509 
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
       Wed Dec 29 19:47:17 2010 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationUtils.java
       Wed Dec 29 20:00:25 2010 +0100
@@ -20,12 +20,7 @@
 
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
-import javax.script.ScriptException;
-import javax.servlet.http.HttpSession;
 
 import org.apache.log4j.Logger;
 import org.hibernate.criterion.Expression;
@@ -96,60 +91,4 @@
     }
     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 {
-        return (String) getJSExpressionResult(parameters, null, 
parameter.getFixedValue());
-      } catch (Exception e) {
-        log.error(e.getMessage(), e);
-        return null;
-      }
-    } else {
-      return parameter.getFixedValue();
-    }
-  }
-
-  public static Object getJSExpressionResult(Map<String, String> parameters, 
HttpSession session,
-      String expression) throws ScriptException {
-    final ScriptEngineManager manager = new ScriptEngineManager();
-    final ScriptEngine engine = manager.getEngineByName("js");
-
-    if (session != null) {
-      engine.put("OB", new OBBindings(OBContext.getOBContext(), parameters, 
session));
-    } else {
-      engine.put("OB", new OBBindings(OBContext.getOBContext(), parameters));
-    }
-
-    return engine.eval(expression);
-  }
 }
diff -r a265147dd5ae -r ee13c8bcb509 
modules/org.openbravo.client.application/src/org/openbravo/client/application/JSExpressionCallout.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/JSExpressionCallout.java
    Wed Dec 29 19:47:17 2010 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/JSExpressionCallout.java
    Wed Dec 29 20:00:25 2010 +0100
@@ -91,7 +91,7 @@
     sb.append(CLEAR_MSG_CODE);
 
     try {
-      Object result = 
ApplicationUtils.getJSExpressionResult(getParameterMap(request),
+      Object result = 
ParameterUtils.getJSExpressionResult(getParameterMap(request),
           request.getSession(false), expression);
 
       sb.append(", ['INFO','"
diff -r a265147dd5ae -r ee13c8bcb509 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ParameterUtils.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ParameterUtils.java
 Wed Dec 29 19:47:17 2010 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ParameterUtils.java
 Wed Dec 29 20:00:25 2010 +0100
@@ -21,16 +21,24 @@
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Map;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.servlet.http.HttpSession;
 
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.domaintype.BigDecimalDomainType;
+import org.openbravo.base.model.domaintype.BooleanDomainType;
 import org.openbravo.base.model.domaintype.DateDomainType;
 import org.openbravo.base.model.domaintype.DomainType;
 import org.openbravo.base.model.domaintype.LongDomainType;
 import org.openbravo.base.model.domaintype.StringDomainType;
 import org.openbravo.base.util.Check;
+import org.openbravo.dal.core.OBContext;
 
 /**
  * Utility class for Parameters handling
@@ -43,7 +51,7 @@
   public static void setParameterValue(Parameter parameter, ParameterValue 
parameterValue,
       JSONObject requestValue) {
     try {
-      setValue(parameterValue, getParameterDomainType(parameter), 
requestValue.getString("value"));
+      setValue(parameterValue, requestValue.getString("value"));
     } catch (Exception e) {
       log.error("Error trying to set value for paramter: "
           + parameterValue.getParameter().getName(), e);
@@ -52,12 +60,11 @@
 
   public static void setDefaultParameterValue(ParameterValue value) {
     Check.isNotNull(value, "Default value is based on Parameter defintion");
-    setValue(value, getParameterDomainType(value.getParameter()), 
value.getParameter()
-        .getDefaultValue());
+    setValue(value, value.getParameter().getDefaultValue());
   }
 
-  private static void setValue(ParameterValue parameterValue, DomainType 
domainType,
-      String stringValue) {
+  private static void setValue(ParameterValue parameterValue, String 
stringValue) {
+    DomainType domainType = 
getParameterDomainType(parameterValue.getParameter());
     final SimpleDateFormat xmlDateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
     try {
       if (domainType.getClass().equals(StringDomainType.class)) {
@@ -81,4 +88,65 @@
     return 
ModelProvider.getInstance().getReference(parameter.getReference().getId())
         .getDomainType();
   }
+
+  /**
+   * 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) {
+    DomainType domainType = 
getParameterDomainType(parameterValue.getParameter());
+    if (domainType.getClass().equals(StringDomainType.class)) {
+      return parameterValue.getValueString();
+    } else if (domainType.getClass().equals(DateDomainType.class)) {
+      return parameterValue.getValueDate();
+    } else if 
(domainType.getClass().getSuperclass().equals(BigDecimalDomainType.class)
+        || domainType.getClass().equals(LongDomainType.class)) {
+      return parameterValue.getValueNumber();
+    } else if (domainType.getClass().equals(BooleanDomainType.class)) {
+      return "true".equals(parameterValue.getValueString());
+    } else { // default
+      return parameterValue.getValueString();
+    }
+  }
+
+  /**
+   * 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 {
+        return (String) getJSExpressionResult(parameters, null, 
parameter.getFixedValue());
+      } catch (Exception e) {
+        // log.error(e.getMessage(), e);
+        return null;
+      }
+    } else {
+      return parameter.getFixedValue();
+    }
+  }
+
+  public static Object getJSExpressionResult(Map<String, String> parameters, 
HttpSession session,
+      String expression) throws ScriptException {
+    final ScriptEngineManager manager = new ScriptEngineManager();
+    final ScriptEngine engine = manager.getEngineByName("js");
+
+    if (session != null) {
+      engine.put("OB", new OBBindings(OBContext.getOBContext(), parameters, 
session));
+    } else {
+      engine.put("OB", new OBBindings(OBContext.getOBContext(), parameters));
+    }
+
+    return engine.eval(expression);
+  }
 }
diff -r a265147dd5ae -r ee13c8bcb509 
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java
--- 
a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java
       Wed Dec 29 19:47:17 2010 +0100
+++ 
b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java
       Wed Dec 29 20:00:25 2010 +0100
@@ -40,6 +40,7 @@
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.client.application.Parameter;
 import org.openbravo.client.application.ParameterTrl;
+import org.openbravo.client.application.ParameterUtils;
 import org.openbravo.client.application.ParameterValue;
 import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.kernel.reference.EnumUIDefinition;
@@ -113,15 +114,15 @@
       for (Parameter parameter : 
widgetClass.getOBUIAPPParameterEMObkmoWidgetClassIDList()) {
         // fixed parameters are not part of the fielddefinitions
         if (parameter.isFixed()) {
-          defaultParameters.put(parameter.getName(), 
parameter.getFixedValue());
+          defaultParameters.put(parameter.getDBColumnName(), 
parameter.getFixedValue());
           continue;
         }
         if (parameter.getDefaultValue() != null) {
-          defaultParameters.put(parameter.getName(), 
parameter.getDefaultValue());
+          defaultParameters.put(parameter.getDBColumnName(), 
parameter.getDefaultValue());
         }
         final JSONObject fieldDefinition = new JSONObject();
         fieldDefinition.put(PARAMETERID, parameter.getId());
-        fieldDefinition.put(PARAMETERNAME, parameter.getName());
+        fieldDefinition.put(PARAMETERNAME, parameter.getDBColumnName());
         fieldDefinition.put(PARAMETERREQUIRED, parameter.isMandatory());
 
         final Reference reference;
@@ -179,16 +180,8 @@
     final JSONObject widgetParameters = new JSONObject();
     for (ParameterValue parameterValue : widgetInstance
         .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList()) {
-      if (parameterValue.getValueDate() != null) {
-        widgetParameters
-            .put(parameterValue.getParameter().getName(), 
parameterValue.getValueDate());
-      } else if (parameterValue.getValueNumber() != null) {
-        widgetParameters.put(parameterValue.getParameter().getName(), 
parameterValue
-            .getValueNumber());
-      } else if (parameterValue.getValueString() != null) {
-        widgetParameters.put(parameterValue.getParameter().getName(), 
parameterValue
-            .getValueString());
-      }
+      widgetParameters.put(parameterValue.getParameter().getDBColumnName(), 
ParameterUtils
+          .getParameterValue(parameterValue));
     }
     jsonObject.put(PARAMETERS, widgetParameters);
   }
diff -r a265147dd5ae -r ee13c8bcb509 
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
--- 
a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
        Wed Dec 29 19:47:17 2010 +0100
+++ 
b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java
        Wed Dec 29 20:00:25 2010 +0100
@@ -28,8 +28,8 @@
 
 import org.hibernate.Query;
 import org.openbravo.base.model.domaintype.PrimitiveDomainType;
-import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.Parameter;
+import org.openbravo.client.application.ParameterUtils;
 import org.openbravo.client.application.ParameterValue;
 import org.openbravo.client.kernel.reference.ForeignKeyUIDefinition;
 import org.openbravo.client.kernel.reference.NumberUIDefinition;
@@ -76,6 +76,7 @@
       WidgetInstance widgetInstance = 
OBDal.getInstance().get(WidgetInstance.class,
           parameters.get("widgetInstanceId"));
       boolean isExport = "true".equals(parameters.get("exportToFile"));
+      boolean showAll = "true".equals(parameters.get("showAll"));
       String viewMode = parameters.get("viewMode");
       WidgetClass widgetClass = widgetInstance.getWidgetClass();
 
@@ -83,7 +84,7 @@
           widgetClass.getOBCQLWidgetQueryList().get(0).getHQL());
       String[] queryAliases = widgetQuery.getReturnAliases();
 
-      if (!isExport && "widget".equals(viewMode)) {
+      if (!isExport && "widget".equals(viewMode) && !showAll) {
         int rowsNumber = Integer.valueOf((parameters.get("rowsNumber") != 
null) ? parameters
             .get("rowsNumber") : "10");
         widgetQuery.setMaxResults(rowsNumber);
@@ -165,14 +166,14 @@
     HashMap<String, Object> parameterValues = new HashMap<String, Object>();
     for (ParameterValue value : widgetInstance
         .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList()) {
-      parameterValues.put(value.getParameter().getDBColumnName(), 
ApplicationUtils
+      parameterValues.put(value.getParameter().getDBColumnName(), 
ParameterUtils
           .getParameterValue(value));
     }
 
     for (Parameter parameter : widgetInstance.getWidgetClass()
         .getOBUIAPPParameterEMObkmoWidgetClassIDList()) {
       if (!parameterValues.containsKey(parameter.getDBColumnName()) && 
parameter.isFixed()) {
-        parameterValues.put(parameter.getDBColumnName(), 
ApplicationUtils.getParameterFixedValue(

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to