details: https://code.openbravo.com/erp/devel/pi/rev/468a1d34cac5 changeset: 29564:468a1d34cac5 user: Naroa Iriarte <naroa.iriarte <at> openbravo.com> date: Mon May 30 15:28:06 2016 +0200 summary: Fixed issue 33073: It was not possible to use _where param in JSON webservices
It was not possible to filter using the "_where" parameter. The "whereAndFilterClause" parameter was needed instead. This was not correct because in the Webservices we must mantain the use of the "_where" parameter to filter the data. This has been fixed in the "JSONRestServlet" class. Before calling the fetch method, the "whereAndFilterClause" has been overwritten with the value of the "_where" parameter. Now when a user uses "_where" in a query of a JSON webService, that value will be set in the "whereAndFilterClause" parameter and will work properly. details: https://code.openbravo.com/erp/devel/pi/rev/ec9932c34210 changeset: 29565:ec9932c34210 user: Naroa Iriarte <naroa.iriarte <at> openbravo.com> date: Mon May 30 17:26:21 2016 +0200 summary: Related to issue 33073: A test has been added. A test that checks the correct behavior has been added. diffstat: modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java | 2 + src-test/src/org/openbravo/test/AllWebserviceTests.java | 4 +- src-test/src/org/openbravo/test/webservice/JSONWebServicesWhereParameter.java | 47 ++++++++++ 3 files changed, 52 insertions(+), 1 deletions(-) diffs (83 lines): diff -r f62e834ae3c2 -r ec9932c34210 modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java --- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java Tue May 31 10:44:19 2016 +0200 +++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java Mon May 30 17:26:21 2016 +0200 @@ -157,6 +157,8 @@ JSONStreamWriter writer = new JSONStreamWriter(response, parameters); parameters.put(JsonConstants.USE_ALIAS, "true"); parameters.put(JsonConstants.IS_WS_CALL, "true"); + parameters.put(JsonConstants.WHERE_AND_FILTER_CLAUSE, + parameters.get(JsonConstants.WHERE_PARAMETER)); DefaultJsonDataService.getInstance().fetch(parameters, writer); writer.close(); } diff -r f62e834ae3c2 -r ec9932c34210 src-test/src/org/openbravo/test/AllWebserviceTests.java --- a/src-test/src/org/openbravo/test/AllWebserviceTests.java Tue May 31 10:44:19 2016 +0200 +++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java Mon May 30 17:26:21 2016 +0200 @@ -43,6 +43,7 @@ import org.openbravo.test.webservice.WSUpdateTest; import org.openbravo.test.webservice.WSWithNoActiveDalObjects; import org.openbravo.test.webservice.WebServicesWithNoActiveFilterTest; +import org.openbravo.test.webservice.JSONWebServicesWhereParameter; /** * This test suite should only contain test cases which are to run the webservices included in core. @@ -74,6 +75,7 @@ FetchDSNoActiveEntityObjects.class, // ExplicitCrossOrganizationReference.class, // DataSourceSecurity.class, // - EmptyStringWhereAndFilterClauseParameter.class }) + EmptyStringWhereAndFilterClauseParameter.class, // + JSONWebServicesWhereParameter.class }) public class AllWebserviceTests { } diff -r f62e834ae3c2 -r ec9932c34210 src-test/src/org/openbravo/test/webservice/JSONWebServicesWhereParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/webservice/JSONWebServicesWhereParameter.java Mon May 30 17:26:21 2016 +0200 @@ -0,0 +1,47 @@ +/* + ************************************************************************* + * 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)2016 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ +package org.openbravo.test.webservice; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; + +/** + * This test evaluates the correct behavior of a JSON webservice request using the "_where" + * parameter. + * + * @author Naroa Iriarte + * + */ +public class JSONWebServicesWhereParameter extends BaseWSTest { + + @Test + public void WebserviceWithWhereParameter() throws Exception { + JSONWebServices jws = new JSONWebServices(); + JSONObject resp = new JSONObject(jws.request("Country", null, "_where=name='Spain'", "GET")) + .getJSONObject("response"); + JSONObject firstRecord = resp.getJSONArray("data").getJSONObject(0); + assertThat("Spanish Country", firstRecord.getString("_identifier"), is(equalTo("Spain"))); + assertThat("Sucess status", resp.getInt("status"), is(0)); + assertThat("Total Rows", resp.getInt("totalRows"), is(1)); + } +} ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits