← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15071: OrganisationUnitService, made call to update version independent, works better for batch operatio...

 

------------------------------------------------------------
revno: 15071
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-28 20:13:09 +0200
message:
  OrganisationUnitService, made call to update version independent, works better for batch operations and unit tests
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/RemoveOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.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/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2014-04-27 22:31:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2014-04-28 18:13:09 +0000
@@ -61,15 +61,6 @@
     int addOrganisationUnit( OrganisationUnit organisationUnit );
 
     /**
-     * Adds an OrganisationUnit to the hierarchy.
-     *
-     * @param organisationUnit the OrganisationUnit to add.
-     * @param indicates whether to update hierarchy version.
-     * @return a generated unique id of the added OrganisationUnit.
-     */
-    int addOrganisationUnit( OrganisationUnit organisationUnit, boolean updateVersion );
-
-    /**
      * Updates an OrganisationUnit.
      *
      * @param organisationUnit the OrganisationUnit to update.
@@ -77,6 +68,11 @@
     void updateOrganisationUnit( OrganisationUnit organisationUnit );
 
     /**
+     * Updates the version of the organisation unit hierarchy.
+     */
+    void updateOrganisationUnitVersion();
+    
+    /**
      * Updates an OrganisationUnit.
      *
      * @param organisationUnit the organisationUnit to update.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2014-04-27 22:31:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2014-04-28 18:13:09 +0000
@@ -114,12 +114,6 @@
     @Override
     public int addOrganisationUnit( OrganisationUnit organisationUnit )
     {
-        return addOrganisationUnit( organisationUnit, true );
-    }
-    
-    @Override
-    public int addOrganisationUnit( OrganisationUnit organisationUnit, boolean updateVersion )
-    {
         int id = organisationUnitStore.save( organisationUnit );
 
         if ( organisationUnit.getParent() == null && currentUserService.getCurrentUser() != null )
@@ -128,19 +122,17 @@
 
             currentUserService.getCurrentUser().getOrganisationUnits().add( organisationUnit );
         }
-
-        if ( updateVersion )
-        {
-            versionService.updateVersion( VersionService.ORGANISATIONUNIT_VERSION );
-        }
         
         return id;
     }
 
     public void updateOrganisationUnit( OrganisationUnit organisationUnit )
     {
-        organisationUnitStore.update( organisationUnit );
-
+        organisationUnitStore.update( organisationUnit );        
+    }
+    
+    public void updateOrganisationUnitVersion()
+    {
         versionService.updateVersion( VersionService.ORGANISATIONUNIT_VERSION );
     }
 
@@ -169,8 +161,6 @@
         }
 
         organisationUnitStore.delete( organisationUnit );
-
-        versionService.updateVersion( VersionService.ORGANISATIONUNIT_VERSION );
     }
 
     public OrganisationUnit getOrganisationUnit( int id )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java	2014-04-28 13:47:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java	2014-04-28 18:13:09 +0000
@@ -31,9 +31,9 @@
 import static org.hisp.dhis.dataapproval.DataApprovalLevelService.APPROVAL_LEVEL_UNAPPROVED;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
 
 import java.util.HashSet;
 import java.util.List;
@@ -190,10 +190,10 @@
         organisationUnitJ = createOrganisationUnit( 'J', organisationUnitI );
         organisationUnitK = createOrganisationUnit( 'K', organisationUnitJ );
 
-        organisationUnitService.addOrganisationUnit( organisationUnitA, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitB, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitC, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitD, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitA );
+        organisationUnitService.addOrganisationUnit( organisationUnitB );
+        organisationUnitService.addOrganisationUnit( organisationUnitC );
+        organisationUnitService.addOrganisationUnit( organisationUnitD );
     }
     
     // -------------------------------------------------------------------------
@@ -386,10 +386,10 @@
         //
         // Variation A: User does *not* have approval at lower levels authority.
         //
-        organisationUnitService.addOrganisationUnit( organisationUnitE, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitF, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitG, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitH, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitE );
+        organisationUnitService.addOrganisationUnit( organisationUnitF );
+        organisationUnitService.addOrganisationUnit( organisationUnitG );
+        organisationUnitService.addOrganisationUnit( organisationUnitH );
 
         dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
         dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
@@ -422,10 +422,10 @@
         //
         // Variation B: User *has* approval at lower levels authority.
         //
-        organisationUnitService.addOrganisationUnit( organisationUnitE, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitF, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitG, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitH, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitE );
+        organisationUnitService.addOrganisationUnit( organisationUnitF );
+        organisationUnitService.addOrganisationUnit( organisationUnitG );
+        organisationUnitService.addOrganisationUnit( organisationUnitH );
 
         dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
         dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
@@ -458,10 +458,10 @@
         //
         // Variation C: No approval level for org unit level 4.
         //
-        organisationUnitService.addOrganisationUnit( organisationUnitE, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitF, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitG, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitH, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitE );
+        organisationUnitService.addOrganisationUnit( organisationUnitF );
+        organisationUnitService.addOrganisationUnit( organisationUnitG );
+        organisationUnitService.addOrganisationUnit( organisationUnitH );
 
         dataApprovalLevelService.addDataApprovalLevel( level1, 1 ); // 1st approval level
         dataApprovalLevelService.addDataApprovalLevel( level2, 2 ); // 2nd approval level
@@ -493,13 +493,13 @@
         //
         // Variation D: User is assigned to two districts
         //
-        organisationUnitService.addOrganisationUnit( organisationUnitE, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitF, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitG, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitH, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitI, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitJ, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitK, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitE );
+        organisationUnitService.addOrganisationUnit( organisationUnitF );
+        organisationUnitService.addOrganisationUnit( organisationUnitG );
+        organisationUnitService.addOrganisationUnit( organisationUnitH );
+        organisationUnitService.addOrganisationUnit( organisationUnitI );
+        organisationUnitService.addOrganisationUnit( organisationUnitJ );
+        organisationUnitService.addOrganisationUnit( organisationUnitK );
 
         dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
         dataApprovalLevelService.addDataApprovalLevel( level2, 2 );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2014-04-28 13:56:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2014-04-28 18:13:09 +0000
@@ -265,12 +265,12 @@
         organisationUnitE.setLevel( 3 );
         organisationUnitF.setLevel( 4 );
 
-        organisationUnitService.addOrganisationUnit( organisationUnitA, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitB, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitC, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitD, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitE, false );
-        organisationUnitService.addOrganisationUnit( organisationUnitF, false );
+        organisationUnitService.addOrganisationUnit( organisationUnitA );
+        organisationUnitService.addOrganisationUnit( organisationUnitB );
+        organisationUnitService.addOrganisationUnit( organisationUnitC );
+        organisationUnitService.addOrganisationUnit( organisationUnitD );
+        organisationUnitService.addOrganisationUnit( organisationUnitE );
+        organisationUnitService.addOrganisationUnit( organisationUnitF );
 
         level1 = new DataApprovalLevel( "level1", 1, null );
         level2 = new DataApprovalLevel( "level2", 2, null );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java	2014-04-28 15:43:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java	2014-04-28 18:13:09 +0000
@@ -147,10 +147,10 @@
         sourceC = createOrganisationUnit( 'C', sourceB );
         sourceD = createOrganisationUnit( 'D', sourceC );
 
-        organisationUnitService.addOrganisationUnit( sourceA, false );
-        organisationUnitService.addOrganisationUnit( sourceB, false );
-        organisationUnitService.addOrganisationUnit( sourceC, false );
-        organisationUnitService.addOrganisationUnit( sourceD, false );
+        organisationUnitService.addOrganisationUnit( sourceA );
+        organisationUnitService.addOrganisationUnit( sourceB );
+        organisationUnitService.addOrganisationUnit( sourceC );
+        organisationUnitService.addOrganisationUnit( sourceD );
 
         userA = createUser( 'A' );
         userB = createUser( 'B' );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java	2014-04-28 18:13:09 +0000
@@ -340,6 +340,8 @@
         }
 
         organisationUnitService.updateOrganisationUnit( organisationUnit );
+        
+        organisationUnitService.updateOrganisationUnitVersion();
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/RemoveOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/RemoveOrganisationUnitAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/RemoveOrganisationUnitAction.java	2014-04-28 18:13:09 +0000
@@ -94,6 +94,8 @@
         try
         {
             organisationUnitService.deleteOrganisationUnit( unit );
+            
+            organisationUnitService.updateOrganisationUnitVersion();
         }
         catch ( DeleteNotAllowedException ex )
         {
@@ -103,7 +105,7 @@
                 
                 return ERROR;
             }
-        }        
+        }
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java	2014-04-28 18:13:09 +0000
@@ -370,6 +370,8 @@
                 manager.updateNoAcl( newGroup );
             }
         }
+        
+        organisationUnitService.updateOrganisationUnitVersion();
 
         return SUCCESS;
     }