details:   https://code.openbravo.com/erp/devel/pi/rev/210aa57e9a79
changeset: 24089:210aa57e9a79
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Mon Jul 21 19:35:39 2014 +0530
summary:   Fixes issue 26696 : Filters work for table references

Filters are displayed properly if the display column is primitive or non 
primitive.
When a field that references another table is used, the displayed value is the 
identifier of the referred table.

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
 |  58 ++++++++-
 1 files changed, 51 insertions(+), 7 deletions(-)

diffs (95 lines):

diff -r 3de9f6eb5863 -r 210aa57e9a79 
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 Jul 21 14:15:37 2014 +0200
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Mon Jul 21 19:35:39 2014 +0530
@@ -637,8 +637,49 @@
         clause = getMainAlias() + DalUtil.DOT
             + useFieldName.replace(DalUtil.DOT + JsonConstants.IDENTIFIER, "");
       } else {
-        clause = computeLeftWhereClauseForIdentifier(useProperty, 
useFieldName, clause,
-            tableReference);
+        if (subEntity != null) {
+          final Property refProperty = this.distinctProperty;
+          tableReference = refProperty.getDomainType() instanceof 
TableDomainType;
+          final boolean isTable = property.getEntity() == 
ModelProvider.getInstance().getEntity(
+              Table.ENTITY_NAME);
+          if (isTable) {
+            useProperty = 
property.getEntity().getProperty(Table.PROPERTY_NAME);
+            final int index = useFieldName.indexOf(DalUtil.DOT);
+            useFieldName = useFieldName.substring(0, index + 1) + 
useProperty.getName();
+          } else {
+            // read the reference to get the table reference
+            final Reference reference = 
OBDal.getInstance().get(Reference.class,
+                refProperty.getDomainType().getReference().getId());
+            for (ReferencedTable referencedTable : 
reference.getADReferencedTableList()) {
+              if (referencedTable.isActive() && 
referencedTable.getDisplayedColumn() != null
+                  && referencedTable.getDisplayedColumn().isActive()) {
+                useProperty = property.getEntity().getPropertyByColumnName(
+                    referencedTable.getDisplayedColumn().getDBColumnName());
+                final int index = useFieldName.lastIndexOf(DalUtil.DOT);
+                if (useProperty.isPrimitive()) {
+                  useFieldName = useFieldName.substring(0, index + 1) + 
useProperty.getName();
+                } else {
+                  // adding _identifier so that the identifier properties will 
be formed properly in
+                  // computeLeftWhereClauseForIdentifier.
+                  useFieldName = useFieldName.substring(0, index + 1) + 
useProperty.getName()
+                      + DalUtil.DOT + JsonConstants.IDENTIFIER;
+                }
+                break;
+              }
+            }
+          }
+          clause = getEntity() + DalUtil.DOT + useFieldName;
+          if (!useProperty.isPrimitive()) {
+            clause = computeLeftWhereClauseForIdentifier(useProperty, 
useFieldName, clause,
+                tableReference);
+          } else {
+            // passing true for last argument to apply filterCriteria
+            clause = resolveJoins(properties, useFieldName, true);
+          }
+        } else {
+          clause = computeLeftWhereClauseForIdentifier(useProperty, 
useFieldName, clause,
+              tableReference);
+        }
       }
     } else if (!useProperty.isPrimitive()) {
       clause = clause + ".id";
@@ -648,7 +689,6 @@
       clause = computeLeftWhereClauseForIdentifier(useProperty, useFieldName, 
clause,
           tableReference);
     }
-
     if (ignoreCase(properties, operator)) {
       clause = "upper(" + clause + ")";
     }
@@ -867,15 +907,17 @@
     // property, that should work fine, as this last property is always part 
of the
     // identifier
     List<Property> identifierProperties = null;
+    identifierProperties = property.getEntity().getIdentifierProperties();
     if (!isTableReference) {
-      identifierProperties = property.getEntity().getIdentifierProperties();
       Check.isTrue(identifierProperties.contains(property), "Property " + 
property
           + " not part of identifier of " + property.getEntity());
     } else {
       // for table references, the display column identifier properties should 
be used in the joins
-      identifierProperties = 
property.getTargetEntity().getIdentifierProperties();
+      if (property.getTargetEntity() != null) {
+        identifierProperties = 
property.getTargetEntity().getIdentifierProperties();
+      }
     }
-    String prefix;
+    String prefix = "";
     final int index = leftWherePart.lastIndexOf(DalUtil.DOT);
     if (key.equals(JsonConstants.IDENTIFIER)) {
       prefix = getMainAlias() + DalUtil.DOT;
@@ -890,7 +932,9 @@
       prefix = "";
     } else {
       // the + 1 makes sure that the dot is included
-      prefix = leftWherePart.substring(0, index + 1);
+      if (index != -1) {
+        prefix = leftWherePart.substring(0, index + 1);
+      }
     }
     return createIdentifierLeftClause(identifierProperties, prefix);
   }

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to