dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29319
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14782: Analytics, applying org unit dimension as mandatory constraint. I.e. if current user has data vie...
------------------------------------------------------------
revno: 14782
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-11 00:52:55 +0200
message:
Analytics, applying org unit dimension as mandatory constraint. I.e. if current user has data view org units, but does not specify any org units in the query, the data view org units are applied as filter in the request.
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
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-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2014-04-10 21:12:18 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2014-04-10 22:52:55 +0000
@@ -291,14 +291,63 @@
return queryGroups;
}
+ // -------------------------------------------------------------------------
+ // Dimension constraints methods
+ // -------------------------------------------------------------------------
+
public void applyDimensionConstraints( DataQueryParams params )
{
- User user = currentUserService.getCurrentUser();
-
- if ( params == null || user == null ||
- user.getUserCredentials() == null || !user.getUserCredentials().hasDimensionConstraints() )
- {
- log.debug( "No dimension constraint applied" );
+ applyOrganisationUnitConstraint( params );
+ applyUserConstraints( params );
+ }
+
+ private void applyOrganisationUnitConstraint( DataQueryParams params )
+ {
+ User user = currentUserService.getCurrentUser();
+
+ // ---------------------------------------------------------------------
+ // Check if current user has data view organisation units
+ // ---------------------------------------------------------------------
+
+ if ( params == null || user == null || !user.hasDataViewOrganisationUnit() )
+ {
+ return;
+ }
+
+ // ---------------------------------------------------------------------
+ // Check if request already has organisation units specified
+ // ---------------------------------------------------------------------
+
+ if ( params.hasDimensionOrFilterWithItems( DimensionalObject.ORGUNIT_DIM_ID ) )
+ {
+ return;
+ }
+
+ // -----------------------------------------------------------------
+ // Apply constraint as filter, and remove potential all-dimension
+ // -----------------------------------------------------------------
+
+ params.removeDimensionOrFilter( DimensionalObject.ORGUNIT_DIM_ID );
+
+ List<OrganisationUnit> orgUnits = new ArrayList<OrganisationUnit>( user.getDataViewOrganisationUnits() );
+
+ DimensionalObject constraint = new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATIONUNIT, orgUnits );
+
+ params.getFilters().add( constraint );
+
+ log.info( "User: " + user.getUsername() + " constrained by data view organisation units" );
+ }
+
+ private void applyUserConstraints( DataQueryParams params )
+ {
+ User user = currentUserService.getCurrentUser();
+
+ // ---------------------------------------------------------------------
+ // Check if current user has dimension constraints
+ // ---------------------------------------------------------------------
+
+ if ( params == null || user == null || user.getUserCredentials() == null || !user.getUserCredentials().hasDimensionConstraints() )
+ {
return;
}
@@ -307,7 +356,7 @@
for ( DimensionalObject dimension : dimensionConstraints )
{
// -----------------------------------------------------------------
- // Check if constraint is already specified with items
+ // Check if constraint already is specified with items
// -----------------------------------------------------------------
if ( params.hasDimensionOrFilterWithItems( dimension.getUid() ) )
=== 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-04-10 21:20:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-04-10 22:52:55 +0000
@@ -90,7 +90,7 @@
{
List<DataApprovalLevel> dataApprovalLevels = dataApprovalLevelStore.getAllDataApprovalLevels();
- for ( DataApprovalLevel dataApprovalLevel : dataApprovalLevels)
+ for ( DataApprovalLevel dataApprovalLevel : dataApprovalLevels )
{
int ouLevelNumber = dataApprovalLevel.getOrgUnitLevel();