← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21582: fully support asc/iasc/desc/idesc order operators in web-api

 

------------------------------------------------------------
revno: 21582
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 15:30:32 +0700
message:
  fully support asc/iasc/desc/idesc order operators in web-api
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/OrderParams.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java	2016-01-05 07:53:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java	2016-01-05 08:30:32 +0000
@@ -128,14 +128,24 @@
         return 0;
     }
 
+    public static Order asc( Property property )
+    {
+        return new Order( property, true );
+    }
+
     public static Order iasc( Property property )
     {
-        return new Order( property, true );
+        return new Order( property, true ).ignoreCase();
+    }
+
+    public static Order desc( Property property )
+    {
+        return new Order( property, false );
     }
 
     public static Order idesc( Property property )
     {
-        return new Order( property, false );
+        return new Order( property, false ).ignoreCase();
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/OrderParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/OrderParams.java	2016-01-05 08:11:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/OrderParams.java	2016-01-05 08:30:32 +0000
@@ -70,24 +70,38 @@
                 continue;
             }
 
-            if ( orders.containsKey( split[0] ) || !schema.haveProperty( split[0] )
-                || !validProperty( schema.getProperty( split[0] ) ) || !validDirection( split[1] ) )
+            String propertyName = split[0];
+            Property property = schema.getProperty( propertyName );
+            String direction = split[1].toLowerCase();
+
+            if ( orders.containsKey( propertyName ) || !schema.haveProperty( propertyName )
+                || !validProperty( property ) || !validDirection( direction ) )
             {
                 continue;
             }
 
             Order order;
 
-            if ( "asc".equals( split[1] ) || "iasc".equals( split[1] ) )
-            {
-                order = Order.iasc( schema.getProperty( split[0] ) );
-            }
-            else
-            {
-                order = Order.idesc( schema.getProperty( split[0] ) );
+            switch ( direction )
+            {
+                case "asc":
+                    order = Order.asc( property );
+                    break;
+                case "iasc":
+                    order = Order.iasc( property );
+                    break;
+                case "desc":
+                    order = Order.desc( property );
+                    break;
+                case "idesc":
+                    order = Order.idesc( property );
+                    break;
+                default:
+                    order = Order.asc( property );
+                    break;
             }
 
-            orders.put( split[0], order.ignoreCase() );
+            orders.put( propertyName, order );
         }
 
         return new ArrayList<>( orders.values() );