details: https://code.openbravo.com/erp/devel/pi/rev/905bb6ff4ee7 changeset: 28567:905bb6ff4ee7 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Wed Feb 03 19:26:25 2016 +0100 summary: fixes issue 31989: Wrong behavior in P&E grids having > 100 records selected After performing a filter/ordering action, the selected records could go out of the first page, causing the Add Payment process crash inside updateInvOrderTotal function (executed on grid load), because the selected record could not be found on the local data. To avoid the problem now the ReadOnlyDataSource fetches all the selected records in the first page, increasing the page size if necessary. Together with this, all the P&E processes must ensure that the data is always ordered by showing first the selected records.
details: https://code.openbravo.com/erp/devel/pi/rev/fc90763f8bed changeset: 28568:fc90763f8bed user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Wed Feb 03 19:29:23 2016 +0100 summary: fixes issue 32091: The Order/Invoices grid now sorts by selected records first Now the AddPaymentOrderInvoicesTransformer places first the selected record criteria for ordering, put it just before the ordering criteria selected by the user in the grid. diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java | 73 +++++- modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js | 1 + modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl | 5 +- modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java | 96 +++++++++- 4 files changed, 148 insertions(+), 27 deletions(-) diffs (truncated from 341 to 300 lines): diff -r 0552a2b32bd2 -r fc90763f8bed modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java Wed Feb 03 11:18:59 2016 +0100 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java Wed Feb 03 19:29:23 2016 +0100 @@ -11,7 +11,7 @@ * 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 - 2015 Openbravo SLU + * All portions are Copyright (C) 2014 - 2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -74,9 +74,9 @@ StringBuffer joinClauseInvoice = getJoinClauseInvoice(requestParameters); StringBuffer whereClause = getWhereClause(transactionType, requestParameters, selectedPSDs); StringBuffer groupByClause = getGroupByClause(transactionType); - StringBuffer orderByClause = new StringBuffer(); + List<String> orderByClauses = new ArrayList<String>(); if (!justCount) { - orderByClause = getOrderByClause(transactionType, selectedPSDs, requestParameters); + orderByClauses = getOrderByClauses(transactionType, selectedPSDs, requestParameters); } // grid filters need to be removed from where clause and added as a having criteria. @@ -103,7 +103,7 @@ transformedHql = transformedHql.replace("@joinClauseInvoice@", joinClauseInvoice.toString()); transformedHql = transformedHql.replace("@whereClause@", whereClause.toString()); transformedHql = transformedHql.replace("@groupByClause@", groupByClause.toString()); - transformedHql = appendOrderByClause(transformedHql, orderByClause, justCount); + transformedHql = appendOrderByClauses(transformedHql, orderByClauses, justCount); // Sets parameters queryNamedParameters.put("currencyId", requestParameters.get("c_currency_id")); queryNamedParameters.put("isSalesTransaction", @@ -333,43 +333,59 @@ protected StringBuffer getOrderByClause(String transactionType, List<String> selectedPSDs, Map<String, String> requestParameters) { StringBuffer orderByClause = new StringBuffer(); + List<String> orderByClauses = getOrderByClauses(transactionType, selectedPSDs, + requestParameters); + for (String clause : orderByClauses) { + orderByClause.append(clause); + } + return orderByClause; + } + + /** + * Order by selectedPSDs, scheduled date and document number + */ + protected List<String> getOrderByClauses(String transactionType, List<String> selectedPSDs, + Map<String, String> requestParameters) { + List<String> orderByClauses = new ArrayList<String>(); if (selectedPSDs.size() == 0) { String strInvoiceId = requestParameters.get("c_invoice_id"); String strOrderId = requestParameters.get("c_order_id"); if (strInvoiceId != null) { - orderByClause.append(" CASE WHEN MAX(inv.id) = '" + strInvoiceId + "' THEN 0 ELSE 1 END "); + orderByClauses.add(" CASE WHEN MAX(inv.id) = '" + strInvoiceId + "' THEN 0 ELSE 1 END "); } else if (strOrderId != null) { - orderByClause.append(" CASE WHEN MAX(ord.id) = '" + strOrderId + "' THEN 0 ELSE 1 END "); + orderByClauses.add(" CASE WHEN MAX(ord.id) = '" + strOrderId + "' THEN 0 ELSE 1 END "); } else { - orderByClause.append(" CASE WHEN MAX(fp.id) IS NOT NULL THEN 0 ELSE 1 END "); + orderByClauses.add(" CASE WHEN MAX(fp.id) IS NOT NULL THEN 0 ELSE 1 END "); } } else { + StringBuffer selectedOrderBy = new StringBuffer(); String strAggId = getAggregatorFunction("psd.id"); - orderByClause.append(" CASE WHEN "); + selectedOrderBy.append(" CASE WHEN "); boolean isFirst = true; for (String strPSDId : selectedPSDs) { if (!isFirst) { - orderByClause.append(" OR "); + selectedOrderBy.append(" OR "); } - orderByClause.append(strAggId + " LIKE '%" + strPSDId + "%'"); + selectedOrderBy.append(strAggId + " LIKE '%" + strPSDId + "%'"); isFirst = false; } - orderByClause.append(" THEN 0 ELSE 1 END "); + selectedOrderBy.append(" THEN 0 ELSE 1 END "); + orderByClauses.add(selectedOrderBy.toString()); } if ("O".equals(transactionType)) { - orderByClause.append(", COALESCE(opriority.priority, ipriority.priority) "); - orderByClause.append(", COALESCE(ops.expectedDate, ips.expectedDate) "); + orderByClauses.add(", COALESCE(opriority.priority, ipriority.priority) "); + orderByClauses.add(", COALESCE(ops.expectedDate, ips.expectedDate) "); } else { - orderByClause.append(", COALESCE(ipriority.priority, opriority.priority) "); - orderByClause.append(", COALESCE(ips.expectedDate, ops.expectedDate) "); + orderByClauses.add(", COALESCE(ipriority.priority, opriority.priority) "); + orderByClauses.add(", COALESCE(ips.expectedDate, ops.expectedDate) "); } if ("O".equals(transactionType)) { - orderByClause.append(", ord.documentNo "); + orderByClauses.add(", ord.documentNo "); } else { - orderByClause.append(", inv.documentNo "); + orderByClauses.add(", inv.documentNo "); } - return orderByClause; + return orderByClauses; } protected String removeGridFilters(String _hqlQuery) { @@ -530,6 +546,27 @@ return hqlQuery; } + protected String appendOrderByClauses(String _hqlQuery, List<String> orderByClauses, + boolean justCount) { + final String orderby = " ORDER BY "; + String hqlQuery = _hqlQuery; + if (!justCount) { + if (hqlQuery.contains(orderby)) { + int offset = hqlQuery.indexOf(orderby) + orderby.length(); + StringBuilder sb = new StringBuilder(hqlQuery); + sb.insert(offset, orderByClauses.get(0) + ", "); + hqlQuery = sb.toString(); + orderByClauses.remove(0); + } else { + hqlQuery = hqlQuery.concat(orderby); + } + for (String clause : orderByClauses) { + hqlQuery = hqlQuery.concat(clause); + } + } + return hqlQuery; + } + protected void transformCriteria(JSONObject buildCriteria, List<String> selectedPSDs) throws JSONException { JSONArray criteriaArray = buildCriteria.getJSONArray("criteria"); diff -r 0552a2b32bd2 -r fc90763f8bed modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js Wed Feb 03 11:18:59 2016 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js Wed Feb 03 19:29:23 2016 +0100 @@ -185,6 +185,7 @@ if (me.view && me.view.buttonOwnerView && me.view.buttonOwnerView.tabId) { dsRequest.params.buttonOwnerViewTabId = me.view.buttonOwnerView.tabId; } + dsRequest.params[OB.Constants.IS_PICK_AND_EDIT] = true; return this.Super('transformRequest', arguments); }; filterableProperties = this.getFields().findAll('canFilter', true); diff -r 0552a2b32bd2 -r fc90763f8bed modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl --- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl Wed Feb 03 11:18:59 2016 +0100 +++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl Wed Feb 03 19:29:23 2016 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2009-2013 Openbravo SLU + * All portions are Copyright (C) 2009-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -72,7 +72,8 @@ TEXT_MATCH_PARAMETER_OVERRIDE: '_textMatchStyleOverride', SUCCESS : 'success', DBL_CLICK_DELAY: 300, - ERROR : 'error' + ERROR : 'error', + IS_PICK_AND_EDIT : '_isPickAndEdit' }, Styles : { diff -r 0552a2b32bd2 -r fc90763f8bed modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java --- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java Wed Feb 03 11:18:59 2016 +0100 +++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java Wed Feb 03 19:29:23 2016 +0100 @@ -11,19 +11,19 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2010-2014 Openbravo SLU + * All portions are Copyright (C) 2010-2016 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ */ package org.openbravo.service.datasource; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; @@ -35,6 +35,8 @@ import org.openbravo.service.json.DefaultJsonDataService.QueryResultWriter; import org.openbravo.service.json.JsonConstants; import org.openbravo.service.json.JsonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The SimpleDataSourceService provides a simple way of returning data in the correct format for a @@ -43,7 +45,11 @@ * @author mtaal */ public abstract class ReadOnlyDataSourceService extends DefaultDataSourceService { - private static final Logger log = Logger.getLogger(ReadOnlyDataSourceService.class); + private static final Logger log = LoggerFactory.getLogger(ReadOnlyDataSourceService.class); + private static final int DATA_PAGE_SIZE = 100; + private static final int MAX_PAGE_SIZE_INCREASE = 3; + private static final String NEW_END_ROW = "_newEndRow"; + private static final String IS_PICK_AND_EDIT = "_isPickAndEdit"; /* * (non-Javadoc) @@ -55,6 +61,7 @@ final String startRowStr = parameters.get(JsonConstants.STARTROW_PARAMETER); final String endRowStr = parameters.get(JsonConstants.ENDROW_PARAMETER); int startRow = 0; + int newEndRow = 0; boolean doCount = false; if (startRowStr != null) { startRow = Integer.parseInt(startRowStr); @@ -66,7 +73,9 @@ boolean preventCountOperation = "true".equals(parameters.get(JsonConstants.NOCOUNT_PARAMETER)); List<JSONObject> jsonObjects = fetchJSONObject(parameters); - + if (parameters.get(NEW_END_ROW) != null) { + newEndRow = Integer.parseInt(parameters.get(NEW_END_ROW)); + } // now jsonfy the data try { final JSONObject jsonResult = new JSONObject(); @@ -76,7 +85,7 @@ if (doCount && !preventCountOperation) { count = getCount(parameters); if (count == -1) { - int endRow = Integer.parseInt(endRowStr); + int endRow = newEndRow == 0 ? Integer.parseInt(endRowStr) : newEndRow; count = (endRow + 2); if ((endRow - startRow) > jsonObjects.size()) { count = startRow + jsonObjects.size(); @@ -85,7 +94,7 @@ } else { count = jsonObjects.size() + startRow; if (endRowStr != null) { - int endRow = Integer.parseInt(endRowStr); + int endRow = newEndRow == 0 ? Integer.parseInt(endRowStr) : newEndRow; // computedMaxResults is one too much, if we got one to much then correct // the result and up the count so that the grid knows that there are more int computedMaxResults = endRow - startRow + 1; @@ -132,7 +141,15 @@ if (tableId != null) { entity = ModelProvider.getInstance().getEntityByTableId(tableId); } - final List<Map<String, Object>> data = getData(parameters, startRow, endRow); + final String isPickAndEditParam = parameters.get(IS_PICK_AND_EDIT); + final boolean isPickAndEdit = isPickAndEditParam != null ? Boolean.valueOf(isPickAndEditParam) + : Boolean.FALSE; + final List<Map<String, Object>> data; + if (startRow == 0 && endRow != -1 && isPickAndEdit) { + data = getSelectedData(parameters, startRow, endRow); + } else { + data = getData(parameters, startRow, endRow); + } final DataToJsonConverter toJsonConverter = OBProvider.getInstance().get( DataToJsonConverter.class); toJsonConverter.setAdditionalProperties(JsonUtils.getAdditionalProperties(parameters)); @@ -140,6 +157,71 @@ return toJsonConverter.convertToJsonObjects(data); } + private List<Map<String, Object>> getSelectedData(Map<String, String> parameters, int startRow, + int endRow) { + List<Map<String, Object>> data; + int pageSizeIncreaseCount = 0; + int selectedRecords = getNumberOfSelectedRecords(parameters); + if (selectedRecords > DATA_PAGE_SIZE) { + data = getData(parameters, startRow, selectedRecords); + parameters.put(NEW_END_ROW, Integer.toString(selectedRecords)); + } else { + data = getData(parameters, startRow, endRow); + while (isLastRecordSelected(data) && pageSizeIncreaseCount < MAX_PAGE_SIZE_INCREASE) { + pageSizeIncreaseCount++; + log.debug( + "The amount of selected records is higher than the page size, increasing page size x{}", + pageSizeIncreaseCount + 1); + data = getData(parameters, startRow, endRow * (pageSizeIncreaseCount + 1)); + } + if (pageSizeIncreaseCount >= 1) { + parameters.put(NEW_END_ROW, Integer.toString(endRow * (pageSizeIncreaseCount + 1))); + if (pageSizeIncreaseCount == MAX_PAGE_SIZE_INCREASE) { + log.warn("The amount of selected records is higher than the maximum page size allowed."); + } + } + } + return data; + } + ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits