dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37111
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18978: Approval/analytics, minor performance improvement, calling getAllDataApprovalLevels only once per...
------------------------------------------------------------
revno: 18978
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-04-22 12:39:06 +0200
message:
Approval/analytics, minor performance improvement, calling getAllDataApprovalLevels only once per request
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.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/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2015-04-22 09:19:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2015-04-22 10:39:06 +0000
@@ -497,6 +497,8 @@
return null;
}
+ List<DataApprovalLevel> approvalLevels = getAllDataApprovalLevels();
+
OrganisationUnit organisationUnit = null;
for ( OrganisationUnit unit : user.getOrganisationUnits() )
@@ -508,7 +510,7 @@
}
}
- return organisationUnit != null ? getUserApprovalLevel( organisationUnit, user ) : null;
+ return organisationUnit != null ? getUserApprovalLevel( organisationUnit, user, approvalLevels ) : null;
}
@Override
@@ -518,6 +520,8 @@
User user = currentUserService.getCurrentUser();
+ List<DataApprovalLevel> approvalLevels = getAllDataApprovalLevels();
+
// ---------------------------------------------------------------------
// Add user organisation units if authorized to approve at lower levels
// ---------------------------------------------------------------------
@@ -533,7 +537,7 @@
{
for ( OrganisationUnit orgUnit : user.getOrganisationUnits() )
{
- map.put( orgUnit, requiredApprovalLevel( orgUnit, user ) );
+ map.put( orgUnit, requiredApprovalLevel( orgUnit, user, approvalLevels ) );
}
}
@@ -552,7 +556,7 @@
{
if ( !map.containsKey( orgUnit ) )
{
- map.put( orgUnit, requiredApprovalLevel( orgUnit, user ) );
+ map.put( orgUnit, requiredApprovalLevel( orgUnit, user, approvalLevels ) );
}
}
@@ -670,14 +674,16 @@
* approved data only from lower approval levels.
*
* @param orgUnit organisation unit to test.
+ * @param user the user.
+ * @param approvalLevels all data approval levels.
* @return required approval level for user to see the data.
*/
- private int requiredApprovalLevel( OrganisationUnit orgUnit, User user )
+ private int requiredApprovalLevel( OrganisationUnit orgUnit, User user, List<DataApprovalLevel> approvalLevels )
{
- DataApprovalLevel userLevel = getUserApprovalLevel( orgUnit, user );
+ DataApprovalLevel userLevel = getUserApprovalLevel( orgUnit, user, approvalLevels );
return userLevel == null ? 0 :
- userLevel.getLevel() == getAllDataApprovalLevels().size() ? APPROVAL_LEVEL_UNAPPROVED :
+ userLevel.getLevel() == approvalLevels.size() ? APPROVAL_LEVEL_UNAPPROVED :
userLevel.getLevel() + 1;
}
@@ -701,19 +707,21 @@
* users may accept/unaccept at the level just *below* this level.
*
* @param orgUnit organisation unit to test.
+ * @param user the user.
+ * @param approvalLevels app data approval levels.
* @return approval level for user.
*/
- private DataApprovalLevel getUserApprovalLevel( OrganisationUnit orgUnit, User user )
+ private DataApprovalLevel getUserApprovalLevel( OrganisationUnit orgUnit, User user, List<DataApprovalLevel> approvalLevels )
{
int orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
DataApprovalLevel userLevel = null;
- for ( DataApprovalLevel level : getAllDataApprovalLevels() )
+ for ( DataApprovalLevel level : approvalLevels )
{
- if ( level.getOrgUnitLevel() >= orgUnitLevel
- && securityService.canRead( level )
- && canReadCOGS( user, level.getCategoryOptionGroupSet() ) )
+ if ( level.getOrgUnitLevel() >= orgUnitLevel &&
+ securityService.canRead( level ) &&
+ canReadCOGS( user, level.getCategoryOptionGroupSet() ) )
{
userLevel = level;
break;