← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 41: OrganisationUnit assignment for DataSets made to respect user level.

 

------------------------------------------------------------
revno: 41
committer: abyot <abyota@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-03-11 16:51:56 +0530
message:
  OrganisationUnit assignment for DataSets made to respect user level.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/SetupAssociationsTreeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UnselectLevelAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2009-03-11 11:21:56 +0000
@@ -64,8 +64,8 @@
     public void setDataSetService( DataSetService dataSetService )
     {
         this.dataSetService = dataSetService;
-    }
-
+    }    
+ 
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
@@ -82,12 +82,25 @@
     public String execute()
         throws Exception
     {
-        DataSet dataSet = dataSetService.getDataSet( dataSetId );
-
-        Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager.getSelectedOrganisationUnits();
-
-        dataSet.setSources( convert( selectedOrganisationUnits ) );
-        
+    	
+        Collection<OrganisationUnit> rootUnits = selectionTreeManager.getRootOrganisationUnits(); 
+        
+        Set<OrganisationUnit> unitsInTheTree = new HashSet<OrganisationUnit>();        
+        
+        getUnitsInTheTree( rootUnits, unitsInTheTree );          
+	
+    	DataSet dataSet = dataSetService.getDataSet( dataSetId );    	
+    	
+    	Set<Source> assignedSources = dataSet.getSources();
+    	
+    	assignedSources.removeAll( convert( unitsInTheTree ) );        
+
+    	Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager.getSelectedOrganisationUnits();
+    	
+    	assignedSources.addAll( convert( selectedOrganisationUnits ) );  	
+    	
+    	dataSet.setSources( assignedSources );
+    	
         dataSetService.updateDataSet( dataSet );
         
         return SUCCESS;
@@ -104,5 +117,14 @@
         sources.addAll( organisationUnits );
         
         return sources;
+    }   
+    
+    private void getUnitsInTheTree( Collection<OrganisationUnit> rootUnits, Set<OrganisationUnit> unitsInTheTree )
+    {
+    	for( OrganisationUnit root : rootUnits )
+        {
+    		unitsInTheTree.add( root );
+    		getUnitsInTheTree( root.getChildren(), unitsInTheTree );    		
+        }
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/SetupAssociationsTreeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/SetupAssociationsTreeAction.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/SetupAssociationsTreeAction.java	2009-03-11 11:21:56 +0000
@@ -110,9 +110,9 @@
         Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
         
         for ( Source source : sources )
-        {
+        {        	
             organisationUnits.add( (OrganisationUnit) source );
-        }
+        }       
         
         return organisationUnits;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UnselectLevelAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UnselectLevelAction.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UnselectLevelAction.java	2009-03-11 11:21:56 +0000
@@ -84,11 +84,11 @@
         throws Exception
     {
         Collection<OrganisationUnit> rootUnits = selectionTreeManager.getRootOrganisationUnits();
-
+        
         Collection<OrganisationUnit> selectedUnits = selectionTreeManager.getSelectedOrganisationUnits();
 
         for ( OrganisationUnit rootUnit : rootUnits )
-        {
+        {        	
             unselectLevel( rootUnit, FIRST_LEVEL, selectedUnits );
         }
 
@@ -106,13 +106,13 @@
     private void unselectLevel( OrganisationUnit orgUnit, int currentLevel, Collection<OrganisationUnit> selectedUnits )
     {
         if ( currentLevel == level )
-        {
+        {        	
             selectedUnits.remove( orgUnit );
         }
         else
         {
             for ( OrganisationUnit child : orgUnit.getChildren() )
-            {
+            {            	
                 unselectLevel( child, currentLevel + 1, selectedUnits );
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml	2009-03-08 05:33:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml	2009-03-11 11:21:56 +0000
@@ -101,7 +101,7 @@
     </property>
     <property name="dataSetService">
       <ref bean="org.hisp.dhis.dataset.DataSetService"/>
-    </property>
+    </property>   
   </bean>
   
   <bean id="org.hisp.dhis.dataset.action.SelectLevelAction"



--

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.