← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3887: Fixed bug: could not move organistion units in hierarchy due to caching

 

------------------------------------------------------------
revno: 3887
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-06-13 14:50:20 +0200
message:
  Fixed bug: could not move organistion units in hierarchy due to caching
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/hierarchy/MoveOrganisationUnitAction.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/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-05-30 14:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-06-13 12:50:20 +0000
@@ -397,6 +397,18 @@
         return hasPatients != null && hasPatients;
     }
     
+    public void updateParent( OrganisationUnit newParent )
+    {
+        if ( this.parent != null && this.parent.getChildren() != null )
+        {
+            this.parent.getChildren().remove( this );            
+        }
+        
+        this.parent = newParent;
+        
+        newParent.getChildren().add( this );
+    }
+    
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/hierarchy/MoveOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/hierarchy/MoveOrganisationUnitAction.java	2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/hierarchy/MoveOrganisationUnitAction.java	2011-06-13 12:50:20 +0000
@@ -87,26 +87,19 @@
         // Get parent
         // ---------------------------------------------------------------------
 
-        OrganisationUnit newParent;
-
-        if ( newParentOrganisationUnitId != null )
-        {
-            newParent = organisationUnitService.getOrganisationUnit( newParentOrganisationUnitId.intValue() );
-        }
-        else
-        {
-            newParent = selectionManager.getRootOrganisationUnitsParent();
-        }
-
-        // ---------------------------------------------------------------------
-        // Update unit to move
-        // ---------------------------------------------------------------------
-
-        OrganisationUnit unitToMove = organisationUnitService.getOrganisationUnit( organisationUnitToMoveId.intValue() );
-
-        unitToMove.setParent( newParent );
-
-        organisationUnitService.updateOrganisationUnit( unitToMove, true );
+        OrganisationUnit newParent = newParentOrganisationUnitId != null ? 
+        organisationUnitService.getOrganisationUnit( newParentOrganisationUnitId ) :
+        selectionManager.getRootOrganisationUnitsParent();
+
+        // ---------------------------------------------------------------------
+        // Update parent
+        // ---------------------------------------------------------------------
+
+        OrganisationUnit unitToMove = organisationUnitService.getOrganisationUnit( organisationUnitToMoveId );
+
+        unitToMove.updateParent( newParent );
+        
+        organisationUnitService.updateOrganisationUnit( unitToMove );
 
         return SUCCESS;
     }