← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21939: Approvals fixes: period alignment and multi-aoc

 

------------------------------------------------------------
revno: 21939
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2016-02-10 23:11:46 -0500
message:
  Approvals fixes: period alignment and multi-aoc
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	2016-02-09 21:30:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2016-02-11 04:11:46 +0000
@@ -120,13 +120,11 @@
     {
         log.debug( "approveData ( " + dataApprovalList.size() + " items )" );
 
-        List<DataApproval> expandedList = expandPeriods( dataApprovalList );
-
-        Map<String, DataApprovalStatus> statusMap = getStatusMap( expandedList );
+        Map<String, DataApprovalStatus> statusMap = getStatusMap( dataApprovalList );
 
         List<DataApproval> checkedList = new ArrayList<>();
 
-        for ( DataApproval da : expandedList )
+        for ( DataApproval da : dataApprovalList )
         {
             DataApprovalStatus status = statusMap.get( daKey( da ) );
 
@@ -184,13 +182,11 @@
     {
         log.debug( "unapproveData ( " + dataApprovalList.size() + " items )" );
 
-        List<DataApproval> expandedList = expandPeriods( dataApprovalList );
-
-        Map<String, DataApprovalStatus> statusMap = getStatusMap( expandedList );
+        Map<String, DataApprovalStatus> statusMap = getStatusMap( dataApprovalList );
 
         List<DataApproval> checkedList = new ArrayList<>();
 
-        for ( DataApproval da : expandedList )
+        for ( DataApproval da : dataApprovalList )
         {
             DataApprovalStatus status = statusMap.get( daKey( da ) );
 
@@ -239,13 +235,11 @@
     {
         log.debug( "acceptData ( " + dataApprovalList.size() + " items )" );
 
-        List<DataApproval> expandedList = expandPeriods( dataApprovalList );
-
-        Map<String, DataApprovalStatus> statusMap = getStatusMap( expandedList );
+        Map<String, DataApprovalStatus> statusMap = getStatusMap( dataApprovalList );
 
         List<DataApproval> checkedList = new ArrayList<>();
 
-        for ( DataApproval da : expandedList )
+        for ( DataApproval da : dataApprovalList )
         {
             DataApprovalStatus status = statusMap.get( daKey( da ) );
 
@@ -299,13 +293,11 @@
     {
         log.debug( "unacceptData ( " + dataApprovalList.size() + " items )" );
 
-        List<DataApproval> expandedList = expandPeriods( dataApprovalList );
-
-        Map<String, DataApprovalStatus> statusMap = getStatusMap( expandedList );
+        Map<String, DataApprovalStatus> statusMap = getStatusMap( dataApprovalList );
 
         List<DataApproval> checkedList = new ArrayList<>();
 
-        for ( DataApproval da : expandedList )
+        for ( DataApproval da : dataApprovalList )
         {
             DataApprovalStatus status = statusMap.get( daKey( da ) );
 
@@ -421,40 +413,6 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Returns an list of data approval expanded based on periods. In the cases
-     * where the data set of the approval has a more frequent period type than
-     * the period of the approval, additional approval objects are included for
-     * that period type for each period between the start date and end date of the
-     * approval period.
-     */
-    private List<DataApproval> expandPeriods( List<DataApproval> approvalList )
-    {
-        List<DataApproval> expandedList = new ArrayList<>();
-
-        for ( DataApproval da : approvalList )
-        {
-            if ( da.getPeriod().getPeriodType().getFrequencyOrder() > da.getWorkflow().getPeriodType().getFrequencyOrder() )
-            {
-                Collection<Period> periods = periodService.getPeriodsBetweenDates( da.getWorkflow().getPeriodType(),
-                    da.getPeriod().getStartDate(), da.getPeriod().getEndDate() );
-
-                for ( Period period : periods )
-                {
-                    expandedList.add( new DataApproval( da.getDataApprovalLevel(), da.getWorkflow(),
-                        period, da.getOrganisationUnit(), da.getAttributeOptionCombo(), da.isAccepted(),
-                        da.getCreated(), da.getCreator() ) );
-                }
-            }
-            else
-            {
-                expandedList.add( da );
-            }
-        }
-
-        return expandedList;
-    }
-
-    /**
      * Returns a mapping from data approval key to data approval status for the given
      * list of data approvals.
      */
@@ -479,7 +437,7 @@
             {
                 status.setPermissions( evaluator.getPermissions( status, da.getOrganisationUnit(), da.getWorkflow() ) );
 
-                statusMap.put( daKey( da ), status );
+                statusMap.put( daKey( da, status.getAttributeOptionComboUid() ), status );
             }
         }
 
@@ -525,8 +483,12 @@
      */
     private String daKey ( DataApproval approval )
     {
-        return statusKey( approval ) + IdentifiableObjectUtils.SEPARATOR +
-            ( approval.getAttributeOptionCombo() == null ? "null" : approval.getAttributeOptionCombo().getId() );
+        return daKey( approval, approval.getAttributeOptionCombo() == null ? "null" : approval.getAttributeOptionCombo().getUid() );
+    }
+
+    private String daKey ( DataApproval approval, String attributeOptionComboUid )
+    {
+        return statusKey( approval ) + IdentifiableObjectUtils.SEPARATOR + attributeOptionComboUid;
     }
 
     /**

=== 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	2016-02-04 21:23:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java	2016-02-11 04:11:46 +0000
@@ -701,7 +701,7 @@
         return approvals;
     }
 
-    private List<DataApproval> getDataApprovalList( Approvals approvals )
+    private List<DataApproval> getDataApprovalList( Approvals approvals ) throws WebMessageException
     {
         List<DataSet> dataSets = objectManager.getByUid( DataSet.class, approvals.getDs() );
         List<Period> periods = PeriodType.getPeriodsFromIsoStrings( approvals.getPe() );
@@ -714,6 +714,11 @@
 
         for ( DataSet dataSet : dataSets )
         {
+            if ( dataSet.getWorkflow() == null )
+            {
+                throw new WebMessageException( WebMessageUtils.conflict( "DataSet has no approval workflow: " + dataSet.getName() ) );
+            }
+
             Set<DataElementCategoryOptionCombo> dataSetOptionCombos = dataSet.getCategoryCombo() != null ? dataSet.getCategoryCombo().getOptionCombos() : null;
 
             for ( Approval approval : approvals.getApprovals() )