dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19621
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8639: Caching in CurrentUserController
------------------------------------------------------------
revno: 8639
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-22 12:53:03 +0200
message:
Caching in CurrentUserController
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.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-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<OrganisationUnit>( organisationUnitService.getOrganisationUnitsBetweenByName( filter, 0, MAX_OBJECTS ) ) );
- recipients.setUsers( new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
- recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
+ recipients.setUsers( new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, MAX_OBJECTS ) ) );
+ recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, MAX_OBJECTS ) ) );
JacksonUtils.toJson( response.getOutputStream(), recipients );
}
@@ -285,33 +291,4 @@
JacksonUtils.toJson( response.getOutputStream(), forms );
}
-
- private Set<OrganisationUnit> getOrganisationUnitsForUser( User user, String filter )
- {
- Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
-
- for ( OrganisationUnit organisationUnit : user.getOrganisationUnits() )
- {
- organisationUnits.add( organisationUnit );
- organisationUnits.addAll( organisationUnitService.getLeafOrganisationUnits( organisationUnit.getId() ) );
- }
-
- if ( filter != null )
- {
- Iterator<OrganisationUnit> iterator = organisationUnits.iterator();
- filter = filter.toUpperCase();
-
- while ( iterator.hasNext() )
- {
- OrganisationUnit organisationUnit = iterator.next();
-
- if ( !organisationUnit.getName().toUpperCase().contains( filter ) )
- {
- iterator.remove();
- }
- }
- }
-
- return organisationUnits;
- }
}