details:   https://code.openbravo.com/erp/devel/pi/rev/e735bef86355
changeset: 25173:e735bef86355
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Nov 05 13:43:25 2014 +0100
summary:   fixed bug 28085: FK drop down filters don't work on 
Organization/Client windows

  The problem was due the generated query, it applied client/organization 
security
  assuming organization and client were in another entities.

  The fix cheks these special cases to do the security query based on that base
  entities.

details:   https://code.openbravo.com/erp/devel/pi/rev/b112216b499b
changeset: 25174:b112216b499b
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Nov 05 13:49:09 2014 +0100
summary:   related to bug 28085: added test case

  test case covering FK drop down datasource in Organization table

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
 |  24 +++-
 src-test/src/org/openbravo/test/AllWebserviceTests.java                        
             |   4 +-
 src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java           
             |  61 ++++++++++
 3 files changed, 86 insertions(+), 3 deletions(-)

diffs (128 lines):

diff -r 8d19acf2b006 -r b112216b499b 
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
       Thu Oct 23 22:28:56 2014 -0500
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Wed Nov 05 13:49:09 2014 +0100
@@ -54,7 +54,9 @@
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.domain.Reference;
 import org.openbravo.model.ad.domain.ReferencedTable;
+import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.service.db.DalConnectionProvider;
 
 /**
@@ -216,9 +218,27 @@
 
     if (subEntity != null) {
       // if there's subentity, process it as a subquery with "exists"
-      String subEntityClientOrg = " and e.organization.id "
+
+      String orgPath;
+      if (subEntity.getMappingClass().isAssignableFrom(Organization.class)) {
+        // special case subentity is Organization, so no extra path required 
to get it
+        orgPath = "e";
+      } else {
+        orgPath = "e.organization";
+      }
+
+      String subEntityClientOrg = " and " + orgPath + ".id "
           + 
createInClause(OBContext.getOBContext().getReadableOrganizations());
-      subEntityClientOrg += " and e.client.id "
+
+      String clientPath;
+      if (subEntity.getMappingClass().isAssignableFrom(Client.class)) {
+        // special case subentity is Client, so no extra path required to get 
it
+        clientPath = "e";
+      } else {
+        clientPath = "e.client";
+      }
+
+      subEntityClientOrg += " and " + clientPath + ".id "
           + createInClause(OBContext.getOBContext().getReadableClients());
 
       AdvancedQueryBuilder subEntityQueryBuilder = 
subDataEntityQueryService.getQueryBuilder();
diff -r 8d19acf2b006 -r b112216b499b 
src-test/src/org/openbravo/test/AllWebserviceTests.java
--- a/src-test/src/org/openbravo/test/AllWebserviceTests.java   Thu Oct 23 
22:28:56 2014 -0500
+++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java   Wed Nov 05 
13:49:09 2014 +0100
@@ -21,6 +21,7 @@
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
+import org.openbravo.test.datasource.FKDropDownDatasource;
 import org.openbravo.test.datasource.ProductSelectorDataSourceTest;
 import org.openbravo.test.datasource.SelectorFieldPropertySelectorDSTest;
 import org.openbravo.test.datasource.TestCSVEncoding;
@@ -46,6 +47,7 @@
     TestCSVEncoding.class, //
     SelectorFieldPropertySelectorDSTest.class, //
     ProductSelectorDataSourceTest.class, //
-    TestComboDatasource.class })
+    TestComboDatasource.class, //
+    FKDropDownDatasource.class })
 public class AllWebserviceTests {
 }
diff -r 8d19acf2b006 -r b112216b499b 
src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java      
Wed Nov 05 13:49:09 2014 +0100
@@ -0,0 +1,61 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2014 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.datasource;
+
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Test cases to check behavior of FK filter drop downs
+ * 
+ * @author alostale
+ *
+ */
+public class FKDropDownDatasource extends BaseDataSourceTestNoDal {
+
+  /**
+   * Drop down FK filter in Organization dataset is a special case because org 
filtering must be
+   * done in the base entity.
+   * 
+   * See issue 28085
+   */
+  @Test
+  public void filterFKInOrganization() throws Exception {
+    Map<String, String> params = new HashMap<String, String>();
+
+    params.put("tabId", "143");
+    params.put("_distinct", "organizationType");
+    params.put("_operationType", "fetch");
+    params.put("_startRow", "0");
+    params.put("_endRow", "75");
+    JSONObject resp = new 
JSONObject(doRequest("/org.openbravo.service.datasource/Organization",
+        params, 200, "POST")).getJSONObject("response");
+
+    assertThat("response status", resp.getInt("status"), is(0));
+    assertThat("number of rows", resp.getInt("totalRows"), greaterThan(0));
+  }
+}

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to