Related with bug 29612: Applies properly the client/organizations filter
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 12 May 2015 13:13:23 +0200
changeset 27114 5a4a2606f285
parent 27113 e65e148f179c
child 27115 f9b82970014e
Related with bug 29612: Applies properly the client/organizations filter

If the column being filtered referenced the Client or Organization entity, then the resulting query was not including the where clause to filter the readable clients and organizations, respectively. This is a known issue, reported here [1].

This issue cannot be easily fixed, so this project address it by adding manually the readable client or organization filter if the entity being filtered is client or organization and if the query is being built as a result of opening the dropdown of one of the new unfiltered foreign key filters.

[1] https://issues.openbravo.com/view.php?id=29846
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon May 11 13:45:43 2015 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Tue May 12 13:13:23 2015 +0200
@@ -286,6 +286,22 @@
       }
 
       typedParameters.addAll(subEntityQueryBuilder.typedParameters);
+    } else if (filterParameters.containsKey(JsonConstants.SHOW_FK_DROPDOWN_UNFILTERED_PARAMETER)) {
+      // If the entity is Client or Organization, we need to add the readable Client or
+      // Organization filter manually, because the OBQuery will not be able to do it
+      // See issue https://issues.openbravo.com/view.php?id=29846
+      String subEntityClientOrg = "";
+      String whereClauseFirstWord = StringUtils.isEmpty(whereClause.trim()) ? "where" : "and";
+      if (entity.getMappingClass().isAssignableFrom(Organization.class)) {
+        subEntityClientOrg = " " + whereClauseFirstWord + " e.id "
+            + createInClause(OBContext.getOBContext().getReadableOrganizations());
+      } else if (entity.getMappingClass().isAssignableFrom(Client.class)) {
+        subEntityClientOrg = " " + whereClauseFirstWord + " e.id "
+            + createInClause(OBContext.getOBContext().getReadableClients());
+      }
+      if (!subEntityClientOrg.isEmpty()) {
+        whereClause += subEntityClientOrg;
+      }
     }
 
     return whereClause;
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Mon May 11 13:45:43 2015 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Tue May 12 13:13:23 2015 +0200
@@ -337,6 +337,8 @@
             .getEntity(entityName), distinctPropertyPath);
         final Entity distinctEntity = distinctProperty.getTargetEntity();
         queryService.setEntityName(distinctEntity.getName());
+        queryService
+            .addFilterParameter(JsonConstants.SHOW_FK_DROPDOWN_UNFILTERED_PARAMETER, "true");
         queryService.setFilterOnReadableOrganizations(filterOnReadableOrganizations);
         if (parameters.containsKey(JsonConstants.USE_ALIAS)) {
           queryService.setUseAlias();