← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17273: Approval. Added resources for batch approving, accepting, unapproving, unaccepting.

 

------------------------------------------------------------
revno: 17273
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-10-25 12:28:03 +0200
message:
  Approval. Added resources for batch approving, accepting, unapproving, unaccepting.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2014-10-25 10:06:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2014-10-25 10:28:03 +0000
@@ -215,7 +215,7 @@
             dataApprovalStore.deleteDataApproval( d );
         }
         
-        log.info( "Unapprovals saved: " + dataApprovalList.size() );
+        log.info( "Approvals deleted: " + dataApprovalList.size() );
     }
 
     @Override
@@ -313,7 +313,7 @@
             dataApprovalStore.updateDataApproval( da );
         }
         
-        log.info( "Unaccepts saved: " + dataApprovalList.size() );
+        log.info( "Accepts deleted: " + dataApprovalList.size() );
     }
 
     @Override

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java	2014-10-25 10:06:33 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java	2014-10-25 10:28:03 +0000
@@ -292,7 +292,7 @@
     }
     
     // -------------------------------------------------------------------------
-    // Post
+    // Post, approval
     // -------------------------------------------------------------------------
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@@ -351,9 +351,6 @@
         }
     }
 
-    /**
-     * The data set, period and category option combo associations will be used.
-     */
     @RequestMapping( method = RequestMethod.POST, value = "/batch" )
     public void saveApprovalBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
         HttpServletRequest request, HttpServletResponse response )
@@ -363,36 +360,7 @@
             ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
         }
         
-        List<DataSet> dataSets = objectManager.getByUid( DataSet.class, getUids( dataApproval.getDataSets() ) );
-        List<Period> periods = PeriodType.getPeriodsFromIsoStrings( getUids( dataApproval.getPeriods() ) );
-        List<DataElementCategoryOptionCombo> optionCombos = objectManager.getByUid( DataElementCategoryOptionCombo.class, getUids( dataApproval.getCategoryOptionCombos() ) );
-
-        User user = currentUserService.getCurrentUser();
-        OrganisationUnit unit = user.getOrganisationUnit(); //TODO
-        DataApprovalLevel approvalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( unit, null );
-        
-        Date date = new Date();
-
-        List<DataApproval> approvals = new ArrayList<>();
-        
-        for ( DataSet dataSet : dataSets )
-        {
-            Set<DataElementCategoryOptionCombo> dataSetOptionCombos = dataSet.hasCategoryCombo() ? dataSet.getCategoryCombo().getOptionCombos() : null;
-            
-            for ( Period period : periods )
-            {
-                for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
-                {
-                    if ( dataSetOptionCombos != null && dataSetOptionCombos.contains( optionCombo ) )
-                    {
-                        DataApproval approval = new DataApproval( approvalLevel, dataSet, period, unit, optionCombo, false, date, user );
-                        approvals.add( approval );
-                    }
-                }
-            }
-        }
-        
-        dataApprovalService.approveData( approvals );
+        dataApprovalService.approveData( getDataApprovalList( dataApproval ) );
     }
     
     @PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@@ -457,6 +425,10 @@
         }
     }
 
+    // -------------------------------------------------------------------------
+    // Post, acceptance
+    // -------------------------------------------------------------------------
+
     @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
     @RequestMapping( value = ACCEPTANCES_PATH, method = RequestMethod.POST )
     public void acceptApproval(
@@ -513,6 +485,18 @@
         }
     }
 
+    @RequestMapping( method = RequestMethod.POST, value = "/acceptances/batch" )
+    public void saveAcceptanceBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+        HttpServletRequest request, HttpServletResponse response )
+    {
+        if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+        {
+            ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
+        }
+        
+        dataApprovalService.acceptData( getDataApprovalList( dataApproval ) );
+    }
+    
     @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
     @RequestMapping( method = RequestMethod.POST, value = MULTIPLE_ACCEPTANCES_RESOURCE_PATH )
     public void acceptApprovalMultiple( @RequestBody DataApprovalStateRequests dataApprovalStateRequests, 
@@ -575,7 +559,7 @@
     }
 
     // -------------------------------------------------------------------------
-    // Delete
+    // Delete, approval
     // -------------------------------------------------------------------------
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@@ -639,6 +623,22 @@
         }
     }
 
+    @RequestMapping( method = RequestMethod.DELETE, value = "/batch" )
+    public void removeApprovalBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+        HttpServletRequest request, HttpServletResponse response )
+    {
+        if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+        {
+            ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
+        }
+        
+        dataApprovalService.unapproveData( getDataApprovalList( dataApproval ) );
+    }
+
+    // -------------------------------------------------------------------------
+    // Delete, acceptance
+    // -------------------------------------------------------------------------
+
     @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )
     @RequestMapping( value = ACCEPTANCES_PATH, method = RequestMethod.DELETE )
     public void unacceptApproval(
@@ -695,6 +695,18 @@
         }
     }
 
+    @RequestMapping( method = RequestMethod.DELETE, value = "/acceptances/batch" )
+    public void removeAcceptancesBatch( @RequestBody BaseMetaDataCollectionObject dataApproval,
+        HttpServletRequest request, HttpServletResponse response )
+    {
+        if ( !dataApproval.hasDataSets() || !dataApproval.hasPeriods() || !dataApproval.hasCategoryOptionCombos() )
+        {
+            ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
+        }
+        
+        dataApprovalService.unacceptData( getDataApprovalList( dataApproval ) );
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -710,4 +722,38 @@
 
         return approvals;
     }
+
+    private List<DataApproval> getDataApprovalList( BaseMetaDataCollectionObject dataApproval )
+    {
+        List<DataSet> dataSets = objectManager.getByUid( DataSet.class, getUids( dataApproval.getDataSets() ) );
+        List<Period> periods = PeriodType.getPeriodsFromIsoStrings( getUids( dataApproval.getPeriods() ) );
+        List<DataElementCategoryOptionCombo> optionCombos = objectManager.getByUid( DataElementCategoryOptionCombo.class, getUids( dataApproval.getCategoryOptionCombos() ) );
+
+        User user = currentUserService.getCurrentUser();
+        OrganisationUnit unit = user.getOrganisationUnit(); //TODO
+        DataApprovalLevel approvalLevel = dataApprovalLevelService.getHighestDataApprovalLevel( unit, null );
+        
+        Date date = new Date();
+
+        List<DataApproval> approvals = new ArrayList<>();
+        
+        for ( DataSet dataSet : dataSets )
+        {
+            Set<DataElementCategoryOptionCombo> dataSetOptionCombos = dataSet.hasCategoryCombo() ? dataSet.getCategoryCombo().getOptionCombos() : null;
+            
+            for ( Period period : periods )
+            {
+                for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+                {
+                    if ( dataSetOptionCombos != null && dataSetOptionCombos.contains( optionCombo ) )
+                    {
+                        DataApproval approval = new DataApproval( approvalLevel, dataSet, period, unit, optionCombo, false, date, user );
+                        approvals.add( approval );
+                    }
+                }
+            }
+        }
+        
+        return approvals;
+    }
 }