=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-17 17:04:50 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-22 10:53:03 +0000 @@ -30,7 +30,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import javax.servlet.http.HttpServletRequest; @@ -38,6 +37,7 @@ import org.apache.commons.collections.CollectionUtils; import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy; import org.hisp.dhis.api.utils.FormUtils; import org.hisp.dhis.api.webdomain.FormDataSet; import org.hisp.dhis.api.webdomain.FormOrganisationUnit; @@ -73,6 +73,7 @@ public class CurrentUserController { public static final String RESOURCE_PATH = "/currentUser"; + private static final int MAX_OBJECTS = 50; @Autowired private CurrentUserService currentUserService; @@ -91,6 +92,9 @@ @Autowired private OrganisationUnitService organisationUnitService; + + @Autowired + private ContextUtils contextUtils; @RequestMapping( produces = {"application/json", "text/*"} ) public void getCurrentUser( HttpServletResponse response ) throws Exception @@ -208,6 +212,8 @@ { User currentUser = currentUserService.getCurrentUser(); + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.CACHE_1_HOUR ); + if ( currentUser == null ) { ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." ); @@ -215,10 +221,10 @@ } Recipients recipients = new Recipients(); - recipients.setOrganisationUnits( getOrganisationUnitsForUser( currentUser, filter ) ); + recipients.setOrganisationUnits( new HashSet( organisationUnitService.getOrganisationUnitsBetweenByName( filter, 0, MAX_OBJECTS ) ) ); - recipients.setUsers( new HashSet( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) ); - recipients.setUserGroups( new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) ); + recipients.setUsers( new HashSet( userService.getAllUsersBetweenByName( filter, 0, MAX_OBJECTS ) ) ); + recipients.setUserGroups( new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, MAX_OBJECTS ) ) ); JacksonUtils.toJson( response.getOutputStream(), recipients ); } @@ -285,33 +291,4 @@ JacksonUtils.toJson( response.getOutputStream(), forms ); } - - private Set getOrganisationUnitsForUser( User user, String filter ) - { - Set organisationUnits = new HashSet(); - - for ( OrganisationUnit organisationUnit : user.getOrganisationUnits() ) - { - organisationUnits.add( organisationUnit ); - organisationUnits.addAll( organisationUnitService.getLeafOrganisationUnits( organisationUnit.getId() ) ); - } - - if ( filter != null ) - { - Iterator iterator = organisationUnits.iterator(); - filter = filter.toUpperCase(); - - while ( iterator.hasNext() ) - { - OrganisationUnit organisationUnit = iterator.next(); - - if ( !organisationUnit.getName().toUpperCase().contains( filter ) ) - { - iterator.remove(); - } - } - } - - return organisationUnits; - } }