details:   https://code.openbravo.com/erp/devel/pi/rev/9bfd8bde32b2
changeset: 30651:9bfd8bde32b2
user:      Naroa Iriarte <naroa.iriarte <at> openbravo.com>
date:      Fri Nov 11 10:10:29 2016 +0100
summary:   Fixed issue 34405: The Manage Variants filter was not working fine.

If the filter was used, after that a record was selected and after that the 
filter was cleaned up, the "no items to show" message was shown instead of 
showing all the records.
The problem was that the "ManageVariantsDS" manual datasource was not capable 
of managing the criteria: "criteria:{"fieldName":"id","operator":"notNull"}" 
which is the criteria that must return every record.
The problem was in this code line: "value = criteria.getString("value")"  
because the creiteria has not value, it only has fieldName and operator. It was 
throwing an exception which was not being correctly handled in the catch. This 
problem has been solved also, by properly handling the exception by showing log.
The first problem has been solved by processing the concrete criteria properly. 
If this criteria is found, it means that every record must be shown, so it 
continues with doing nothing.
There was a another problem that has been solved and it is that the searchKey 
and the nameFilters were acting as a "Contains" filter instead of like as an 
"iContains".
This has been fixed by changing the "contains" method of StringUtils by the 
"containsIgnoreCase".

diffstat:

 src/org/openbravo/materialmgmt/ManageVariantsDS.java |  24 +++++++++++++++----
 1 files changed, 19 insertions(+), 5 deletions(-)

diffs (67 lines):

diff -r 0d2395a0d55f -r 9bfd8bde32b2 
src/org/openbravo/materialmgmt/ManageVariantsDS.java
--- a/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Tue Nov 15 
10:41:40 2016 +0100
+++ b/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Fri Nov 11 
10:10:29 2016 +0100
@@ -48,8 +48,12 @@
 import org.openbravo.model.common.plm.ProductCharacteristicValue;
 import org.openbravo.service.datasource.ReadOnlyDataSourceService;
 import org.openbravo.service.json.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ManageVariantsDS extends ReadOnlyDataSourceService {
+
+  private static final Logger log = 
LoggerFactory.getLogger(ManageVariantsDS.class);
   private static final int searchKeyLength = getSearchKeyColumnLength();
   private static final String MANAGE_VARIANTS_TABLE_ID = 
"147D4D709FAC4AF0B611ABFED328FA12";
 
@@ -234,11 +238,12 @@
         }
         if (StringUtils.isNotEmpty(searchKeyFilter)) {
           includeInResult = includeInResult
-              && StringUtils.contains((String) variantMap.get("searchKey"), 
searchKeyFilter);
+              && StringUtils.containsIgnoreCase((String) 
variantMap.get("searchKey"),
+                  searchKeyFilter);
         }
         if (StringUtils.isNotEmpty(nameFilter)) {
           includeInResult = includeInResult
-              && StringUtils.contains((String) variantMap.get("name"), 
nameFilter);
+              && StringUtils.containsIgnoreCase((String) 
variantMap.get("name"), nameFilter);
         }
         if (variantCreated != null) {
           includeInResult = includeInResult && variantCreated == 
(existingProduct != null);
@@ -275,7 +280,7 @@
       Collections.sort(result, new ResultComparator(strSortBy, ascending));
 
     } catch (JSONException e) {
-      // Do nothing
+      log.error("Error while managing the variant characteristics", e);
     } finally {
       OBContext.restorePreviousMode();
     }
@@ -291,6 +296,7 @@
     variantCreated = null;
 
     for (int i = 0; i < criteriaArray.length(); i++) {
+      String value = "";
       JSONObject criteria = criteriaArray.getJSONObject(i);
       // Basic advanced criteria handling
       if (criteria.has("_constructor")
@@ -300,8 +306,16 @@
         criteria = innerCriteriaArray.getJSONObject(0);
       }
       String fieldName = criteria.getString("fieldName");
-      // String operatorName = criteria.getString("operator");
-      String value = criteria.getString("value");
+      String operatorName = criteria.getString("operator");
+      if (criteria.has("value")) {
+        value = criteria.getString("value");
+      }
+      if (fieldName.equals("id") && operatorName.equals("notNull")) {
+        // In the case of having the criteria 
"fieldName":"id","operator":"notNull" don't do
+        // nothing.
+        // this case is the one which should return every record.
+        continue;
+      }
       if (fieldName.equals("name")) {
         nameFilter = value;
       } else if (fieldName.equals("searchKey")) {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to