← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7194: [mobile] minor fix

 

------------------------------------------------------------
revno: 7194
committer: Long <thanhlongngo1988@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-06-05 16:30:22 +0700
message:
  [mobile] minor fix
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetFindBeneficiaryFormAction.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-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetFindBeneficiaryFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetFindBeneficiaryFormAction.java	2012-05-15 07:40:06 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/namebaseddataentry/action/GetFindBeneficiaryFormAction.java	2012-06-05 09:30:22 +0000
@@ -27,7 +27,11 @@
 
 package org.hisp.dhis.light.namebaseddataentry.action;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.CurrentUserService;
 import com.opensymphony.xwork2.Action;
@@ -38,9 +42,9 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-    
+
     private CurrentUserService currentUserService;
-    
+
     public CurrentUserService getCurrentUserService()
     {
         return currentUserService;
@@ -55,14 +59,14 @@
     // Input & Output
     // -------------------------------------------------------------------------
 
-    private Collection<OrganisationUnit> organisationUnits;
-    
-    public Collection<OrganisationUnit> getOrganisationUnits()
+    private Set<OrganisationUnit> organisationUnits;
+
+    public Set<OrganisationUnit> getOrganisationUnits()
     {
         return organisationUnits;
     }
 
-    public void setOrganisationUnits( Collection<OrganisationUnit> organisationUnits )
+    public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
     {
         this.organisationUnits = organisationUnits;
     }
@@ -71,8 +75,29 @@
     public String execute()
         throws Exception
     {
-        organisationUnits = currentUserService.getCurrentUser().getOrganisationUnits();        
+        Collection<OrganisationUnit> basicOrganisationUnits = currentUserService.getCurrentUser()
+            .getOrganisationUnits();
+        organisationUnits = new HashSet<OrganisationUnit>();
+
+        for ( OrganisationUnit organisationUnit : basicOrganisationUnits )
+        {
+            organisationUnits.addAll( this.getAllParentOrganisationUnits( organisationUnit ) );
+        }
+
         return SUCCESS;
     }
 
+    private Collection<? extends OrganisationUnit> getAllParentOrganisationUnits( OrganisationUnit organisationUnit )
+    {
+        List<OrganisationUnit> parents = new ArrayList<OrganisationUnit>();
+        parents.add( organisationUnit );
+        
+        while ( organisationUnit.getParent() != null )
+        {
+            parents.add( organisationUnit.getParent() );
+            organisationUnit = organisationUnit.getParent();
+        }
+        return parents;
+    }
+
 }