← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15734: support inclusionStrategy as parameter in web-api, supports ALWAYS, NON_NULL, NON_EMPTY

 

------------------------------------------------------------
revno: 15734
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-17 17:45:23 +0200
message:
  support inclusionStrategy as parameter in web-api, supports ALWAYS, NON_NULL, NON_EMPTY
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java	2014-06-17 14:33:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java	2014-06-17 15:45:23 +0000
@@ -50,40 +50,40 @@
          * Inclusion strategy that only includes non null objects.
          */
         NON_NULL
-        {
-            @Override
-            public <T> boolean include( T object )
             {
-                return object != null;
-            }
-        },
+                @Override
+                public <T> boolean include( T object )
+                {
+                    return object != null;
+                }
+            },
 
         /**
          * Inclusion strategy that only includes non empty objects:
          * -
          */
         NON_EMPTY
-        {
-            @Override
-            public <T> boolean include( T object )
             {
-                if ( object == null )
-                {
-                    return false;
-                }
-
-                if ( Collection.class.isAssignableFrom( object.getClass() ) )
-                {
-                    return !((Collection<?>) object).isEmpty();
-                }
-                else if ( String.class.isAssignableFrom( object.getClass() ) )
-                {
-                    return !StringUtils.isEmpty( object );
-                }
-
-                return true;
-            }
-        };
+                @Override
+                public <T> boolean include( T object )
+                {
+                    if ( object == null )
+                    {
+                        return false;
+                    }
+
+                    if ( Collection.class.isAssignableFrom( object.getClass() ) )
+                    {
+                        return !((Collection<?>) object).isEmpty();
+                    }
+                    else if ( String.class.isAssignableFrom( object.getClass() ) )
+                    {
+                        return !StringUtils.isEmpty( object );
+                    }
+
+                    return true;
+                }
+            };
 
         @Override
         public <T> boolean include( T object )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-17 15:28:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-06-17 15:45:23 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.base.Enums;
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import org.hisp.dhis.acl.Access;
@@ -47,6 +48,7 @@
 import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
 import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException;
 import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.node.config.InclusionStrategy;
 import org.hisp.dhis.node.types.CollectionNode;
 import org.hisp.dhis.node.types.ComplexNode;
 import org.hisp.dhis.node.types.RootNode;
@@ -181,6 +183,8 @@
         rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
         rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
 
+        rootNode.getConfig().setInclusionStrategy( getInclusionStrategy( parameters.get( "inclusionStrategy" ) ) );
+
         if ( pager != null )
         {
             ComplexNode pagerNode = rootNode.addChild( new ComplexNode( "pager" ) );
@@ -256,6 +260,8 @@
             rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
             rootNode.addChild( collectionNode );
 
+            rootNode.getConfig().setInclusionStrategy( getInclusionStrategy( parameters.get( "inclusionStrategy" ) ) );
+
             return rootNode;
         }
         else
@@ -264,6 +270,8 @@
             rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );
             rootNode.setNamespace( DxfNamespaces.DXF_2_0 );
 
+            rootNode.getConfig().setInclusionStrategy( getInclusionStrategy( parameters.get( "inclusionStrategy" ) ) );
+
             return rootNode;
         }
     }
@@ -552,4 +560,19 @@
             throw new RuntimeException( ex );
         }
     }
+
+    private InclusionStrategy.Include getInclusionStrategy( String inclusionStrategy )
+    {
+        if ( inclusionStrategy != null )
+        {
+            Optional<InclusionStrategy.Include> optional = Enums.getIfPresent( InclusionStrategy.Include.class, inclusionStrategy );
+
+            if ( optional.isPresent() )
+            {
+                return optional.get();
+            }
+        }
+
+        return InclusionStrategy.Include.NON_NULL;
+    }
 }