← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12970: bugfix for ouwt search, only return OU-trees that are connected to the user

 

------------------------------------------------------------
revno: 12970
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-11-19 12:41:34 +0100
message:
  bugfix for ouwt search, only return OU-trees that are connected to the user
modified:
  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/ouwt/action/GetOrganisationUnitsByNameAction.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/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	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2013-11-19 11:41:34 +0000
@@ -160,12 +160,15 @@
                 organisationUnits.add( child );
                 OrganisationUnit parent = child.getParent();
 
-                do
+                if ( parent != null )
                 {
-                    organisationUnits.add( parent );
-                    organisationUnits.addAll( parent.getChildren() );
+                    do
+                    {
+                        organisationUnits.add( parent );
+                        organisationUnits.addAll( parent.getChildren() );
+                    }
+                    while ( (parent = parent.getParent()) != null );
                 }
-                while ( (parent = parent.getParent()) != null );
 
                 return "partial";
             }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetOrganisationUnitsByNameAction.java	2013-11-19 11:41:34 +0000
@@ -29,11 +29,16 @@
  */
 
 import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author Chau Thu Tran
@@ -54,6 +59,14 @@
         this.organisationUnitService = organisationUnitService;
     }
 
+    @Autowired
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -69,7 +82,7 @@
     // Output
     // -------------------------------------------------------------------------
 
-    private List<OrganisationUnit> organisationUnits;
+    private List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
 
     public List<OrganisationUnit> getOrganisationUnits()
     {
@@ -84,7 +97,26 @@
     public String execute()
         throws Exception
     {
-        organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByName( term, 0, MAX ) );
+        // organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByName( term, 0, MAX ) );
+
+        term = term.toLowerCase();
+
+        Set<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>( currentUserService.getCurrentUser().getOrganisationUnits() );
+
+        userOrganisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( userOrganisationUnits ) ) );
+
+        for ( OrganisationUnit organisationUnit : userOrganisationUnits )
+        {
+            if ( organisationUnits.size() >= MAX )
+            {
+                return SUCCESS;
+            }
+
+            if ( organisationUnit.getName().toLowerCase().contains( term ) )
+            {
+                organisationUnits.add( organisationUnit );
+            }
+        }
 
         return SUCCESS;
     }