details: /erp/devel/pi/rev/b8ffaca422e9 changeset: 9101:b8ffaca422e9 user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com> date: Mon Dec 13 16:46:18 2010 +0100 summary: QueryList dataset now handles any type of parameter values, including fixed parameters.
details: /erp/devel/pi/rev/b8ec45242e12 changeset: 9102:b8ec45242e12 user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com> date: Mon Dec 13 16:46:57 2010 +0100 summary: Modified example query list widget to add a fixed parameter with a js expression as value. diffstat: modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBCQL_WIDGET_QUERY.xml | 1 + modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml | 19 ++++ modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java | 44 ++++++++- 3 files changed, 56 insertions(+), 8 deletions(-) diffs (115 lines): diff -r 38d89a46ff8d -r b8ec45242e12 modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBCQL_WIDGET_QUERY.xml --- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBCQL_WIDGET_QUERY.xml Mon Dec 13 16:39:46 2010 +0100 +++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBCQL_WIDGET_QUERY.xml Mon Dec 13 16:46:57 2010 +0100 @@ -9,6 +9,7 @@ <!--C0A8491CDB43466D9F2645018473588B--> <HQL><![CDATA[select tab.window.name as windowName, tab.name as tabName, tab.id as tabId from ADTab tab where window.name like :window_name + and window.client.id = :client order by tab.window.name]]></HQL> <!--C0A8491CDB43466D9F2645018473588B--></OBCQL_WIDGET_QUERY> diff -r 38d89a46ff8d -r b8ec45242e12 modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml --- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml Mon Dec 13 16:39:46 2010 +0100 +++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml Mon Dec 13 16:46:57 2010 +0100 @@ -56,4 +56,23 @@ <!--95F5AD0B752C48A2E040007F01001111--> <EM_OBKMO_WIDGET_CLASS_ID><![CDATA[D1E4261099AE4095B2F2DAEE0F7E7784]]></EM_OBKMO_WIDGET_CLASS_ID> <!--95F5AD0B752C48A2E040007F01001111--></OBUIAPP_PARAMETER> +<!--AAF45F634C164AF2AED1B57FAF0CF124--><OBUIAPP_PARAMETER> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <OBUIAPP_PARAMETER_ID><![CDATA[AAF45F634C164AF2AED1B57FAF0CF124]]></OBUIAPP_PARAMETER_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <AD_MODULE_ID><![CDATA[0A060B2AF1974E8EAA8DB61388E9AECC]]></AD_MODULE_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <NAME><![CDATA[Client]]></NAME> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <SEQNO><![CDATA[0]]></SEQNO> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <AD_REFERENCE_ID><![CDATA[10]]></AD_REFERENCE_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <COLUMNNAME><![CDATA[client]]></COLUMNNAME> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <FIELDLENGTH><![CDATA[0]]></FIELDLENGTH> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <ISMANDATORY><![CDATA[N]]></ISMANDATORY> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <ISFIXED><![CDATA[Y]]></ISFIXED> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <FIXEDVALUE><![CDATA[OB.getContext().getCurrentClient().id]]></FIXEDVALUE> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <EVALUATEFIXEDVALUE><![CDATA[Y]]></EVALUATEFIXEDVALUE> +<!--AAF45F634C164AF2AED1B57FAF0CF124--> <EM_OBKMO_WIDGET_CLASS_ID><![CDATA[D1E4261099AE4095B2F2DAEE0F7E7784]]></EM_OBKMO_WIDGET_CLASS_ID> +<!--AAF45F634C164AF2AED1B57FAF0CF124--></OBUIAPP_PARAMETER> + </data> diff -r 38d89a46ff8d -r b8ec45242e12 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 Mon Dec 13 16:39:46 2010 +0100 +++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListDataSource.java Mon Dec 13 16:46:57 2010 +0100 @@ -24,6 +24,8 @@ import java.util.Map; import org.hibernate.Query; +import org.openbravo.client.application.ApplicationUtils; +import org.openbravo.client.application.Parameter; import org.openbravo.client.application.ParameterValue; import org.openbravo.client.myob.WidgetClass; import org.openbravo.client.myob.WidgetInstance; @@ -79,17 +81,14 @@ } String[] params = widgetQuery.getNamedParameters(); if (params.length > 0) { - List<ParameterValue> parameterValues = widgetInstance - .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList(); + HashMap<String, Object> parameterValues = getParameterValues(parameters, widgetInstance); for (int i = 0; i < params.length; i++) { String namedParam = params[i]; boolean isParamSet = false; - for (ParameterValue paramValue : parameterValues) { - if (namedParam.equals(paramValue.getParameter().getDBColumnName())) { - widgetQuery.setParameter(namedParam, paramValue.getValueString()); - isParamSet = true; - } + if (parameterValues.containsKey(namedParam)) { + widgetQuery.setParameter(namedParam, parameterValues.get(namedParam)); + isParamSet = true; } if (!isParamSet) { // TODO: throw an exception @@ -109,7 +108,7 @@ resultList[0] = objResult; for (OBCQL_QueryColumn column : columns) { - // TODO: throw an exception if the display exception doesn't match any returned alias. + // TODO: throw an exception if the display expression doesn't match any returned alias. for (int i = 0; i < queryAliases.length; i++) { if (column.getDisplayExpression().equals(queryAliases[i])) { data.put(column.getName(), resultList[i]); @@ -123,4 +122,33 @@ OBContext.restorePreviousMode(); } } + + /** + * Returns a HashMap with the values of the parameters included on the given widget instance. + * + * @param parameters + * the parameters passed in from the request + * @param widgetInstance + * the widget instance owner of the parameter values + * @return a HashMap<String, Object> with the value of each parameter mapped by the DBColumnName + * of the parameter. + */ + private HashMap<String, Object> getParameterValues(Map<String, String> parameters, + WidgetInstance widgetInstance) { + HashMap<String, Object> parameterValues = new HashMap<String, Object>(); + for (ParameterValue value : widgetInstance + .getOBUIAPPParameterValueEMObkmoWidgetInstanceIDList()) { + parameterValues.put(value.getParameter().getDBColumnName(), + ApplicationUtils.getParameterValue(value)); + } + + for (Parameter parameter : widgetInstance.getWidgetClass() + .getOBUIAPPParameterEMObkmoWidgetClassIDList()) { + if (!parameterValues.containsKey(parameter.getDBColumnName()) && parameter.isFixed()) { + parameterValues.put(parameter.getDBColumnName(), + ApplicationUtils.getParameterFixedValue(parameters, parameter)); + } + } + return parameterValues; + } } ------------------------------------------------------------------------------ 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 Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits