← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15052: Data approval service. Added method for adding approval level with explicit level assignment. The...

 

------------------------------------------------------------
revno: 15052
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-28 12:17:37 +0200
message:
  Data approval service. Added method for adding approval level with explicit level assignment. The existing add method does not work well with unit testing since levels are retrieved into session and updated multiple times, as a result of spring running unit tests inside a transaction.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.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/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-04-14 07:24:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-04-28 10:17:37 +0000
@@ -132,6 +132,15 @@
      * @return the identifier of the added level, or -1 if not well formed or duplicate.
      */
     int addDataApprovalLevel( DataApprovalLevel newLevel );
+    
+    /**
+     * Adds a new data approval level. Sets the level epxlicitl.
+     * 
+     * @param approvalLevel the new level to add.
+     * @param level the level.
+     * @return the identifier of the added level, or -1 if not well formed or duplicate.
+     */
+    int addDataApprovalLevel( DataApprovalLevel approvalLevel, int level );
 
     /**
      * Removes a data approval level.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-04-28 09:48:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-04-28 10:17:37 +0000
@@ -28,6 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
 import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -38,15 +46,6 @@
 import org.hisp.dhis.user.User;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * @author Jim Grace
  */
@@ -259,11 +258,6 @@
 
     public int addDataApprovalLevel( DataApprovalLevel newLevel )
     {
-        if ( newLevel.getOrgUnitLevel() <= 0 )
-        {
-            return -1;
-        }
-
         List<DataApprovalLevel> dataApprovalLevels = getAllDataApprovalLevels();
 
         int index = getInsertIndex( dataApprovalLevels, newLevel );
@@ -283,10 +277,16 @@
         }
 
         newLevel.setLevel( index + 1 );
-        newLevel.setCreated( new Date() );
 
         return dataApprovalLevelStore.save( newLevel );
     }
+
+    public int addDataApprovalLevel( DataApprovalLevel approvalLevel, int level )
+    {
+        approvalLevel.setLevel( level );
+        
+        return dataApprovalLevelStore.save( approvalLevel );        
+    }
     
     public void deleteDataApprovalLevel( DataApprovalLevel dataApprovalLevel )
     {

=== 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 09:05:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java	2014-04-28 10:17:37 +0000
@@ -202,10 +202,10 @@
     @Test
     public void testAddDataApprovalLevel() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level3B );
-        dataApprovalLevelService.addDataApprovalLevel( level2C );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level4A );
+        dataApprovalLevelService.addDataApprovalLevel( level2C, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level3B, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level4A, 4 );
         
         List<DataApprovalLevel> levels = dataApprovalLevelService.getAllDataApprovalLevels();
         assertEquals( 4, levels.size() );
@@ -230,10 +230,10 @@
     @Test
     public void testDeleteDataApprovalLevel() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level2B );
-        dataApprovalLevelService.addDataApprovalLevel( level3C );
-        dataApprovalLevelService.addDataApprovalLevel( level4D );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level2B, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level3C, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level4D, 4 );
 
         List<DataApprovalLevel> levels = null;
 
@@ -274,12 +274,12 @@
     @Test
     public void testExists() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level1B );
-        dataApprovalLevelService.addDataApprovalLevel( level2A );
-        dataApprovalLevelService.addDataApprovalLevel( level2B );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level1B, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level2A, 5 );
+        dataApprovalLevelService.addDataApprovalLevel( level2B, 6 );
 
         assertTrue( dataApprovalLevelService.dataApprovalLevelExists( level1A ) );
         assertTrue( dataApprovalLevelService.dataApprovalLevelExists( level1A ) );
@@ -299,15 +299,15 @@
     @Test
     public void testCanMoveDown() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level1B );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level2A );
-        dataApprovalLevelService.addDataApprovalLevel( level2B );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level3A );
-        dataApprovalLevelService.addDataApprovalLevel( level3B );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level1B, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level2A, 5 );
+        dataApprovalLevelService.addDataApprovalLevel( level2B, 6 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 7 );
+        dataApprovalLevelService.addDataApprovalLevel( level3A, 8 );
+        dataApprovalLevelService.addDataApprovalLevel( level3B, 9 );
 
         assertFalse( dataApprovalLevelService.canDataApprovalLevelMoveDown( -1 ) );
         assertFalse( dataApprovalLevelService.canDataApprovalLevelMoveDown( 0 ) );
@@ -327,15 +327,15 @@
     @Test
     public void testCanMoveUp() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level1B );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level2A );
-        dataApprovalLevelService.addDataApprovalLevel( level2B );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level3A );
-        dataApprovalLevelService.addDataApprovalLevel( level3B );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level1B, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level2A, 5 );
+        dataApprovalLevelService.addDataApprovalLevel( level2B, 6 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 7 );
+        dataApprovalLevelService.addDataApprovalLevel( level3A, 8 );
+        dataApprovalLevelService.addDataApprovalLevel( level3B, 9 );
 
         assertFalse( dataApprovalLevelService.canDataApprovalLevelMoveUp( -1 ) );
         assertFalse( dataApprovalLevelService.canDataApprovalLevelMoveUp( 0 ) );
@@ -355,11 +355,11 @@
     @Test
     public void testMoveDown() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1D );
-        dataApprovalLevelService.addDataApprovalLevel( level1C );
-        dataApprovalLevelService.addDataApprovalLevel( level1B );
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level1B, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level1C, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level1D, 5 );
 
         List<DataApprovalLevel> levels;
 
@@ -395,11 +395,11 @@
     @Test
     public void testMoveUp() throws Exception
     {
-        dataApprovalLevelService.addDataApprovalLevel( level1D );
-        dataApprovalLevelService.addDataApprovalLevel( level1C );
-        dataApprovalLevelService.addDataApprovalLevel( level1B );
-        dataApprovalLevelService.addDataApprovalLevel( level1A );
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level1A, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level1B, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level1C, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level1D, 5 );
 
         List<DataApprovalLevel> levels;
 
@@ -446,11 +446,11 @@
         organisationUnitService.addOrganisationUnit( organisationUnitG );
         organisationUnitService.addOrganisationUnit( organisationUnitH );
 
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level4 );
-        dataApprovalLevelService.addDataApprovalLevel( level5 );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level4, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level5, 5 );
 
         Set<OrganisationUnit> assignedOrgUnits = new HashSet<OrganisationUnit>();
         assignedOrgUnits.add( organisationUnitC );
@@ -481,11 +481,11 @@
         organisationUnitService.addOrganisationUnit( organisationUnitG );
         organisationUnitService.addOrganisationUnit( organisationUnitH );
 
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level4 );
-        dataApprovalLevelService.addDataApprovalLevel( level5 );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level4, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level5, 5 );
 
         Set<OrganisationUnit> assignedOrgUnits = new HashSet<OrganisationUnit>();
         assignedOrgUnits.add( organisationUnitC );
@@ -516,10 +516,10 @@
         organisationUnitService.addOrganisationUnit( organisationUnitG );
         organisationUnitService.addOrganisationUnit( organisationUnitH );
 
-        dataApprovalLevelService.addDataApprovalLevel( level1 ); // 1st approval level
-        dataApprovalLevelService.addDataApprovalLevel( level2 ); // 2nd approval level
-        dataApprovalLevelService.addDataApprovalLevel( level3 ); // 3rd approval level
-        dataApprovalLevelService.addDataApprovalLevel( level5 ); // 4th approval level
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 ); // 1st approval level
+        dataApprovalLevelService.addDataApprovalLevel( level2, 2 ); // 2nd approval level
+        dataApprovalLevelService.addDataApprovalLevel( level3, 3 ); // 3rd approval level
+        dataApprovalLevelService.addDataApprovalLevel( level5, 4 ); // 4th approval level
 
         Set<OrganisationUnit> assignedOrgUnits = new HashSet<OrganisationUnit>();
         assignedOrgUnits.add( organisationUnitC );
@@ -553,11 +553,11 @@
         organisationUnitService.addOrganisationUnit( organisationUnitJ );
         organisationUnitService.addOrganisationUnit( organisationUnitK );
 
-        dataApprovalLevelService.addDataApprovalLevel( level1 );
-        dataApprovalLevelService.addDataApprovalLevel( level2 );
-        dataApprovalLevelService.addDataApprovalLevel( level3 );
-        dataApprovalLevelService.addDataApprovalLevel( level4 );
-        dataApprovalLevelService.addDataApprovalLevel( level5 );
+        dataApprovalLevelService.addDataApprovalLevel( level1, 1 );
+        dataApprovalLevelService.addDataApprovalLevel( level2, 2 );
+        dataApprovalLevelService.addDataApprovalLevel( level3, 3 );
+        dataApprovalLevelService.addDataApprovalLevel( level4, 4 );
+        dataApprovalLevelService.addDataApprovalLevel( level5, 5 );
 
         Set<OrganisationUnit> assignedOrgUnits = new HashSet<OrganisationUnit>();
         assignedOrgUnits.add( organisationUnitC );