← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3793: Managed OrganisationUnit-User association. Caching issues should now be gone.

 

------------------------------------------------------------
revno: 3793
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-05-30 20:34:15 +0200
message:
  Managed OrganisationUnit-User association. Caching issues should now be gone.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.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-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2011-05-30 18:34:15 +0000
@@ -224,6 +224,34 @@
     // Logic
     // -------------------------------------------------------------------------
     
+    public void addDataElementGroup( DataElementGroup group )
+    {
+        groups.add( group );
+        group.getMembers().add( this );
+    }
+    
+    public void removeDataElementGroup( DataElementGroup group )
+    {
+        groups.remove( group );
+        group.getMembers().remove( this );
+    }
+    
+    public void updateDataElementGroups( Set<DataElementGroup> updates )
+    {
+        for ( DataElementGroup group : new HashSet<DataElementGroup>( groups ) )
+        {
+            if ( !updates.contains( group ) )
+            {
+                removeDataElementGroup( group );
+            }
+        }
+        
+        for ( DataElementGroup group : updates )
+        {
+            addDataElementGroup( group );
+        }
+    }
+    
     /**
      * Returns the value type. If value type is int and the number type exists,
      * the number type is returned, if the type is int and the number type does

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2011-05-30 18:34:15 +0000
@@ -77,6 +77,34 @@
     // Logic
     // -------------------------------------------------------------------------
 
+    public void addIndicatorGroup( IndicatorGroup group )
+    {
+        groups.add( group );
+        group.getMembers().add( this );
+    }
+    
+    public void removeIndicatorGroup( IndicatorGroup group )
+    {
+        groups.remove( group );
+        group.getMembers().remove( this );
+    }
+    
+    public void updateIndicatorGroups( Set<IndicatorGroup> updates )
+    {
+        for ( IndicatorGroup group : new HashSet<IndicatorGroup>( groups ) )
+        {
+            if ( !updates.contains( group ) )
+            {
+                removeIndicatorGroup( group );
+            }
+        }
+        
+        for ( IndicatorGroup group : updates )
+        {
+            addIndicatorGroup( group );
+        }
+    }
+    
     public boolean isAnnualized()
     {
         return annualized != null && annualized;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2011-05-30 18:34:15 +0000
@@ -120,6 +120,34 @@
     // Logic
     // -------------------------------------------------------------------------
 
+    public void addOrganisationUnit( OrganisationUnit unit )
+    {
+        organisationUnits.add( unit );
+        unit.getUsers().add( this );
+    }
+    
+    public void removeOrganisationUnit( OrganisationUnit unit )
+    {
+        organisationUnits.remove( unit );
+        unit.getUsers().remove( this );
+    }
+    
+    public void updateOrganisationUnits( Set<OrganisationUnit> updates )
+    {
+        for ( OrganisationUnit unit : new HashSet<OrganisationUnit>( organisationUnits ) )
+        {
+            if ( !updates.contains( unit ) )
+            {
+                removeOrganisationUnit( unit );
+            }
+        }
+        
+        for ( OrganisationUnit unit : updates )
+        {
+            addOrganisationUnit( unit );
+        }
+    }
+    
     /**
      * Returns the concatenated first name and surname.
      */

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java	2010-12-13 06:40:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java	2011-05-30 18:34:15 +0000
@@ -38,13 +38,10 @@
 
 /**
  * @author Tran Thanh Tri
- * @version $Id: AssignGroupsForDataElementAction.java 2869 2010-03-27 14:26:09Z Chau Thu Tran $
  */
-
 public class AssignGroupsForDataElementAction
     implements Action
 {
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -78,32 +75,19 @@
     public String execute()
         throws Exception
     {
-        DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
         Set<DataElementGroup> selectedGroups = new HashSet<DataElementGroup>();
 
         for ( Integer id : dataElementGroups )
         {
-            DataElementGroup dataElementGroup = dataElementService.getDataElementGroup( id );
-
-            selectedGroups.add( dataElementGroup );
-
-            dataElementGroup.getMembers().add( dataElement );
-
-            dataElementService.updateDataElementGroup( dataElementGroup );
-
-        }
-        
-        Set<DataElementGroup>removeGroups = new HashSet<DataElementGroup>( dataElementService
-            .getGroupsContainingDataElement( dataElement ) );
-        removeGroups.removeAll( selectedGroups );
-        
-        for ( DataElementGroup removeGroup : removeGroups )
-        {
-            removeGroup.getMembers().remove( dataElement );
-            dataElementService.updateDataElementGroup( removeGroup );
-        }
-
+            selectedGroups.add( dataElementService.getDataElementGroup( id ) );
+        }
+
+        DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+        dataElement.updateDataElementGroups( selectedGroups );
+        
+        dataElementService.updateDataElement( dataElement );
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java	2010-12-13 06:40:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java	2011-05-30 18:34:15 +0000
@@ -38,13 +38,10 @@
 
 /**
  * @author Tran Thanh Tri
- * @version $Id: AssignGroupsForIndicatorAction.java 2869 2010-03-27 15:01:079Z
- *          Chau Thu Tran $
  */
 public class AssignGroupsForIndicatorAction
     implements Action
 {
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -78,34 +75,19 @@
     public String execute()
         throws Exception
     {
-
-        Indicator indicator = indicatorService.getIndicator( indicatorId );
-
         Set<IndicatorGroup> selectedGroups = new HashSet<IndicatorGroup>();
 
         for ( Integer id : indicatorGroups )
         {
-            IndicatorGroup group = indicatorService.getIndicatorGroup( id );
-
-            selectedGroups.add( group );
-            
-            group.getMembers().add( indicator );
-
-            indicatorService.updateIndicatorGroup( group );
-
-        }
-
-        Set<IndicatorGroup> removeGroups = new HashSet<IndicatorGroup>( indicatorService
-            .getGroupsContainingIndicator( indicator ) );
-        removeGroups.removeAll( selectedGroups );
-
-        for ( IndicatorGroup removeGroup : removeGroups )
-        {
-            removeGroup.getMembers().remove( indicator );
-            indicatorService.updateIndicatorGroup( removeGroup );
-        }
-
+            selectedGroups.add( indicatorService.getIndicatorGroup( id ) );
+        }
+
+        Indicator indicator = indicatorService.getIndicator( indicatorId );
+
+        indicator.updateIndicatorGroups( selectedGroups );
+        
+        indicatorService.updateIndicator( indicator );
+        
         return SUCCESS;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java	2011-04-01 03:10:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java	2011-05-30 18:34:15 +0000
@@ -175,7 +175,7 @@
         user.setFirstName( firstName );
         user.setEmail( email );
         user.setPhoneNumber( phoneNumber );
-        user.setOrganisationUnits( new HashSet<OrganisationUnit>( orgUnits ) );
+        user.updateOrganisationUnits( new HashSet<OrganisationUnit>( orgUnits ) );
 
         UserCredentials userCredentials = new UserCredentials();
         userCredentials.setUser( user );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2011-04-01 03:10:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2011-05-30 18:34:15 +0000
@@ -167,7 +167,7 @@
         user.setFirstName( firstName );
         user.setEmail( email );
         user.setPhoneNumber( phoneNumber );
-        user.setOrganisationUnits( new HashSet<OrganisationUnit>( units ) );
+        user.updateOrganisationUnits( new HashSet<OrganisationUnit>( units ) );
 
         UserCredentials userCredentials = userService.getUserCredentials( user );