=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-09-24 06:28:31 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-10-06 10:40:16 +0000 @@ -93,7 +93,9 @@ */ Collection getAllUsers(); - Collection getAllUsersBetween(int first, int max); + Collection getAllUsersBetween( int first, int max ); + + Collection getAllUsersBetweenByName( String name, int first, int max ); Collection getUsersByLastUpdated(Date lastUpdated); @@ -133,8 +135,6 @@ int getUserCountByName( String name ); - Collection getUsersByName(String name); - int getUsersWithoutOrganisationUnitCount(); int getUsersWithoutOrganisationUnitCountByName( String name ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-09-24 06:28:31 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-10-06 10:40:16 +0000 @@ -188,6 +188,12 @@ { return userStore.getBetween( first, max ); } + + @Override + public Collection getAllUsersBetweenByName( String name, int first, int max ) + { + return userStore.getBetweenByName( name, first, max ); + } @Override public Collection getUsersByLastUpdated( Date lastUpdated ) @@ -392,23 +398,6 @@ return userCredentialsStore.getUserCountByName( userName ); } - @Override - public Collection getUsersByName( String name ) - { - Collection users = userStore.getAll(); - Collection result = new HashSet(); - - for(User user : users) - { - if(user.getName().toUpperCase().contains( name.toUpperCase() )) - { - result.add( user ); - } - } - - return result; - } - public Collection getUsersWithoutOrganisationUnitBetween( int first, int max ) { return userCredentialsStore.getUsersWithoutOrganisationUnitBetween( first, max ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-08-21 07:59:21 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-10-06 10:40:16 +0000 @@ -33,6 +33,7 @@ import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.user.User; @@ -59,6 +60,18 @@ return criteria.list(); } + @Override + @SuppressWarnings( "unchecked" ) + public Collection getBetweenByName( String name, int first, int max ) + { + Criteria criteria = getCriteria(); + criteria.add( Restrictions.or( Restrictions.ilike( "surname", "%" + name + "%" ), Restrictions.ilike( "firstName", "%" + name + "%" ) ) ); + criteria.addOrder( Order.asc( "surname" ) ).addOrder( Order.asc( "firstName" ) ); + criteria.setFirstResult( first ); + criteria.setMaxResults( max ); + return criteria.list(); + } + public Collection getUsersWithoutOrganisationUnit() { Collection users = getAll(); === 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-01 14:21:41 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-06 10:40:16 +0000 @@ -255,7 +255,7 @@ } else { - recipients.setUsers( new HashSet( userService.getUsersByName( filter ) ) ); + recipients.setUsers( new HashSet( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) ); recipients.setUserGroups( new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) ); } === modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java' --- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java 2012-09-24 06:28:31 +0000 +++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/message/action/GetMessageRecipientsAction.java 2012-10-06 10:40:16 +0000 @@ -27,8 +27,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_JSON; import com.opensymphony.xwork2.Action; + +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserGroup; import org.hisp.dhis.user.UserGroupService; @@ -44,6 +50,8 @@ public class GetMessageRecipientsAction implements Action { + private static final int MAX_PER_OBJECT = 15; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -54,6 +62,9 @@ @Autowired private UserGroupService userGroupService; + @Autowired + private ContextUtils contextUtils; + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -67,13 +78,13 @@ private Set users = new HashSet(); - private Set userGroups = new HashSet(); - public Set getUsers() { return users; } + private Set userGroups = new HashSet(); + public Set getUserGroups() { return userGroups; @@ -86,17 +97,17 @@ @Override public String execute() throws Exception { - if ( filter == null || filter.isEmpty() ) - { - users = new HashSet( userService.getAllUsers() ); - userGroups = new HashSet( userGroupService.getAllUserGroups() ); - } - else - { - users = new HashSet( userService.getUsersByName( filter ) ); - userGroups = new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ); + filter = StringUtils.trimToNull( filter ); + + if ( filter != null ) + { + users = new HashSet( userService.getAllUsersBetweenByName( filter, 0, MAX_PER_OBJECT ) ); + + userGroups = new HashSet( userGroupService.getUserGroupsBetweenByName( filter, 0, MAX_PER_OBJECT ) ); } + contextUtils.configureResponse( ServletActionContext.getResponse(), CONTENT_TYPE_JSON, CacheStrategy.CACHE_1_HOUR ); + return SUCCESS; } }