← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13749: add new parameter to programController, orgUnit=uid, to filter for assigned orgUnits

 

------------------------------------------------------------
revno: 13749
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-16 14:48:44 +0700
message:
  add new parameter to programController, orgUnit=uid, to filter for assigned orgUnits
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/ProgramController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/ProgramController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/ProgramController.java	2013-09-27 15:16:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/ProgramController.java	2014-01-16 07:48:44 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.api.controller.WebMetaData;
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -75,11 +76,14 @@
             entityList = new ArrayList<Program>( manager.getAllSorted( getEntityClass() ) );
         }
 
-        if ( options.getOptions().get( "type" ) != null )
+        String type = options.getOptions().get( "type" );
+        String orgUnit = options.getOptions().get( "orgUnit" );
+
+        if ( type != null )
         {
             try
             {
-                int type = Integer.parseInt( options.getOptions().get( "type" ) );
+                int programType = Integer.parseInt( type );
 
                 Iterator<Program> iterator = entityList.iterator();
 
@@ -87,7 +91,7 @@
                 {
                     Program program = iterator.next();
 
-                    if ( program.getType() != type )
+                    if ( program.getType() != programType )
                     {
                         iterator.remove();
                     }
@@ -98,6 +102,26 @@
             }
         }
 
+        if ( orgUnit != null )
+        {
+            OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, orgUnit );
+
+            if ( organisationUnit != null )
+            {
+                Iterator<Program> iterator = entityList.iterator();
+
+                while ( iterator.hasNext() )
+                {
+                    Program program = iterator.next();
+
+                    if ( !program.getOrganisationUnits().contains( organisationUnit ) )
+                    {
+                        iterator.remove();
+                    }
+                }
+            }
+        }
+
         return entityList;
     }
 }