details: /erp/devel/pi/rev/9c6fecf14181
changeset: 11157:9c6fecf14181
user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date: Wed Mar 09 19:34:14 2011 +0100
summary: [OBJSON] Moved buildCriteria() method to JsonUtils.
details: /erp/devel/pi/rev/8c11b21568d3
changeset: 11158:8c11b21568d3
user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date: Wed Mar 09 19:34:59 2011 +0100
summary: [OBUISEL] Applied advancedCriteria filter to CustomQueryDatasource.
details: /erp/devel/pi/rev/715e5f37db43
changeset: 11159:715e5f37db43
user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date: Wed Mar 09 19:36:04 2011 +0100
summary: Fixed issue 16143.[OBUIAPP] Fixed issue on isSalesTransaction()
method.
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
| 18 +++-
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
| 49 +---------
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
| 48 +++++++++
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
| 32 ++++++-
4 files changed, 95 insertions(+), 52 deletions(-)
diffs (226 lines):
diff -r 03f21336f3da -r 715e5f37db43
modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
Wed Mar 09 12:34:16 2011 -0600
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
Wed Mar 09 19:36:04 2011 +0100
@@ -103,12 +103,24 @@
}
String value = requestMap.get(OBBindingsConstants.SO_TRX_PARAM);
-
- if (value == null) {
+ if (value != null) {
+ return "Y".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
+ }
+ if (httpSession == null) {
+ log.warn("Requesting isSOTrx check without request parameters and
session");
return null;
}
- return "Y".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
+ value = (String) httpSession.getAttribute("inpisSOTrxTab");
+ if (value != null) {
+ return "Y".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
+ }
+
+ value = (String) httpSession.getAttribute(getWindowId() + "|ISSOTRX");
+ if (value != null) {
+ return "Y".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value);
+ }
+ return null;
}
public String getWindowId() {
diff -r 03f21336f3da -r 715e5f37db43
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Wed Mar 09 12:34:16 2011 -0600
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Wed Mar 09 19:36:04 2011 +0100
@@ -211,7 +211,7 @@
queryService.addFilterParameter(key, parameters.get(key));
}
}
- queryService.setCriteria(buildCriteria(parameters, queryService));
+ queryService.setCriteria(JsonUtils.buildCriteria(parameters));
if (parameters.get(JsonConstants.NO_ACTIVE_FILTER) != null
&& parameters.get(JsonConstants.NO_ACTIVE_FILTER).equals("true")) {
@@ -264,53 +264,6 @@
return queryService;
}
- private JSONObject buildCriteria(Map<String, String> parameters,
- DataEntityQueryService queryService) {
- try {
- final JSONObject criteria = new JSONObject();
-
- if (parameters.get(JsonConstants.OR_EXPRESSION_PARAMETER) != null) {
- criteria.put("operator", "or");
- } else {
- criteria.put("operator", "and");
- }
- criteria.put("_constructor", "AdvancedCriteria");
-
- final List<JSONObject> criteriaObjects = new ArrayList<JSONObject>();
- if (parameters.containsKey("criteria") &&
!parameters.get("criteria").equals("")) {
- String fullCriteriaStr = parameters.get("criteria");
- if (fullCriteriaStr.startsWith("[")) {
- JSONArray criteriaArray = new JSONArray(fullCriteriaStr);
- fullCriteriaStr = "";
- for (int i = 0; i < criteriaArray.length(); i++) {
- if (i > 0) {
- fullCriteriaStr += JsonConstants.IN_PARAMETER_SEPARATOR;
- }
- fullCriteriaStr += criteriaArray.getJSONObject(i).toString();
- }
- }
- final String[] criteriaStrs =
fullCriteriaStr.split(JsonConstants.IN_PARAMETER_SEPARATOR);
- if (!fullCriteriaStr.equals("")) {
- for (String criteriaStr : criteriaStrs) {
- final JSONObject criteriaJSONObject = new JSONObject(criteriaStr);
- if (criteriaJSONObject.has("fieldName")) {
- final String fieldName =
criteriaJSONObject.getString("fieldName");
- if (!fieldName.startsWith("_")) {
- criteriaObjects.add(criteriaJSONObject);
- }
- } else {
- criteriaObjects.add(criteriaJSONObject);
- }
- }
- }
- }
- criteria.put("criteria", new JSONArray(criteriaObjects));
- return criteria;
- } catch (JSONException e) {
- throw new OBException(e);
- }
- }
-
private void addWritableAttribute(List<JSONObject> jsonObjects) throws
JSONException {
for (JSONObject jsonObject : jsonObjects) {
if (!jsonObject.has("client") || !jsonObject.has("organization")) {
diff -r 03f21336f3da -r 715e5f37db43
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
Wed Mar 09 12:34:16 2011 -0600
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
Wed Mar 09 19:36:04 2011 +0100
@@ -27,7 +27,9 @@
import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.base.exception.OBException;
import org.openbravo.base.model.Entity;
import org.openbravo.base.model.Property;
import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -259,4 +261,50 @@
return properties;
}
+ public static JSONObject buildCriteria(Map<String, String> parameters) {
+ try {
+ final JSONObject criteria = new JSONObject();
+
+ if (parameters.get(JsonConstants.OR_EXPRESSION_PARAMETER) != null) {
+ criteria.put("operator", "or");
+ } else {
+ criteria.put("operator", "and");
+ }
+ criteria.put("_constructor", "AdvancedCriteria");
+
+ final List<JSONObject> criteriaObjects = new ArrayList<JSONObject>();
+ if (parameters.containsKey("criteria") &&
!parameters.get("criteria").equals("")) {
+ String fullCriteriaStr = parameters.get("criteria");
+ if (fullCriteriaStr.startsWith("[")) {
+ JSONArray criteriaArray = new JSONArray(fullCriteriaStr);
+ fullCriteriaStr = "";
+ for (int i = 0; i < criteriaArray.length(); i++) {
+ if (i > 0) {
+ fullCriteriaStr += JsonConstants.IN_PARAMETER_SEPARATOR;
+ }
+ fullCriteriaStr += criteriaArray.getJSONObject(i).toString();
+ }
+ }
+ final String[] criteriaStrs =
fullCriteriaStr.split(JsonConstants.IN_PARAMETER_SEPARATOR);
+ if (!fullCriteriaStr.equals("")) {
+ for (String criteriaStr : criteriaStrs) {
+ final JSONObject criteriaJSONObject = new JSONObject(criteriaStr);
+ if (criteriaJSONObject.has("fieldName")) {
+ final String fieldName =
criteriaJSONObject.getString("fieldName");
+ if (!fieldName.startsWith("_")) {
+ criteriaObjects.add(criteriaJSONObject);
+ }
+ } else {
+ criteriaObjects.add(criteriaJSONObject);
+ }
+ }
+ }
+ }
+ criteria.put("criteria", new JSONArray(criteriaObjects));
+ return criteria;
+ } catch (JSONException e) {
+ throw new OBException(e);
+ }
+ }
+
}
diff -r 03f21336f3da -r 715e5f37db43
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
---
a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
Wed Mar 09 12:34:16 2011 -0600
+++
b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/CustomQuerySelectorDatasource.java
Wed Mar 09 19:36:04 2011 +0100
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -30,6 +31,9 @@
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
import org.hibernate.Query;
import org.hibernate.criterion.Expression;
import org.openbravo.base.model.ModelProvider;
@@ -177,11 +181,18 @@
boolean hasFilter = false;
List<SelectorField> fields = OBDao.getActiveOBObjectList(sel,
Selector.PROPERTY_OBUISELSELECTORFIELDLIST);
+ HashMap<String, String> criteria = getCriteria(parameters);
for (SelectorField field : fields) {
if (StringUtils.isEmpty(field.getClauseLeftPart())) {
continue;
}
- String value = parameters.get(field.getDisplayColumnAlias());
+ String value = null;
+ if (criteria != null) {
+ value = criteria.get(field.getDisplayColumnAlias());
+ }
+ if (StringUtils.isEmpty(value)) {
+ value = parameters.get(field.getDisplayColumnAlias());
+ }
// Add field default expression on picklist if it is not already
filtered. Default expressions
// on selector popup are already evaluated and their values came in the
parameters object.
if (field.getDefaultExpression() != null && !"Window".equals(requestType)
@@ -424,4 +435,23 @@
return 0;
}
+ private HashMap<String, String> getCriteria(Map<String, String> parameters) {
+ if (!"AdvancedCriteria".equals(parameters.get("_constructor"))) {
+ return null;
+ }
+ HashMap<String, String> criteriaValues = new HashMap<String, String>();
+ try {
+ JSONArray criterias = (JSONArray)
JsonUtils.buildCriteria(parameters).get("criteria");
+ for (int i = 0; i < criterias.length(); i++) {
+ final JSONObject criteria = criterias.getJSONObject(i);
+ criteriaValues.put(criteria.getString("fieldName"),
criteria.getString("value"));
+ }
+ } catch (JSONException e) {
+ // Ignore exception.
+ }
+ if (criteriaValues.isEmpty()) {
+ return null;
+ }
+ return criteriaValues;
+ }
}
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits