← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11727: added additional options to assignedPrograms, includeDescendants, and parent info

 

------------------------------------------------------------
revno: 11727
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-21 12:15:05 +0200
message:
  added additional options to assignedPrograms, includeDescendants, and parent info
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.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/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java	2013-08-20 13:23:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java	2013-08-21 10:15:05 +0000
@@ -78,7 +78,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping(value = CurrentUserController.RESOURCE_PATH, method = RequestMethod.GET)
+@RequestMapping( value = CurrentUserController.RESOURCE_PATH, method = RequestMethod.GET )
 public class CurrentUserController
 {
     public static final String RESOURCE_PATH = "/currentUser";
@@ -117,7 +117,7 @@
     @Autowired
     private I18nService i18nService;
 
-    @RequestMapping(produces = { "application/json", "text/*" })
+    @RequestMapping( produces = { "application/json", "text/*" } )
     public void getCurrentUser( HttpServletResponse response ) throws Exception
     {
         User currentUser = currentUserService.getCurrentUser();
@@ -130,7 +130,7 @@
         JacksonUtils.toJson( response.getOutputStream(), currentUser );
     }
 
-    @RequestMapping(value = "/inbox", produces = { "application/json", "text/*" })
+    @RequestMapping( value = "/inbox", produces = { "application/json", "text/*" } )
     public void getInbox( HttpServletResponse response ) throws Exception
     {
         User currentUser = currentUserService.getCurrentUser();
@@ -147,7 +147,7 @@
         JacksonUtils.toJson( response.getOutputStream(), inbox );
     }
 
-    @RequestMapping(value = "/dashboard", produces = { "application/json", "text/*" })
+    @RequestMapping( value = "/dashboard", produces = { "application/json", "text/*" } )
     public void getDashboard( HttpServletResponse response ) throws Exception
     {
         User currentUser = currentUserService.getCurrentUser();
@@ -274,7 +274,7 @@
 
     @SuppressWarnings( "unchecked" )
     @RequestMapping( value = { "/assignedPrograms" }, produces = { "application/json", "text/*" } )
-    public void getPrograms( HttpServletResponse response ) throws IOException, NotAuthenticatedException
+    public void getPrograms( HttpServletResponse response, @RequestParam Map<String, String> parameters ) throws IOException, NotAuthenticatedException
     {
         User currentUser = currentUserService.getCurrentUser();
 
@@ -297,6 +297,21 @@
             userOrganisationUnits.addAll( currentUser.getOrganisationUnits() );
         }
 
+        if ( parameters.containsKey( "includeDescendants" ) && Boolean.parseBoolean( parameters.get( "includeDescendants" ) ) )
+        {
+            for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+            {
+                userOrganisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( organisationUnit.getUid() ) );
+            }
+        }
+        else
+        {
+            for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+            {
+                userOrganisationUnits.addAll( organisationUnit.getChildren() );
+            }
+        }
+
         for ( OrganisationUnit organisationUnit : userOrganisationUnits )
         {
             Collection<Program> ouPrograms = programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION, organisationUnit );
@@ -307,18 +322,6 @@
                 programs.addAll( ouPrograms );
                 programAssociations.put( organisationUnit.getUid(), ouPrograms );
             }
-
-            for ( OrganisationUnit child : organisationUnit.getChildren() )
-            {
-                ouPrograms = programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION, child );
-
-                if ( !ouPrograms.isEmpty() )
-                {
-                    organisationUnits.add( child );
-                    programs.addAll( ouPrograms );
-                    programAssociations.put( organisationUnit.getUid(), ouPrograms );
-                }
-            }
         }
 
         i18nService.internationalise( programs );
@@ -332,6 +335,11 @@
             formOrganisationUnit.setLabel( organisationUnit.getDisplayName() );
             formOrganisationUnit.setLevel( organisationUnit.getOrganisationUnitLevel() );
 
+            if ( organisationUnit.getParent() != null )
+            {
+                formOrganisationUnit.setParent( organisationUnit.getParent().getUid() );
+            }
+
             for ( Program program : programAssociations.get( organisationUnit.getUid() ) )
             {
                 FormProgram formProgram = new FormProgram();
@@ -354,7 +362,7 @@
 
     @SuppressWarnings( "unchecked" )
     @RequestMapping( value = { "/forms", "/assignedDataSets" }, produces = { "application/json", "text/*" } )
-    public void getDataSets( HttpServletResponse response ) throws IOException, NotAuthenticatedException
+    public void getDataSets( HttpServletResponse response, @RequestParam Map<String, String> parameters ) throws IOException, NotAuthenticatedException
     {
         User currentUser = currentUserService.getCurrentUser();
 
@@ -383,6 +391,21 @@
             userDataSets = currentUser.getUserCredentials().getAllDataSets();
         }
 
+        if ( parameters.containsKey( "includeDescendants" ) && Boolean.parseBoolean( parameters.get( "includeDescendants" ) ) )
+        {
+            for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+            {
+                userOrganisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( organisationUnit.getUid() ) );
+            }
+        }
+        else
+        {
+            for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+            {
+                userOrganisationUnits.addAll( organisationUnit.getChildren() );
+            }
+        }
+
         for ( OrganisationUnit ou : userOrganisationUnits )
         {
             Set<DataSet> dataSets = new HashSet<DataSet>( CollectionUtils.intersection( ou.getDataSets(), userDataSets ) );
@@ -391,16 +414,6 @@
             {
                 organisationUnits.add( ou );
             }
-
-            for ( OrganisationUnit child : ou.getChildren() )
-            {
-                Set<DataSet> childDataSets = new HashSet<DataSet>( CollectionUtils.intersection( child.getDataSets(), userDataSets ) );
-
-                if ( childDataSets.size() > 0 )
-                {
-                    organisationUnits.add( child );
-                }
-            }
         }
 
         i18nService.internationalise( organisationUnits );
@@ -412,6 +425,11 @@
             formOrganisationUnit.setLabel( organisationUnit.getDisplayName() );
             formOrganisationUnit.setLevel( organisationUnit.getOrganisationUnitLevel() );
 
+            if ( organisationUnit.getParent() != null )
+            {
+                formOrganisationUnit.setParent( organisationUnit.getParent().getUid() );
+            }
+
             Set<DataSet> dataSets = new HashSet<DataSet>( CollectionUtils.intersection( organisationUnit.getDataSets(), userDataSets ) );
             i18nService.internationalise( dataSets );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java	2013-08-20 11:01:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java	2013-08-21 10:15:05 +0000
@@ -46,6 +46,8 @@
 
     private Integer level;
 
+    private String parent;
+
     private Set<FormDataSet> dataSets = new HashSet<FormDataSet>();
 
     private Set<FormProgram> programs = new HashSet<FormProgram>();
@@ -88,6 +90,17 @@
     }
 
     @JsonProperty
+    public String getParent()
+    {
+        return parent;
+    }
+
+    public void setParent( String parent )
+    {
+        this.parent = parent;
+    }
+
+    @JsonProperty
     public Set<FormDataSet> getDataSets()
     {
         return dataSets;