fixed bug 19621: fixed null and not null filters on FK fields
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 13 Feb 2012 16:00:40 +0100
changeset 15480 e4e3a55d6378
parent 15479 3082e66a5d16
child 15481 34727a4bec62
fixed bug 19621: fixed null and not null filters on FK fields
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon Feb 13 12:02:18 2012 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon Feb 13 16:00:40 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -291,11 +291,7 @@
     String fieldName = jsonCriteria.getString("fieldName");
     Object value = jsonCriteria.has("value") ? jsonCriteria.get("value") : null;
 
-    if (operator.equals(OPERATOR_ISNULL)) {
-      operator = OPERATOR_EQUALS;
-      value = null;
-    } else if (operator.equals(OPERATOR_NOTNULL)) {
-      operator = OPERATOR_NOTEQUAL;
+    if (operator.equals(OPERATOR_ISNULL) || operator.equals(OPERATOR_NOTNULL)) {
       value = null;
     }
 
@@ -455,7 +451,12 @@
     // Within the if the leftWherePart is used because it contains the join aliases
     if (useFieldName.equals(JsonConstants.IDENTIFIER)
         || useFieldName.endsWith("." + JsonConstants.IDENTIFIER)) {
-      clause = computeLeftWhereClauseForIdentifier(useProperty, useFieldName, clause);
+      if (useFieldName.endsWith("." + JsonConstants.IDENTIFIER)
+          && (operator.equals(OPERATOR_ISNULL) || operator.equals(OPERATOR_NOTNULL))) {
+        clause = getMainAlias() + "." + useFieldName.replace("." + JsonConstants.IDENTIFIER, "");
+      } else {
+        clause = computeLeftWhereClauseForIdentifier(useProperty, useFieldName, clause);
+      }
     } else if (!useProperty.isPrimitive()) {
       clause = clause + ".id";
     }
@@ -818,6 +819,10 @@
       return "like";
     } else if (operator.equals(OPERATOR_ENDSWITHFIELD)) {
       return "like";
+    } else if (operator.equals(OPERATOR_ISNULL)) {
+      return "is";
+    } else if (operator.equals(OPERATOR_NOTNULL)) {
+      return "is not";
     }
     // todo throw exception
     return null;