details: https://code.openbravo.com/erp/devel/main/rev/dd959ca91073 changeset: 25109:dd959ca91073 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Tue Nov 18 22:10:10 2014 +0100 summary: Fixes issue 28214: _selectedProperties parameter work in JSON REST webservice
In a call to the Openbravo JSON REST webservice, the _selectedProperties parameter allows the user to specify the set of properties whose values should be returned by the webservice. This property was working properly when an ID is specified in the request, but not if it is not specified. This stopped working because of this issue [1]. [1] implements a new method to handlle the case when the ID is not specified to improve the performance, but its missing the handling of _selectedProperties. [1] https://code.openbravo.com/erp/devel/pi/rev/c171ecac2673 details: https://code.openbravo.com/erp/devel/main/rev/35c3b66543dd changeset: 25110:35c3b66543dd user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Nov 21 14:25:25 2014 +0100 summary: related to bug 28214: added test case details: https://code.openbravo.com/erp/devel/main/rev/69fa80585f96 changeset: 25111:69fa80585f96 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Thu Nov 20 11:48:06 2014 +0530 summary: Fixes Issue 28226:Is not possible to Void a shipment related with an order and containing a negative line A check to avoid MovementQtyCheck for Reversed Document is provided. diffstat: modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java | 5 + src-db/database/model/functions/M_INOUT_POST.xml | 12 +- src-test/src/org/openbravo/test/AllWebserviceTests.java | 4 +- src-test/src/org/openbravo/test/webservice/JSONWebServices.java | 115 ++++++++++ 4 files changed, 132 insertions(+), 4 deletions(-) diffs (198 lines): diff -r 2a84d451ce38 -r 69fa80585f96 modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java --- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java Wed Nov 19 18:09:26 2014 +0100 +++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java Thu Nov 20 11:48:06 2014 +0530 @@ -261,9 +261,14 @@ final DataEntityQueryService queryService = createSetQueryService(parameters, false); queryService.setEntityName(entityName); + String selectedProperties = parameters.get(JsonConstants.SELECTEDPROPERTIES_PARAMETER); + final DataToJsonConverter toJsonConverter = OBProvider.getInstance().get( DataToJsonConverter.class); toJsonConverter.setAdditionalProperties(JsonUtils.getAdditionalProperties(parameters)); + // Convert to Json only the properties specified in the request. If no properties are specified, + // all of them will be converted to Json + toJsonConverter.setSelectedProperties(selectedProperties); final ScrollableResults scrollableResults = queryService.scroll(); try { diff -r 2a84d451ce38 -r 69fa80585f96 src-db/database/model/functions/M_INOUT_POST.xml --- a/src-db/database/model/functions/M_INOUT_POST.xml Wed Nov 19 18:09:26 2014 +0100 +++ b/src-db/database/model/functions/M_INOUT_POST.xml Thu Nov 20 11:48:06 2014 +0530 @@ -114,6 +114,7 @@ v_released NUMBER; v_IsQtyVariable M_Product.IsQuantityVariable%TYPE; + v_IsReversedDoc CHAR(1); BEGIN @@ -223,7 +224,12 @@ RAISE_APPLICATION_ERROR(-20000, '@Inline@ '||v_Message_Qty||' '||'@ProductNotNullAndMovementQtyZero@') ; END IF; End ; - if(v_isreturndoctype = 'N' AND v_isSoTrx = 'Y' and v_DocAction<>'RC') then + SELECT CASE WHEN COALESCE(instr(M_INOUT.Description,'*R*:'),0) = 0 THEN 'N' ELSE 'Y' END + INTO v_IsReversedDoc + FROM M_INOUT + WHERE M_INOUT.M_INOUT_id = v_Record_ID; + -- Skip MovementQtyCheck when it is reversed document + if(v_isreturndoctype = 'N' AND v_isSoTrx = 'Y' and v_DocAction<>'RC' AND v_IsReversedDoc='N') then v_message := null; for Cur_OrderLine in ( select c_orderline_id, line, m_product_id @@ -232,13 +238,13 @@ and c_orderline_id is not null order by line ) loop - select COALESCE(sum(movementqty), 0) + select COALESCE(sum(ABS(movementqty)), 0) into v_qty from m_inoutline where m_inout_id = v_Record_ID and c_orderline_id = Cur_OrderLine.c_orderline_id; - select qtyordered, (coalesce(qtydelivered, 0) + v_qty) + select ABS(qtyordered), (coalesce(ABS(qtydelivered), 0) + v_qty) into v_QuantityOrder, v_qty from c_orderline where c_orderline_id = Cur_OrderLine.c_orderline_id; diff -r 2a84d451ce38 -r 69fa80585f96 src-test/src/org/openbravo/test/AllWebserviceTests.java --- a/src-test/src/org/openbravo/test/AllWebserviceTests.java Wed Nov 19 18:09:26 2014 +0100 +++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java Thu Nov 20 11:48:06 2014 +0530 @@ -26,6 +26,7 @@ import org.openbravo.test.datasource.SelectorFieldPropertySelectorDSTest; import org.openbravo.test.datasource.TestCSVEncoding; import org.openbravo.test.datasource.TestComboDatasource; +import org.openbravo.test.webservice.JSONWebServices; import org.openbravo.test.webservice.PerformanceTest; import org.openbravo.test.webservice.WSAddRecordWithComputedColumns; import org.openbravo.test.webservice.WSReadTest; @@ -48,6 +49,7 @@ SelectorFieldPropertySelectorDSTest.class, // ProductSelectorDataSourceTest.class, // TestComboDatasource.class, // - FKDropDownDatasource.class }) + FKDropDownDatasource.class, // + JSONWebServices.class }) public class AllWebserviceTests { } diff -r 2a84d451ce38 -r 69fa80585f96 src-test/src/org/openbravo/test/webservice/JSONWebServices.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/webservice/JSONWebServices.java Thu Nov 20 11:48:06 2014 +0530 @@ -0,0 +1,115 @@ +/* + ************************************************************************* + * 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.webservice; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; +import org.openbravo.base.exception.OBException; + +/** + * Test cases for JSON dal web services + * + * @author alostale + * + */ +public class JSONWebServices extends BaseWSTest { + @SuppressWarnings("serial") + private final Set<String> expectedProperties = new HashSet<String>() { + { + // infrastructure properties, always present in all responses + add("_identifier"); + add("_entityName"); + add("$ref"); + add("recordTime"); + + // selected properties + add("id"); + add("name"); + } + }; + + /** When getting a single record by id, selected properties should be taken into account */ + @Test + public void selectedPropertiesUsingId() throws JSONException { + JSONObject resp = new JSONObject( + request("Country", "100", "_selectedProperties=id,name", "GET")); + assertSingleRecord(resp); + } + + /** + * When getting a set of records without id, selected properties should be taken into account. + * + * See https://issues.openbravo.com/view.php?id=28214 + */ + @Test + public void selectedPropertiesNotUsingId() throws JSONException { + JSONObject resp = new JSONObject(request("Country", "", "_selectedProperties=id,name", "GET")); + JSONObject firstRecord = resp.getJSONObject("response").getJSONArray("data").getJSONObject(0); + assertSingleRecord(firstRecord); + } + + private void assertSingleRecord(JSONObject resp) { + @SuppressWarnings("unchecked") + Iterator<String> it = resp.keys(); + Set<String> receivedProperties = new HashSet<String>(); + + while (it.hasNext()) { + receivedProperties.add(it.next()); + } + + assertThat("Properties received in JSON", receivedProperties, is(equalTo(expectedProperties))); + } + + private String request(String entityName, String id, String queryPart, String method) { + String wsPart = entityName + (id == null ? "" : "/" + id) + + (queryPart == null ? "" : "?" + queryPart); + + final StringBuilder sb = new StringBuilder(); + try { + + final HttpURLConnection hc = createConnection("/org.openbravo.service.json.jsonrest/" + + wsPart, method); + hc.connect(); + final InputStream is = hc.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + + String line; + while ((line = reader.readLine()) != null) { + sb.append(line).append("\n"); + } + return sb.toString(); + } catch (Exception e) { + throw new OBException("Exception when executing ws: " + wsPart, e); + } + } +} ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits