dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31274
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15921: TEI query, implemented new ou search mode ACCESSIBLE
------------------------------------------------------------
revno: 15921
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-30 20:29:16 +0200
message:
TEI query, implemented new ou search mode ACCESSIBLE
modified:
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.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-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-06-30 18:07:45 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-06-30 18:29:16 +0000
@@ -35,6 +35,7 @@
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.PAGER_META_KEY;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_ID;
import static org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams.TRACKED_ENTITY_INSTANCE_ID;
+import static org.hisp.dhis.common.OrganisationUnitSelectionMode.*;
import java.util.Collection;
import java.util.Date;
@@ -70,6 +71,7 @@
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
import org.hisp.dhis.validation.ValidationCriteria;
import org.springframework.transaction.annotation.Transactional;
@@ -166,6 +168,14 @@
// Verify params
// ---------------------------------------------------------------------
+ User user = currentUserService.getCurrentUser();
+
+ if ( user != null && params.isOrganisationUnitMode( OrganisationUnitSelectionMode.ACCESSIBLE ) )
+ {
+ params.setOrganisationUnits( user.getDataViewOrganisationUnitsWithFallback() );
+ params.setOrganisationUnitMode( OrganisationUnitSelectionMode.DESCENDANTS );
+ }
+
for ( OrganisationUnit organisationUnit : params.getOrganisationUnits() )
{
if ( !organisationUnit.hasLevel() )
@@ -283,7 +293,7 @@
public void decideAccess( TrackedEntityInstanceQueryParams params )
{
- if ( params.isOrganisationUnitMode( OrganisationUnitSelectionMode.ALL ) &&
+ if ( params.isOrganisationUnitMode( ALL ) &&
!currentUserService.currenUserIsAuthorized( F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS ) )
{
throw new IllegalQueryException( "Current user is not authorized to query across all organisation units" );
@@ -301,10 +311,17 @@
throw new IllegalQueryException( "Params cannot be null" );
}
- if ( !params.hasOrganisationUnits() && !params.isOrganisationUnitMode( OrganisationUnitSelectionMode.ALL ) )
+ User user = currentUserService.getCurrentUser();
+
+ if ( !params.hasOrganisationUnits() && !( params.isOrganisationUnitMode( ALL ) || params.isOrganisationUnitMode( ACCESSIBLE ) ) )
{
violation = "At least one organisation unit must be specified";
}
+
+ if ( params.isOrganisationUnitMode( ACCESSIBLE ) && ( user == null || !user.hasDataViewOrganisationUnitWithFallback() ) )
+ {
+ violation = "Current user must be associated with at least one organisation unit when selection mode is ACCESSIBLE";
+ }
if ( params.hasProgram() && params.hasTrackedEntity() )
{