details:   https://code.openbravo.com/erp/devel/pi/rev/5f989d992338
changeset: 28577:5f989d992338
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Mon Feb 08 09:06:40 2016 +0100
summary:   related to issue 32091: code review improvements

After sorting the grid without having any filter applied, the selection was not 
being kept on top. To solve this, now we check if there is a criteria present 
in the request and also if there are selected records. In that case, a new 
criteria is included in the request with the ids of the selected records.

Besides, two methods are deleted from AddPaymentOrderInvoicesTransformer as 
they are no longer needed. And a new check is added when retrieving the 
selected records in the backend, in order to avoid a possible JSONException.

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
 |  35 +--------
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
        |   4 +
 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
                |   6 +-
 3 files changed, 12 insertions(+), 33 deletions(-)

diffs (96 lines):

diff -r 42c991e213ba -r 5f989d992338 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
       Tue Feb 02 13:45:46 2016 -0500
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
       Mon Feb 08 09:06:40 2016 +0100
@@ -330,21 +330,7 @@
   /**
    * Order by selectedPSDs, scheduled date and document number
    */
-  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,
+  private List<String> getOrderByClauses(String transactionType, List<String> 
selectedPSDs,
       Map<String, String> requestParameters) {
     List<String> orderByClauses = new ArrayList<String>();
     if (selectedPSDs.size() == 0) {
@@ -532,21 +518,7 @@
     return hqlQuery;
   }
 
-  protected String appendOrderByClause(String _hqlQuery, StringBuffer 
orderByClause,
-      boolean justCount) {
-    String hqlQuery = _hqlQuery;
-    if (!justCount) {
-      if (hqlQuery.contains(" ORDER BY ")) {
-        hqlQuery = hqlQuery.concat(", ");
-      } else {
-        hqlQuery = hqlQuery.concat(" ORDER BY ");
-      }
-      hqlQuery = hqlQuery.concat(orderByClause.toString());
-    }
-    return hqlQuery;
-  }
-
-  protected String appendOrderByClauses(String _hqlQuery, List<String> 
orderByClauses,
+  private String appendOrderByClauses(String _hqlQuery, List<String> 
orderByClauses,
       boolean justCount) {
     final String orderby = " ORDER BY ";
     String hqlQuery = _hqlQuery;
@@ -573,7 +545,8 @@
     JSONArray newCriteriaArray = new JSONArray();
     for (int i = 0; i < criteriaArray.length(); i++) {
       JSONObject criteria = criteriaArray.getJSONObject(i);
-      if (criteria.has("fieldName") && 
criteria.getString("fieldName").equals("id")) {
+      if (criteria.has("fieldName") && 
criteria.getString("fieldName").equals("id")
+          && criteria.has("value")) {
         String value = criteria.getString("value");
         for (String psdID : value.split(",")) {
           JSONObject newCriteria = criteria;
diff -r 42c991e213ba -r 5f989d992338 
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
      Tue Feb 02 13:45:46 2016 -0500
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
      Mon Feb 08 09:06:40 2016 +0100
@@ -185,6 +185,10 @@
       if (me.view && me.view.buttonOwnerView && me.view.buttonOwnerView.tabId) 
{
         dsRequest.params.buttonOwnerViewTabId = me.view.buttonOwnerView.tabId;
       }
+      // Add selected records (if any) when there is not criteria present in 
the request
+      if (dsRequest.originalData && !dsRequest.originalData.criteria && 
me.selectedIds.length) {
+        isc.addProperties(dsRequest.originalData, 
me.addSelectedIDsToCriteria());
+      }
       dsRequest.params[OB.Constants.IS_PICK_AND_EDIT] = true;
       return this.Super('transformRequest', arguments);
     };
diff -r 42c991e213ba -r 5f989d992338 
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
      Tue Feb 02 13:45:46 2016 -0500
+++ 
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
      Mon Feb 08 09:06:40 2016 +0100
@@ -190,7 +190,8 @@
     if (hasCriteria) {
       try {
         selectedRecords = 
getSelectedRecordsFromCriteria(JsonUtils.buildCriteria(parameters));
-      } catch (JSONException ignore) {
+      } catch (JSONException jsonex) {
+        log.error("Error retrieving number of selected records", jsonex);
       }
     }
     return selectedRecords.size();
@@ -202,7 +203,8 @@
     JSONArray criteriaArray = buildCriteria.getJSONArray("criteria");
     for (int i = 0; i < criteriaArray.length(); i++) {
       JSONObject criteria = criteriaArray.getJSONObject(i);
-      if (criteria.has("fieldName") && 
criteria.getString("fieldName").equals("id")) {
+      if (criteria.has("fieldName") && 
criteria.getString("fieldName").equals("id")
+          && criteria.has("value")) {
         String value = criteria.getString("value");
         for (String recordId : value.split(",")) {
           selectedRecords.add(recordId.trim());

------------------------------------------------------------------------------
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

Reply via email to