details:   https://code.openbravo.com/erp/devel/pi/rev/f5cb1a5fbecd
changeset: 14025:f5cb1a5fbecd
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Wed Oct 19 10:38:21 2011 +0200
summary:   Fixed issue 18770. On Custom Query selectors, the reference of the 
field will be checked

diffstat:

 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
 |  50 +++++++--
 1 files changed, 38 insertions(+), 12 deletions(-)

diffs (84 lines):

diff -r 89ab64d75b34 -r f5cb1a5fbecd 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
--- 
a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
       Wed Oct 19 10:13:56 2011 +0200
+++ 
b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
       Wed Oct 19 10:38:21 2011 +0200
@@ -35,6 +35,9 @@
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
 import org.openbravo.client.application.ParameterUtils;
+import org.openbravo.client.kernel.reference.StringUIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinitionController;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
@@ -114,6 +117,7 @@
     if (value == null) {
       return;
     }
+    boolean isCustomQuerySelector = sel.getHQL() != null;
     String filteredCriteria = "";
     String fieldName;
     Entity entity = ModelProvider.getInstance().getEntityByTableName(
@@ -124,7 +128,7 @@
       if (value.contains(JsonConstants.IN_PARAMETER_SEPARATOR)) {
         final String[] separatedValues = 
value.split(JsonConstants.IN_PARAMETER_SEPARATOR);
         for (String separatedValue : separatedValues) {
-         cEntity = entity;
+          cEntity = entity;
           JSONObject jSONObject = new JSONObject(separatedValue);
           fieldName = (String) jSONObject.get("fieldName");
           if (fieldName.contains("_dummy") || fieldName.contains("_identifier")
@@ -132,20 +136,42 @@
             filteredCriteria += jSONObject.toString() + 
JsonConstants.IN_PARAMETER_SEPARATOR;
             continue;
           }
-          String[] fieldNameSplit = fieldName.split("\\.");
-          Property fProp = null;
-          if (fieldNameSplit.length == 1) {
-            fProp = entity.getProperty(fieldName);
-          } else {
-            for (int i = 0; i < fieldNameSplit.length; i++) {
-              fProp = cEntity.getProperty(fieldNameSplit[i]);
-              if (i != fieldNameSplit.length - 1) {
-                cEntity = fProp.getReferencedProperty().getEntity();
+          boolean filterParameter = false;
+          if (isCustomQuerySelector) {
+            // This is a custom query selector. We cannot filter parameters by 
linking them to
+            // entity properties
+            // Instead, we will do it by checking the references of the fields
+            for (SelectorField field : sel.getOBUISELSelectorFieldList()) {
+              if (field.isSearchinsuggestionbox()) {
+                if (field.getDisplayColumnAlias().equals(fieldName)) {
+                  UIDefinition uiDef = 
UIDefinitionController.getInstance().getUIDefinition(
+                      field.getReference());
+                  if (!(uiDef instanceof StringUIDefinition)) {
+                    filterParameter = true;
+                  }
+                }
               }
             }
+          } else {
+            // A property in the entity is searched for this fieldName
+            // If the property is numeric or date, then it is filtered
+            String[] fieldNameSplit = fieldName.split("\\.");
+            Property fProp = null;
+            if (fieldNameSplit.length == 1) {
+              fProp = entity.getProperty(fieldName);
+            } else {
+              for (int i = 0; i < fieldNameSplit.length; i++) {
+                fProp = cEntity.getProperty(fieldNameSplit[i]);
+                if (i != fieldNameSplit.length - 1) {
+                  cEntity = fProp.getReferencedProperty().getEntity();
+                }
+              }
+            }
+            if (fProp.isNumericType() || fProp.isDate()) {
+              filterParameter = true;
+            }
           }
-
-          if (fProp.isNumericType() || fProp.isDate()) {
+          if (filterParameter) {
             try {
               jSONObject.put("operator", "equals");
               BigDecimal valueJSONObject = new 
BigDecimal(jSONObject.get("value").toString());

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to