← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4933: fixed bug, add/update orgunits on a user with multiple orgunits roots was not working correctly

 

------------------------------------------------------------
revno: 4933
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-10-13 17:15:00 +0200
message:
  fixed bug, add/update orgunits on a user with multiple orgunits roots was not working correctly
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/RemoveSelectedOrganisationUnitAction.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/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2011-09-21 12:46:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2011-10-13 15:15:00 +0000
@@ -62,11 +62,11 @@
     private String firstName;
 
     private String email;
-    
+
     private String phoneNumber;
 
     private UserCredentials userCredentials;
-    
+
     /**
      * All OrgUnits where the user could belong
      * 
@@ -78,7 +78,7 @@
      * Set of the dynamic attributes values that belong to this dataElement.
      */
     private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
-    
+
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------
@@ -90,7 +90,7 @@
         int result = 1;
 
         result = result * prime + surname.hashCode();
-        result = result * prime + firstName.hashCode();    
+        result = result * prime + firstName.hashCode();
 
         return result;
     }
@@ -115,10 +115,9 @@
 
         final User other = (User) o;
 
-        return surname.equals( other.getSurname() )
-            && firstName.equals( other.getFirstName() );
+        return surname.equals( other.getSurname() ) && firstName.equals( other.getFirstName() );
     }
-    
+
     @Override
     public String toString()
     {
@@ -134,13 +133,13 @@
         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 ) )
@@ -150,13 +149,13 @@
                 removeOrganisationUnit( unit );
             }
         }
-        
+
         for ( OrganisationUnit unit : updates )
         {
             addOrganisationUnit( unit );
         }
     }
-    
+
     /**
      * Returns the concatenated first name and surname.
      */
@@ -164,11 +163,12 @@
     {
         return firstName + " " + surname;
     }
-    
+
     /**
-     * Returns the first of the organisation units associated with the user. Null
-     * is returned if the user has no organisation units. Which organisation unit
-     * to return is undefined if the user has multiple organisation units.
+     * Returns the first of the organisation units associated with the user.
+     * Null is returned if the user has no organisation units. Which
+     * organisation unit to return is undefined if the user has multiple
+     * organisation units.
      * 
      * @return an organisation unit associated with the user.
      */
@@ -176,22 +176,22 @@
     {
         return CollectionUtils.isEmpty( organisationUnits ) ? null : organisationUnits.iterator().next();
     }
-    
+
     public boolean hasOrganisationUnit()
     {
         return !CollectionUtils.isEmpty( organisationUnits );
     }
-    
+
     public String getOrganisationUnitsName()
     {
         return IdentifiableObjectUtils.join( organisationUnits );
     }
-    
+
     public String getUsername()
     {
         return userCredentials != null ? userCredentials.getUsername() : null;
     }
-    
+
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -215,7 +215,7 @@
     {
         this.firstName = firstName;
     }
-    
+
     public String getSurname()
     {
         return surname;

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/RemoveSelectedOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/RemoveSelectedOrganisationUnitAction.java	2011-04-24 08:46:21 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/RemoveSelectedOrganisationUnitAction.java	2011-10-13 15:15:00 +0000
@@ -122,7 +122,12 @@
         if ( id != null )
         {
             OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
-            selectedUnits.remove( unit );
+
+            // TODO fix this, not pretty, but selectionTreeManager is not
+            // correctly handling adding/removing selected orgunits
+            while ( selectedUnits.remove( unit ) )
+            {
+            }
         }
 
         if ( level != null )
@@ -132,8 +137,8 @@
 
         if ( organisationUnitGroupId != null )
         {
-            selectedUnits.removeAll( organisationUnitGroupService
-                .getOrganisationUnitGroup( organisationUnitGroupId ).getMembers() );
+            selectedUnits.removeAll( organisationUnitGroupService.getOrganisationUnitGroup( organisationUnitGroupId )
+                .getMembers() );
         }
 
         if ( children != null && children == true )
@@ -147,11 +152,11 @@
 
                 if ( !selectedOrganisationUnits.contains( parent ) )
                 {
-                    selectedUnits.removeAll( organisationUnitService.getOrganisationUnitWithChildren( selected
-                        .getId() ) );
-                    
-                    selectedUnits.add( selected );                      
-                }                    
+                    selectedUnits
+                        .removeAll( organisationUnitService.getOrganisationUnitWithChildren( selected.getId() ) );
+
+                    selectedUnits.add( selected );
+                }
             }
         }
 

=== 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-09-22 10:32:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2011-10-13 15:15:00 +0000
@@ -217,7 +217,7 @@
             userCredentials.setPassword( passwordManager.encodePassword( userCredentials.getUsername(), rawPassword ) );
         }
 
-        if ( jsonAttributeValues != null)
+        if ( jsonAttributeValues != null )
         {
             AttributeUtils.updateAttributeValuesFromJson( user.getAttributeValues(), jsonAttributeValues,
                 attributeService );
@@ -226,6 +226,12 @@
         userService.updateUserCredentials( userCredentials );
         userService.updateUser( user );
 
+        selectionManager.setRootOrganisationUnits( units );
+        selectionManager.setSelectedOrganisationUnits( units );
+
+        selectionTreeManager.setRootOrganisationUnits( units );
+        selectionTreeManager.setSelectedOrganisationUnits( units );
+
         if ( units.size() > 0 )
         {
             selectionManager.setSelectedOrganisationUnits( units );