← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4334: Modified ouwt response to return orgunits in a flat list

 

------------------------------------------------------------
revno: 4334
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-08-17 16:51:49 +0200
message:
  Modified ouwt response to return orgunits in a flat list
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-08-17 12:51:38 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-08-17 14:51:49 +0000
@@ -1,19 +1,9 @@
-
-#macro( expandOrganisationUnit $organisationUnit )
-{
-"id":$!{organisationUnit.id},
-#if( $organisationUnit.parent )"pid":$!{organisationUnit.parent.id},#end
-"n":"$!encoder.jsonEncode( ${organisationUnit.name} )"#if( $organisationUnit.children.size() > 0 ),
-"c":[
-#foreach ( $child in $organisationUnit.sortedChildren )
-#expandOrganisationUnit( $child )#if( $velocityCount < $organisationUnit.children.size() ),#end
-#end]#end }
-#end
-
-{ "version":"$!encoder.jsonEncode( $version )"
-#if( ! $versionOnly )
-,"organisationUnits":[
-#foreach ( $organisationUnit in $organisationUnits )
-#expandOrganisationUnit( $organisationUnit )#if( $velocityCount < $organisationUnits.size() ),#end
-#end ]
-#end }
\ No newline at end of file
+{
+"version":"$!encoder.jsonEncode( $version )"
+#if( ! $versionOnly )
+,"organisationUnits": {
+#foreach( $unit in $organisationUnits )
+"${unit.id}":{"id":${unit.id},"n":"${unit.name}",#if( $unit.parent )"pid":${unit.parent.id},#end"c":[#foreach( $child in $unit.sortedChildren )${child.id}#if( $velocityCount < $organisationUnit.children.size() ),#end#end]}
+#if( $velocityCount < $organisationUnits.size() ),#end#end
+#end
+} }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-17 12:51:38 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-17 14:51:49 +0000
@@ -28,8 +28,8 @@
  */
 
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.UUID;
 
@@ -74,21 +74,10 @@
     }
 
     // -------------------------------------------------------------------------
-    // Comparator
-    // -------------------------------------------------------------------------
-
-    private Comparator<OrganisationUnit> organisationUnitComparator;
-
-    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
-    {
-        this.organisationUnitComparator = organisationUnitComparator;
-    }
-
-    // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
 
-    private List<OrganisationUnit> organisationUnits;
+    private List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
 
     public List<OrganisationUnit> getOrganisationUnits()
     {
@@ -120,29 +109,34 @@
 
     public String execute()
         throws Exception
-    {
+    {   
         if ( !versionOnly )
         {
+            Collection<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>();
+            
             User user = currentUserService.getCurrentUser();
 
             if ( user.getOrganisationUnits() != null && user.getOrganisationUnits().size() > 0 )
             {
-                organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
+                userOrganisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
             }
             else
             {
                 if ( user.getOrganisationUnits() != null && currentUserService.currentUserIsSuper() )
                 {
-                    organisationUnits = new ArrayList<OrganisationUnit>(
+                    userOrganisationUnits = new ArrayList<OrganisationUnit>(
                         organisationUnitService.getRootOrganisationUnits() );
                 }
                 else
                 {
-                    organisationUnits = new ArrayList<OrganisationUnit>();
+                    userOrganisationUnits = new ArrayList<OrganisationUnit>();
                 }
             }
 
-            Collections.sort( organisationUnits, organisationUnitComparator );
+            for ( OrganisationUnit unit : userOrganisationUnits )
+            {
+                organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) );
+            }            
         }
 
         version = getVersionString();