← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17254: fetch approval permisisons without option groups and options

 

------------------------------------------------------------
revno: 17254
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-10-23 16:41:45 -0400
message:
  fetch approval permisisons without option groups and options
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalService.java
  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/DefaultDataApprovalService.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/DataApprovalService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalService.java	2014-10-23 18:10:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalService.java	2014-10-23 20:41:45 +0000
@@ -91,6 +91,22 @@
                                               DataElementCategoryOptionCombo attributeOptionCombo );
 
     /**
+     * Returns the data approval status and permissions for a given data set,
+     * period, organisation unit and attribute category combination.
+     * If attributeOptionCombo is null, the default option combo will be used.
+     * If data is approved at multiple levels, the lowest level is returned.
+     *
+     * @param dataSet DataSet to check for approval.
+     * @param period Period to check for approval.
+     * @param organisationUnit OrganisationUnit to check for approval.
+     * @param attributeOptionCombo CategoryOptionCombo (if any) for approval.
+     * @return the data approval status.
+     */
+    DataApprovalStatus getDataApprovalStatusAndPermissions( DataSet dataSet, Period period,
+                                                            OrganisationUnit organisationUnit,
+                                                            DataElementCategoryOptionCombo attributeOptionCombo );
+
+    /**
      * Returns the data approval permissions and status for a given data set,
      * period, organisation unit, category option group and/or and attribute
      * category combination. If attributeOptionCombo is null, the default

=== 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	2014-10-23 09:39:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-10-23 20:41:45 +0000
@@ -733,16 +733,6 @@
                 && CollectionUtils.isEmpty( userCredentials.getCatDimensionConstraints() );
         }
 
-        for ( CategoryOptionGroup cog : cogs.getMembers() )
-        {
-            tracePrint("canReadCOGS( " + cogs.getName() + " ) cog " + cog.getName() + " " + securityService.canRead( cog ) );
-
-            if ( securityService.canRead( cog ) )
-            {
-                return true;
-            }
-        }
-        
-        return false;
+        return !CollectionUtils.isEmpty( categoryService.getAllCategoryOptionGroups() );
     }
 }

=== 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-23 18:31:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2014-10-23 20:41:45 +0000
@@ -356,9 +356,17 @@
     }
 
     @Override
+    public DataApprovalStatus getDataApprovalStatusAndPermissions( DataSet dataSet, Period period, OrganisationUnit organisationUnit, DataElementCategoryOptionCombo attributeOptionCombo )
+    {
+        DataApprovalStatus status = getDataApprovalStatus( dataSet, period, organisationUnit, attributeOptionCombo );
+
+        return getPermissions( status.getDataApprovalLevel(), status, status.getDataApproval() );
+    }
+
+    @Override
     public DataApprovalStatus getDataApprovalStatusAndPermissions( DataSet dataSet, Period period,
-                                    OrganisationUnit organisationUnit, Set<CategoryOptionGroup> categoryOptionGroups,
-                                    Set<DataElementCategoryOption> attributeCategoryOptions )
+                                                                   OrganisationUnit organisationUnit, Set<CategoryOptionGroup> categoryOptionGroups,
+                                                                   Set<DataElementCategoryOption> attributeCategoryOptions )
     {
         tracePrint( "---------------------------------------------------------------------- getDataApprovalStatusAndPermissions" );
 
@@ -389,7 +397,7 @@
             return new DataApprovalStatus( DataApprovalState.UNAPPROVABLE, null, null, null );
         }
 
-        DataApproval da = checkDataApproval( new DataApproval( dal, dataSet, period, organisationUnit, null, false, null, null ), true, new HashMap<OrganisationUnit, Integer>() );
+        DataApproval da = checkDataApproval( new DataApproval( dal, dataSet, period, organisationUnit, null, false, null, null ), true );
 
         DataApprovalStatus status = doGetDataApprovalStatus( makeApprovalsList( da, asSet( dataSet ), categoryOptionGroups, attributeCategoryOptions, true ), da );
 
@@ -466,7 +474,7 @@
             return checkApprovalsList( org.hisp.dhis.system.util.CollectionUtils.asList( dataApproval ), dataSets, isGetStatus );
         }
 
-        DataApproval da = checkDataApproval( dataApproval, false, new HashMap<OrganisationUnit, Integer>() );
+        DataApproval da = checkDataApproval( dataApproval, false );
 
         tracePrint("makeApprovalsList(2) combo - " + ( da.getAttributeOptionCombo() == null ? "(null)" : da.getAttributeOptionCombo().getName() ) );
 
@@ -538,11 +546,9 @@
     {
         List<DataApproval> daList = new ArrayList<>();
 
-        Map<OrganisationUnit, Integer> approvalLevelCache = new HashMap<>();
-
         for ( DataApproval dataApproval : dataApprovalList )
         {
-            DataApproval da = checkDataApproval( dataApproval, isGetStatus, approvalLevelCache );
+            DataApproval da = checkDataApproval( dataApproval, isGetStatus );
 
             tracePrint("checkApprovalsList(1) combo - " + ( da.getAttributeOptionCombo() == null ? "(null)" : da.getAttributeOptionCombo().getName() ) );
 
@@ -570,7 +576,7 @@
         return false;
     }
 
-    private DataApproval checkDataApproval( DataApproval dataApproval, boolean includeDataViewOrgUnits, Map<OrganisationUnit, Integer> approvalLevelCache )
+    private DataApproval checkDataApproval( DataApproval dataApproval, boolean includeDataViewOrgUnits )
     {
         DataApproval da = new DataApproval ( dataApproval ); // Defensive copy so we can change it.
 
@@ -586,21 +592,9 @@
             tracePrint( "getDefaultDataElementCategoryOptionCombo() -> " + ( da.getAttributeOptionCombo() == null ? "(null)" : da.getAttributeOptionCombo().getName() ) );
         }
 
-        Integer userLevel = approvalLevelCache.get( da.getOrganisationUnit() );
+        DataApprovalLevel dal = dataApprovalLevelService.getUserApprovalLevel( da.getOrganisationUnit(), includeDataViewOrgUnits );
 
-        if ( userLevel == null )
-        {
-            DataApprovalLevel dal = dataApprovalLevelService.getUserApprovalLevel( da.getOrganisationUnit(), includeDataViewOrgUnits );
-            if ( dal == null )
-            {
-                userLevel = 99999;
-            }
-            else
-            {
-                userLevel = dal.getLevel();
-            }
-            approvalLevelCache.put( da.getOrganisationUnit(), userLevel );
-        }
+        int userLevel = ( dal == null ? 99999 : dal.getLevel() );
 
         tracePrint( "userLevel ( " + da.getOrganisationUnit().getName() + " ): " + userLevel + ", data approval level " + da.getDataApprovalLevel().getLevel() );
         log.info( "userLevel ( " + da.getOrganisationUnit().getName() + " ): " + userLevel );
@@ -783,7 +777,7 @@
         tracePrint( "getPermissions - dal " + ( dal == null ? "(null)" : dal.getName() )
                 + " dataApproval null? " + ( status.getDataApproval() == null ) );
 
-        if ( dal != null && securityService.canRead( dal ) && status.getDataApproval() != null
+        if ( da != null && dal != null && securityService.canRead( dal ) && status.getDataApproval() != null
                 && ( dal.getCategoryOptionGroupSet() == null || securityService.canRead( dal.getCategoryOptionGroupSet() ) ) )
         {
             DataApprovalState state = status.getState();