details: https://code.openbravo.com/erp/devel/pi/rev/a496e0ae760c changeset: 24139:a496e0ae760c user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Wed Jul 30 15:31:26 2014 +0200 summary: fixed bug 27233: incorrect combos if selected value is not in 1st page
details: https://code.openbravo.com/erp/devel/pi/rev/687d91cddde8 changeset: 24140:687d91cddde8 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Wed Jul 30 15:33:11 2014 +0200 summary: related to bug 27233: added test case diffstat: modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ComboTableDatasourceService.java | 10 +- src-test/org/openbravo/test/datasource/TestComboDatasource.java | 31 +++++- src/org/openbravo/erpCommon/utility/ComboTableData.java | 53 ++++++--- 3 files changed, 73 insertions(+), 21 deletions(-) diffs (138 lines): diff -r 67abd792f3d3 -r 687d91cddde8 modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ComboTableDatasourceService.java --- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ComboTableDatasourceService.java Wed Jul 30 13:40:16 2014 +0530 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ComboTableDatasourceService.java Wed Jul 30 15:33:11 2014 +0200 @@ -160,8 +160,14 @@ if (!StringUtils.isEmpty(filterString)) { newParameters.put("FILTER_VALUE", filterString); } - fps = comboTableData.select(new DalConnectionProvider(false), newParameters, true, startRow, - endRow); + + boolean optionalFieldNonFirstPage = !column.isMandatory() && startRow > 0 + && StringUtils.isEmpty(filterString); + // non-mandatory fields add a blank record at the beginning of 1st page, this needs to be + // taken into account in subsequent pages + + fps = comboTableData.select(new DalConnectionProvider(false), newParameters, true, startRow + - (optionalFieldNonFirstPage ? 1 : 0), endRow - (optionalFieldNonFirstPage ? 1 : 0)); ArrayList<JSONObject> comboEntries = new ArrayList<JSONObject>(); // If column is mandatory we add an initial blank value in the first page if not filtered diff -r 67abd792f3d3 -r 687d91cddde8 src-test/org/openbravo/test/datasource/TestComboDatasource.java --- a/src-test/org/openbravo/test/datasource/TestComboDatasource.java Wed Jul 30 13:40:16 2014 +0530 +++ b/src-test/org/openbravo/test/datasource/TestComboDatasource.java Wed Jul 30 15:33:11 2014 +0200 @@ -35,7 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TestComboDatasource extends BaseDataSourceTestNoDal { +public class TestComboDatasource extends BaseDataSourceTestDal { private static final Logger log = LoggerFactory.getLogger(TestComboDatasource.class); @@ -107,6 +107,35 @@ } /** + * Checks selected value not in 1st page + * + * see issue #27233 + */ + public void testDefaultNotInFirstPage() throws Exception { + String US_ID = "100"; + + Map<String, String> params = new HashMap<String, String>(); + params.put("fieldId", "1005500085"); // BP > Account > Country + params.put("_operationType", "fetch"); + params.put("_startRow", "0"); + params.put("_endRow", "75"); + params.put("_currentValue", US_ID); // US + + JSONObject jsonResponse = requestCombo(params); + JSONArray data = getData(jsonResponse); + assertTrue(getStatus(jsonResponse).equals( + String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); + + int totalRows = jsonResponse.getJSONObject("response").getInt("totalRows"); // 78 + int endRow = jsonResponse.getJSONObject("response").getInt("endRow"); // 76 + assertTrue("more than one page shoudl be detected", totalRows > endRow + 1); + String lastRowId = data.getJSONObject(data.length() - 1).getString("id"); + assertFalse( + "selected record should not be added at the end of 1st page, because it is in a page after it", + lastRowId.equals(US_ID)); + } + + /** * Test to check filtering of the record using passed parameter * * @throws Exception diff -r 67abd792f3d3 -r 687d91cddde8 src/org/openbravo/erpCommon/utility/ComboTableData.java --- a/src/org/openbravo/erpCommon/utility/ComboTableData.java Wed Jul 30 13:40:16 2014 +0530 +++ b/src/org/openbravo/erpCommon/utility/ComboTableData.java Wed Jul 30 15:33:11 2014 +0200 @@ -1124,6 +1124,7 @@ } if (includeActual && actual != null && !actual.equals("")) { + String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; String strSqlDisc = getQuery(true, discard, null, null, null, null, false); PreparedStatement stInactive = conn.getPreparedStatement(strSqlDisc); @@ -1188,24 +1189,40 @@ result.close(); if (includeActual && actual != null && !actual.equals("") && !idFound) { - conn.releasePreparedStatement(st); - String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; - strSql = getQuery(true, discard, null, null, null, null, false); - if (log4j.isDebugEnabled()) - log4j.debug("SQL Actual ID: " + strSql); - st = conn.getPreparedStatement(strSql); - iParameter = setSQLParameters(st, lparameters, 0, discard); - UtilSql.setValue(st, ++iParameter, 12, null, actual); - result = st.executeQuery(); - while (result.next()) { - SQLReturnObject sqlReturnObject = new SQLReturnObject(); - sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); - String strName = UtilSql.getValue(result, "NAME"); - if (!strName.startsWith(INACTIVE_DATA)) - strName = INACTIVE_DATA + strName; - sqlReturnObject.setData("NAME", strName); - vector.addElement(sqlReturnObject); - idFound = true; + boolean allDataInSinglePage = startRow == 0 && vector.size() < endRow - startRow; + if (!allDataInSinglePage) { + // retrieved a partial set of data, checking if current id is in a page different that the + // served applying the same criteria, if so, do not add it again to the list (it will + // appear in its own page) + conn.releasePreparedStatement(st); + strSql = getQuery(true, null, null, 0, 1, conn, !StringUtils.isEmpty(filterValue)); + log4j.debug("SQL to check if actual ID is in another page: " + strSql); + st = conn.getPreparedStatement(strSql); + setSQLParameters(st, lparameters, 0, null, actual, filterValue); + result = st.executeQuery(); + idFound = result.next(); + result.close(); + } + if (!idFound) { + conn.releasePreparedStatement(st); + String[] discard = { "filter", "orderBy", "CLIENT_LIST", "ORG_LIST" }; + strSql = getQuery(true, discard, null, null, null, null, false); + if (log4j.isDebugEnabled()) + log4j.debug("SQL Actual ID: " + strSql); + st = conn.getPreparedStatement(strSql); + iParameter = setSQLParameters(st, lparameters, 0, discard); + UtilSql.setValue(st, ++iParameter, 12, null, actual); + result = st.executeQuery(); + if (result.next()) { + SQLReturnObject sqlReturnObject = new SQLReturnObject(); + sqlReturnObject.setData("ID", UtilSql.getValue(result, "ID")); + String strName = UtilSql.getValue(result, "NAME"); + if (!strName.startsWith(INACTIVE_DATA)) + strName = INACTIVE_DATA + strName; + sqlReturnObject.setData("NAME", strName); + vector.addElement(sqlReturnObject); + idFound = true; + } } result.close(); if (!idFound) { ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
