← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20647: Data approval level. Split the add function into prepareAdd and add. Hooking in the prepareAdd me...

 

------------------------------------------------------------
revno: 20647
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-10-12 18:34:33 +0200
message:
  Data approval level. Split the add function into prepareAdd and add. Hooking in the prepareAdd method in DataApprovalLevelController.
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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalLevelController.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	2015-09-16 15:14:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2015-10-12 16:34:33 +0000
@@ -188,6 +188,15 @@
     boolean dataApprovalLevelExists ( DataApprovalLevel level );
 
     /**
+     * Reorders the existing approval levels to prepare insert of the given
+     * approval level. Should be followed by saving of the approval level.
+     * 
+     * @param level the level to add.
+     * @return true if the level can be added, false if not.
+     */
+    boolean prepareAddDataApproval( DataApprovalLevel level );
+    
+    /**
      * Adds a new data approval level. Adds the new level at the highest
      * position possible (to facilitate the use case where users add the
      * approval levels from low to high.)
@@ -198,7 +207,7 @@
     int addDataApprovalLevel( DataApprovalLevel level );
     
     /**
-     * Adds a new data approval level. Sets the level epxlicitl.
+     * Adds a new data approval level. Sets the level explicitly.
      * 
      * @param approvalLevel the new level to add.
      * @param level the 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	2015-09-16 18:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2015-10-12 16:34:33 +0000
@@ -427,7 +427,7 @@
     }
 
     @Override
-    public int addDataApprovalLevel( DataApprovalLevel level )
+    public boolean prepareAddDataApproval( DataApprovalLevel level )
     {
         List<DataApprovalLevel> dataApprovalLevels = getAllDataApprovalLevels();
 
@@ -435,7 +435,7 @@
 
         if ( index < 0 )
         {
-            return -1;
+            return false;
         }
 
         dataApprovalLevels.add( index, level );
@@ -448,6 +448,17 @@
         }
 
         level.setLevel( index + 1 );
+        
+        return true;
+    }
+    
+    @Override
+    public int addDataApprovalLevel( DataApprovalLevel level )
+    {
+        if ( !prepareAddDataApproval( level ) )
+        {
+            return -1;
+        }
 
         return dataApprovalLevelStore.save( level );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalLevelController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalLevelController.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalLevelController.java	2015-10-12 16:34:33 +0000
@@ -29,7 +29,9 @@
  */
 
 import org.hisp.dhis.dataapproval.DataApprovalLevel;
+import org.hisp.dhis.dataapproval.DataApprovalLevelService;
 import org.hisp.dhis.schema.descriptors.DataApprovalLevelSchemaDescriptor;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 
@@ -38,4 +40,12 @@
 public class DataApprovalLevelController
     extends AbstractCrudController<DataApprovalLevel>
 {
+    @Autowired
+    private DataApprovalLevelService dataApprovalLevelService;
+    
+    @Override
+    protected void preCreateEntity( DataApprovalLevel entity )
+    {
+        dataApprovalLevelService.prepareAddDataApproval( entity );
+    }
 }