Author: nmalin
Date: Fri Apr  8 15:16:22 2016
New Revision: 1738258

URL: http://svn.apache.org/viewvc?rev=1738258&view=rev
Log:
correct error when sort a localized field with the order way is present like 
'-field', '+field', 'field ASC', 'field DESC'
This error raise by james yong on the issue OFBIZ-6987. Thanks to him for the 
issue and Deepak Dixit to spot the source

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java?rev=1738258&r1=1738257&r2=1738258&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java 
(original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java Fri 
Apr  8 15:16:22 2016
@@ -342,17 +342,25 @@ public class EntityUtil {
      *@param values List of GenericValues
      *@param orderBy The fields of the named entity to order the query by;
      *      optionally add a " ASC" for ascending or " DESC" for descending
-     *@param locale Locale use to retreive localized value
+     *@param locale Locale use to retrieve localized value
      *@return List of GenericValue's in the proper order
      */
     public static <T extends GenericEntity> List<T> 
localizedOrderBy(Collection<T> values, List<String> orderBy, Locale locale) {
         if (values == null) return null;
-        if (values.isEmpty()) return new ArrayList<>();
+        if (values.isEmpty()) return new ArrayList<T>();
         //force check entity label before order by
         List<T> localizedValues = new ArrayList<T>();
         for (T value : values) {
             T newValue = (T) value.clone();
             for (String orderByField : orderBy) {
+                if (orderByField.endsWith(" DESC")) {
+                    orderByField= orderByField.substring(0, 
orderByField.length() - 5);
+                } else if (orderByField.endsWith(" ASC")) {
+                    orderByField= orderByField.substring(0, 
orderByField.length() - 4);
+                } else if (orderByField.startsWith("-")
+                        || orderByField.startsWith("+")) {
+                    orderByField= orderByField.substring(1, 
orderByField.length());
+                }
                 newValue.put(orderByField, value.get(orderByField, locale));
             }
             localizedValues.add(newValue);


Reply via email to