← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19064: Lock data entry when org unit is below all approval levels

 

------------------------------------------------------------
revno: 19064
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2015-04-29 19:39:45 -0500
message:
  Lock data entry when org unit is below all approval levels
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.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/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2015-04-29 19:13:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2015-04-30 00:39:45 +0000
@@ -396,7 +396,7 @@
             approvedAboveSubquery = "exists(select 1 from dataapproval da " +
                 "join dataapprovallevel dal on dal.dataapprovallevelid = da.dataapprovallevelid " +
                 "join _orgunitstructure ou on ou.organisationunitid = o.organisationunitid and ou.idlevel" + orgUnitLevelAbove + " = da.organisationunitid " +
-                "where da.periodid in (" + periodIds + ") and da.datasetid in (" + dataSetIds + ") and da.attributeoptioncomboid = cocco.categoryoptioncomboid) ";
+                "where da.periodid in (" + periodIds + ") and da.datasetid in (" + dataSetIds + ") and da.attributeoptioncomboid = cocco.categoryoptioncomboid)";
         }
 
         final String sql =
@@ -469,18 +469,18 @@
             if ( ou != null )
             {
                 DataApproval da = new DataApproval( daLevel, dataSet, period, ou, optionCombo, accepted, null, null );
-    
+
                 DataApprovalState state = (
-                    statusLevel == null ?
-                        lowestApprovalLevelForOrgUnit == null ?
-                            orgUnitLevelAbove == 0 ?
-                                UNAPPROVABLE :
-                                UNAPPROVED_ABOVE :
-                            readyBelow ?
-                                UNAPPROVED_READY :
-                                UNAPPROVED_WAITING :
-                        approvedAbove ?
-                            APPROVED_ABOVE :
+                    approvedAbove ?
+                        APPROVED_ABOVE :
+                        statusLevel == null ?
+                            lowestApprovalLevelForOrgUnit == null ?
+                                orgUnitLevelAbove == 0 ?
+                                    UNAPPROVABLE :
+                                    UNAPPROVED_ABOVE :
+                                readyBelow ?
+                                    UNAPPROVED_READY :
+                                    UNAPPROVED_WAITING :
                             accepted ?
                                 ACCEPTED_HERE :
                                 APPROVED_HERE );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2015-04-16 08:27:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2015-04-30 00:39:45 +0000
@@ -700,7 +700,33 @@
         assertEquals( DataApprovalState.UNAPPROVABLE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitE, defaultCombo ).getState() );
         assertEquals( DataApprovalState.UNAPPROVABLE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitF, defaultCombo ).getState() );
     }
-    
+
+    @Test
+    public void testGetDataApprovalStateAbove() throws Exception
+    {
+        dataApprovalLevelService.addDataApprovalLevel( level3 );
+
+        Set<OrganisationUnit> units = asSet( organisationUnitA );
+
+        CurrentUserService currentUserService = new MockCurrentUserService( units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS );
+        setDependency( dataApprovalService, "currentUserService", currentUserService, CurrentUserService.class );
+        setDependency( dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class );
+
+        dataSetA.setApproveData( true );
+
+        organisationUnitC.addDataSet( dataSetA );
+        organisationUnitD.addDataSet( dataSetA );
+
+        Date date = new Date();
+
+        // Approved for organisation unit C
+        DataApproval dataApprovalC = new DataApproval( level3, dataSetA, periodA, organisationUnitC, defaultCombo, NOT_ACCEPTED, date, userA );
+        dataApprovalService.approveData( asList( dataApprovalC ) );
+
+        assertEquals( DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitC, defaultCombo ).getState() );
+        assertEquals( DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus( dataSetA, periodA, organisationUnitD, defaultCombo ).getState() );
+    }
+
     @Test
     public void testGetDataApprovalStateWithMultipleChildren() throws Exception
     {