← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15144: Approval bug fixes

 

------------------------------------------------------------
revno: 15144
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Sun 2014-05-04 17:36:18 -0400
message:
  Approval bug fixes
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties


--
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/DataApprovalSelection.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java	2014-04-28 18:23:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DataApprovalSelection.java	2014-05-04 21:36:18 +0000
@@ -708,6 +708,14 @@
     /**
      * Is this data selection approved at the given level index, for the
      * given organisation unit?
+     * <p>
+     * If we are testing for approval at the same or higher level and
+     * there are selected category options, then the data is approved if
+     * *any selected* category option is approved.
+     * <p>
+     * If we are testing for approval at a lower level and
+     * there are selected category options, then the data is approved if
+     * *all category option group member category options* are approved.
      *
      * @param index (matching) approval level index at which to test.
      * @param orgUnit organisation unit to test.
@@ -715,11 +723,22 @@
      */
     private DataApproval getDataApproval( int index, OrganisationUnit orgUnit )
     {
-        Set<CategoryOptionGroup> groups = categoryOptionGroupsByLevel.get( index );
-
-        if ( groups == null )
-        {
-            DataApproval da = dataApprovalStore.getDataApproval( dataSet, period, orgUnit, null );
+        DataApproval da = null;
+
+        Set<CategoryOptionGroup> groups = null;
+
+        if ( index < lowerIndex )
+        {
+            groups = categoryOptionGroupsByLevel.get( index );
+        }
+        else if ( allApprovalLevels.get( index ).getCategoryOptionGroupSet() != null )
+        {
+            groups = new HashSet<CategoryOptionGroup>( allApprovalLevels.get( index ).getCategoryOptionGroupSet().getMembers() );
+        }
+
+        if ( groups == null || groups.isEmpty() )
+        {
+            da = dataApprovalStore.getDataApproval( dataSet, period, orgUnit, null );
 
             log.debug( "getDataApproval( " + orgUnit.getName() + " ) = " + ( da != null ) + " (no groups)" );
 
@@ -728,19 +747,26 @@
 
         for ( CategoryOptionGroup group : groups )
         {
-            DataApproval da = dataApprovalStore.getDataApproval( dataSet, period, orgUnit, group );
+            da = dataApprovalStore.getDataApproval( dataSet, period, orgUnit, group );
 
             log.debug( "getDataApproval( " + orgUnit.getName() + " ) = " + ( da != null ) + " (group: " + group.getName() + ")" );
 
-            if ( da != null )
-            {
-                return da;
+            if ( index < lowerIndex )
+            {
+                if ( da != null )
+                {
+                    return da;
+                }
+            }
+            else if ( da == null )
+            {
+                return null;
             }
         }
 
-        log.debug( "getDataApproval( " + orgUnit.getName() + " ) = false (none of " + groups.size() + " groups matched)" );
+        log.debug( "getDataApproval( " + orgUnit.getName() + " ) = " + ( da != null ) + " (after testing all " + groups.size() + " groups)" );
 
-        return null;
+        return da;
     }
 
     /**
@@ -771,7 +797,7 @@
 
         if ( lowerIndex < allApprovalLevels.size() )
         {
-            if ( orgUnitLevel == allApprovalLevels.get( lowerIndex ).getLevel() )
+            if ( orgUnitLevel == allApprovalLevels.get( lowerIndex ).getOrgUnitLevel() )
             {
                 log.debug( "isUnapprovedBelow() orgUnit level " + orgUnitLevel + " matches approval level." );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java	2014-04-16 15:56:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java	2014-05-04 21:36:18 +0000
@@ -29,6 +29,7 @@
  */
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -105,7 +106,9 @@
         @RequestParam( required = false ) Set<String> cog,
         @RequestParam( required = false ) String cp, HttpServletResponse response ) throws IOException
     {
-        log.info( "getApprovalState called." );
+        log.info( "GET " + RESOURCE_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+                + ( cog == null || cog.isEmpty() ? "" : ( "&cog=" + Arrays.toString( cog.toArray() ) ) )
+                + ( cp == null ? "" : ( "&cp=" + cp ) ) );
 
         DataSet dataSet = dataSetService.getDataSet( ds );
         
@@ -131,11 +134,16 @@
             return;
         }
 
-        Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroups( response, cog );
+        Set<CategoryOptionGroup> categoryOptionGroups = null;
 
-        if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+        if ( cog != null && !cog.isEmpty() )
         {
-            return;
+            categoryOptionGroups = inputUtils.getAttributeOptionGroups( response, cog );
+
+            if ( categoryOptionGroups == null )
+            {
+                return;
+            }
         }
 
         Set<DataElementCategoryOption> categoryOptions = inputUtils.getAttributeOptions( response, cp );
@@ -165,7 +173,8 @@
         @RequestParam String ou,
         @RequestParam( required = false ) String cog, HttpServletResponse response )
     {
-        log.info( "saveApproval called." );
+        log.info( "POST " + RESOURCE_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+                + ( cog == null ? "" : ( "&cog=" + cog ) ) );
 
         DataSet dataSet = dataSetService.getDataSet( ds );
         
@@ -191,11 +200,16 @@
             return;
         }
 
-        Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+        Set<CategoryOptionGroup> categoryOptionGroups = null;
 
-        if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+        if ( cog != null )
         {
-            return;
+            categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+            if ( categoryOptionGroups == null )
+            {
+                return;
+            }
         }
 
         DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
@@ -215,7 +229,7 @@
 
         User user = currentUserService.getCurrentUser();
 
-        CategoryOptionGroup categoryOptionGroup = categoryOptionGroups == null ? null : (CategoryOptionGroup) categoryOptionGroups.toArray() [0];
+        CategoryOptionGroup categoryOptionGroup = categoryOptionGroups == null || categoryOptionGroups.isEmpty() ? null : (CategoryOptionGroup) categoryOptionGroups.iterator().next();
 
         DataApproval approval = new DataApproval( permissions.getDataApprovalStatus().getDataApprovalLevel(),
                 dataSet, period, organisationUnit, categoryOptionGroup, false, new Date(), user );
@@ -232,7 +246,8 @@
         @RequestParam String ou,
         @RequestParam( required = false ) String cog, HttpServletResponse response )
     {
-        log.info( "removeApproval called." );
+        log.info( "DELETE " + RESOURCE_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+                + ( cog == null ? "" : ( "&cog=" + cog ) ) );
 
         DataSet dataSet = dataSetService.getDataSet( ds );
         
@@ -258,11 +273,16 @@
             return;
         }
 
-        Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+        Set<CategoryOptionGroup> categoryOptionGroups = null;
 
-        if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+        if ( cog != null )
         {
-            return;
+            categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+            if ( categoryOptionGroups == null )
+            {
+                return;
+            }
         }
 
         DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
@@ -294,7 +314,8 @@
             @RequestParam String ou,
             @RequestParam( required = false ) String cog, HttpServletResponse response )
     {
-        log.info( "acceptApproval called." );
+        log.info( "POST " + RESOURCE_PATH + ACCEPTANCES_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+                + ( cog == null ? "" : ( "&cog=" + cog ) ) );
 
         DataSet dataSet = dataSetService.getDataSet( ds );
 
@@ -320,11 +341,16 @@
             return;
         }
 
-        Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+        Set<CategoryOptionGroup> categoryOptionGroups = null;
 
-        if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+        if ( cog != null )
         {
-            return;
+            categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+            if ( categoryOptionGroups == null )
+            {
+                return;
+            }
         }
 
         DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );
@@ -354,7 +380,8 @@
             @RequestParam String ou,
             @RequestParam( required = false ) String cog, HttpServletResponse response )
     {
-        log.info( "unacceptApproval called." );
+        log.info( "DELETE " + RESOURCE_PATH + ACCEPTANCES_PATH + "?ds=" + ds + "&pe=" + pe + "&ou=" + ou
+                + ( cog == null ? "" : ( "&cog=" + cog ) ) );
 
         DataSet dataSet = dataSetService.getDataSet( ds );
 
@@ -380,11 +407,16 @@
             return;
         }
 
-        Set<CategoryOptionGroup> categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+        Set<CategoryOptionGroup> categoryOptionGroups = null;
 
-        if ( categoryOptionGroups != null && categoryOptionGroups.isEmpty() )
+        if ( cog != null )
         {
-            return;
+            categoryOptionGroups = inputUtils.getAttributeOptionGroup( response, cog );
+
+            if ( categoryOptionGroups == null )
+            {
+                return;
+            }
         }
 
         DataApprovalPermissions permissions = dataApprovalService.getDataApprovalPermissions( dataSet, period, organisationUnit, categoryOptionGroups, null );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2014-04-20 15:54:16 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2014-05-04 21:36:18 +0000
@@ -253,7 +253,7 @@
 unapprove=Unapprove
 accept=Accept
 unaccept=Unaccept
-waiting_for_lower_level_approval=Waiting for lower level org units to approve
+waiting_for_lower_level_approval=Waiting for lower levels to approve
 approved=Approved
 approved_and_accepted=Approved and accepted
 ready_for_approval=Ready for approval