← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17810: Using the new user solution in user module and web api. Remvoed obsolete methods.

 

------------------------------------------------------------
revno: 17810
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-12-28 15:15:49 +0100
message:
  Using the new user solution in user module and web api. Remvoed obsolete methods.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java
  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/hibernate/HibernateUserCredentialsStore.java
  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/test/java/org/hisp/dhis/user/UserCredentialsStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetOrgunitUserListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm


--
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-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	2014-12-27 11:19:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentialsStore.java	2014-12-28 14:15:49 +0000
@@ -28,11 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-
 import java.util.Collection;
 import java.util.Date;
-import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -101,8 +98,6 @@
 
     UserCredentials getUserCredentialsByOpenID( String openId );
     
-    List<UserCredentials> getUserCredentialsWithLessAuthorities( UserCredentials userCredentials );
-    
     Collection<UserCredentials> searchUsersByName( String key );
 
     Collection<UserCredentials> searchUsersByName( String key, int first, int max );
@@ -111,11 +106,6 @@
 
     Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max );
 
-    Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max );
-
-    Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
-        int first, int max );
-
     Collection<UserCredentials> getSelfRegisteredUserCredentials( int first, int max );
 
     int getSelfRegisteredUserCredentialsCount();
@@ -132,9 +122,5 @@
 
     int getUserCountByName( String name );
 
-    int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
-
-    int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
-
     Collection<String> getUsernames( String key, Integer max );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java	2014-12-28 14:15:49 +0000
@@ -37,7 +37,7 @@
  */
 public class UserQueryParams
 {
-    private String searchKey;
+    private String query;
     
     private User user;
     
@@ -76,14 +76,14 @@
     // Getters and setters
     // -------------------------------------------------------------------------
 
-    public String getSearchKey()
+    public String getQuery()
     {
-        return searchKey;
+        return query;
     }
 
-    public void setSearchKey( String searchKey )
+    public void setQuery( String query )
     {
-        this.searchKey = searchKey;
+        this.query = query;
     }
 
     public User getUser()

=== 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	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2014-12-28 14:15:49 +0000
@@ -36,7 +36,6 @@
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 
 /**
  * @author Chau Thu Tran
@@ -112,10 +111,6 @@
 
     int getUserCountByName( String name );
 
-    int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
-
-    int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
-
     List<User> getUsersByUid( List<String> uids );
 
     User searchForUser( String query );
@@ -168,7 +163,7 @@
      * @param user the user.
      * @return number of users.
      */
-    long getManagedUserCount( User user );
+    int getManagedUserCount( User user );
 
     /**
      * Returns a list of users based on the given query parameters.
@@ -184,7 +179,7 @@
      * @param params the user query parameters.
      * @return number of users.
      */
-    long getUserCount( UserQueryParams params );
+    int getUserCount( UserQueryParams params );
     
     /**
      * Tests whether the current user is allowed to create a user associated
@@ -292,10 +287,6 @@
 
     Collection<UserCredentials> getUsersBetweenByName( String name, int first, int max );
 
-    Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max );
-
-    Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name, int first, int max );
-
     Collection<UserCredentials> getSelfRegisteredUserCredentials( int first, int max );
 
     int getSelfRegisteredUserCredentialsCount();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java	2014-12-28 14:15:49 +0000
@@ -72,5 +72,5 @@
      * @param params the user query parameters.
      * @return number of users.
      */
-    long getUserCount( UserQueryParams params );
+    int getUserCount( UserQueryParams params );
 }

=== 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	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2014-12-28 14:15:49 +0000
@@ -48,7 +48,6 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.security.migration.MigrationPasswordManager;
 import org.hisp.dhis.setting.SystemSettingManager;
@@ -214,7 +213,7 @@
     }
 
     @Override
-    public long getManagedUserCount( User user )
+    public int getManagedUserCount( User user )
     {
         UserQueryParams params = new UserQueryParams( user );
         params.setCanManage( true );
@@ -231,7 +230,7 @@
     }
 
     @Override
-    public long getUserCount( UserQueryParams params )
+    public int getUserCount( UserQueryParams params )
     {
         handleUserQueryParams( params );
         return userStore.getUserCount( params );
@@ -239,45 +238,29 @@
     
     private void handleUserQueryParams( UserQueryParams params )
     {
+        boolean disjointRoles = (Boolean) systemSettingManager.getSystemSetting( KEY_CAN_GRANT_OWN_USER_AUTHORITY_GROUPS, false );
+        params.setDisjointRoles( disjointRoles );
+        
+        if ( params.getUser() == null )
+        {
+            params.setUser( currentUserService.getCurrentUser() );
+        }
+        
+        if ( params.getUser() != null && params.getUser().isSuper() )
+        {
+            params.setCanManage( false );
+            params.setAuthSubset( false );
+        }
+
         if ( params.getInactiveMonths() != null )
         {
             Calendar cal = PeriodType.createCalendarInstance();
             cal.add( Calendar.MONTH, ( params.getInactiveMonths() * -1 ) );
             params.setInactiveSince( cal.getTime() );
         }
-        
-        if ( params.getUser() != null && params.getUser().isSuper() )
-        {
-            params.setCanManage( false );
-            params.setAuthSubset( false );
-        }
     }
     
     @Override
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit unit, int first, int max )
-    {
-        return userCredentialsStore.getUsersByOrganisationUnitBetween( unit, first, max );
-    }
-
-    @Override
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit unit, String userName, int first, int max )
-    {
-        return userCredentialsStore.getUsersByOrganisationUnitBetweenByName( unit, userName, first, max );
-    }
-
-    @Override
-    public int getUsersByOrganisationUnitCount( OrganisationUnit unit )
-    {
-        return userCredentialsStore.getUsersByOrganisationUnitCount( unit );
-    }
-
-    @Override
-    public int getUsersByOrganisationUnitCountByName( OrganisationUnit unit, String userName )
-    {
-        return userCredentialsStore.getUsersByOrganisationUnitCountByName( unit, userName );
-    }
-
-    @Override
     public Collection<User> getUsersByPhoneNumber( String phoneNumber )
     {
         return userStore.getUsersByPhoneNumber( phoneNumber );
@@ -367,12 +350,6 @@
     }
 
     @Override
-    public int countDataSetUserAuthorityGroups( DataSet dataSet )
-    {
-        return userAuthorityGroupStore.countDataSetUserAuthorityGroups( dataSet );
-    }
-    
-    @Override
     public boolean isSuperUser( UserCredentials userCredentials )
     {
         if ( userCredentials == null )
@@ -552,6 +529,12 @@
     }
 
     @Override
+    public int countDataSetUserAuthorityGroups( DataSet dataSet )
+    {
+        return userAuthorityGroupStore.countDataSetUserAuthorityGroups( dataSet );
+    }
+    
+    @Override
     public void assignDataSetToUserRole( DataSet dataSet )
     {
         User currentUser = currentUserService.getCurrentUser();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2014-12-27 11:19:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserCredentialsStore.java	2014-12-28 14:15:49 +0000
@@ -28,11 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.List;
-import java.util.Set;
 
 import org.hibernate.Criteria;
 import org.hibernate.Query;
@@ -42,7 +39,6 @@
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserCredentialsStore;
@@ -126,25 +122,6 @@
 
         return (UserCredentials) query.uniqueResult();
     }
-
-    @SuppressWarnings("unchecked")
-    public List<UserCredentials> getUserCredentialsWithLessAuthorities( UserCredentials userCredentials )
-    {
-        Session session = sessionFactory.getCurrentSession();
-        
-        Set<String> auths = userCredentials.getAllAuthorities();
-        
-        String hql = 
-            "select uc from UserCredentials uc " +
-            "where not exists (" +
-                "select uc2 from UserCredentials uc2 " +
-                "inner join uc2.userAuthorityGroups ag " +
-                "inner join ag.authorities a " +
-                "where uc2.id = uc.id " +
-                "and a not in (:auths) )";
-        
-        return session.createQuery( hql ).setParameterList( "auths", auths ).list();
-    }
     
     @Override
     @SuppressWarnings("unchecked")
@@ -261,31 +238,6 @@
     }
 
     @Override
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max )
-    {
-        return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max );
-    }
-
-    @Override
-    public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
-        int first, int max )
-    {
-        return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max );
-    }
-
-    @Override
-    public int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit )
-    {
-        return orgUnit.getUsers().size();
-    }
-
-    @Override
-    public int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name )
-    {
-        return findByName( toUserCredentials( orgUnit.getUsers() ), name ).size();
-    }
-
-    @Override
     @SuppressWarnings("unchecked")
     public Collection<UserCredentials> getSelfRegisteredUserCredentials( int first, int max )
     {
@@ -378,47 +330,4 @@
 
         return query.list();
     }
-    
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Collection<UserCredentials> findByName( Collection<UserCredentials> users, String key )
-    {
-        List<UserCredentials> returnList = new ArrayList<>();
-
-        for ( UserCredentials user : users )
-        {
-            if ( user != null )
-            {
-                if ( user.getUsername().toLowerCase().contains( key.toLowerCase() ) )
-                {
-                    returnList.add( user );
-                }
-            }
-        }
-
-        return returnList;
-    }
-
-    private List<UserCredentials> getBlockUser( Collection<UserCredentials> usersList, int startPos, int pageSize )
-    {
-        List<UserCredentials> elementList = new ArrayList<>( usersList );
-
-        int toIndex = Math.min( startPos + pageSize, elementList.size() );
-
-        return elementList.subList( startPos, toIndex );
-    }
-
-    private List<UserCredentials> toUserCredentials( Collection<User> users )
-    {
-        List<UserCredentials> credentials = new ArrayList<>();
-
-        for ( User user : users )
-        {
-            credentials.add( user.getUserCredentials() );
-        }
-
-        return credentials;
-    }
 }

=== 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	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2014-12-28 14:15:49 +0000
@@ -110,9 +110,10 @@
     }
 
     @Override
-    public long getUserCount( UserQueryParams params )
+    public int getUserCount( UserQueryParams params )
     {
-        return (Long) getUserQuery( params, true ).uniqueResult();
+        Long count = (Long) getUserQuery( params, true ).uniqueResult();
+        return count != null ? count.intValue() : 0;
     }
 
     private Query getUserQuery( UserQueryParams params, boolean count )
@@ -126,10 +127,12 @@
             "inner join u.userCredentials uc " +
             "left join u.groups g ";
 
-        if ( params.getSearchKey() != null )
+        if ( params.getQuery() != null )
         {
             hql += hlp.whereAnd() + " (" +
                 "lower(u.firstName) like :key " +
+                "or lower(u.email) like :key " +
+                "or lower(u.phoneNumber) like :key " +
                 "or lower(u.surname) like :key " +
                 "or lower(uc.username) like :key) ";
         }
@@ -180,9 +183,9 @@
         
         Query query = sessionFactory.getCurrentSession().createQuery( hql );
         
-        if ( params.getSearchKey() != null )
+        if ( params.getQuery() != null )
         {
-            query.setString( "key", "%" + params.getSearchKey().toLowerCase() + "%" );
+            query.setString( "key", "%" + params.getQuery().toLowerCase() + "%" );
         }
         
         if ( params.isCanManage() && params.getUser() != null )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserCredentialsStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserCredentialsStoreTest.java	2014-12-26 18:56:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserCredentialsStoreTest.java	2014-12-28 14:15:49 +0000
@@ -29,9 +29,6 @@
  */
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.junit.Test;
@@ -91,54 +88,4 @@
         assertEquals( credentialsA, userCredentialsStore.getUserCredentials( idA ) );
         assertEquals( credentialsB, userCredentialsStore.getUserCredentials( idB ) );
     }
-    
-    @Test
-    public void testGetUserCredentialsWithLessAuthorities()
-    {
-        User userA = createUser( 'A' );
-        User userB = createUser( 'B' );
-        User userC = createUser( 'C' );
-        User userD = createUser( 'D' );
-        
-        UserCredentials credentialsA = createUserCredentials( 'A', userA );
-        UserCredentials credentialsB = createUserCredentials( 'B', userB );
-        UserCredentials credentialsC = createUserCredentials( 'C', userC );
-        UserCredentials credentialsD = createUserCredentials( 'D', userD );
-        
-        credentialsA.getUserAuthorityGroups().add( roleA );
-        credentialsB.getUserAuthorityGroups().add( roleB );
-        credentialsB.getUserAuthorityGroups().add( roleC );
-        credentialsC.getUserAuthorityGroups().add( roleB );
-        credentialsD.getUserAuthorityGroups().add( roleC );
-        
-        userCredentialsStore.addUserCredentials( credentialsA );
-        userCredentialsStore.addUserCredentials( credentialsB );
-        userCredentialsStore.addUserCredentials( credentialsC );
-        userCredentialsStore.addUserCredentials( credentialsD );
-        
-        List<UserCredentials> userCredentials = userCredentialsStore.getUserCredentialsWithLessAuthorities( credentialsA );
-                
-        assertEquals( 4, userCredentials.size() );
-        assertTrue( userCredentials.contains( credentialsA ) );
-        assertTrue( userCredentials.contains( credentialsB ) );
-        assertTrue( userCredentials.contains( credentialsC ) );
-        assertTrue( userCredentials.contains( credentialsD ) );
-        
-        userCredentials = userCredentialsStore.getUserCredentialsWithLessAuthorities( credentialsB );
-        
-        assertEquals( 3, userCredentials.size() );
-        assertTrue( userCredentials.contains( credentialsB ) );
-        assertTrue( userCredentials.contains( credentialsC ) );
-        assertTrue( userCredentials.contains( credentialsD ) );
-        
-        userCredentials = userCredentialsStore.getUserCredentialsWithLessAuthorities( credentialsC );
-        
-        assertEquals( 1, userCredentials.size() );
-        assertTrue( userCredentials.contains( credentialsC ) );
-
-        userCredentials = userCredentialsStore.getUserCredentialsWithLessAuthorities( credentialsD );
-        
-        assertEquals( 1, userCredentials.size() );
-        assertTrue( userCredentials.contains( credentialsD ) );
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	2014-12-28 14:15:49 +0000
@@ -33,6 +33,7 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_CAN_GRANT_OWN_USER_AUTHORITY_GROUPS;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -41,6 +42,7 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.setting.SystemSettingManager;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -61,6 +63,9 @@
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
+    @Autowired
+    private SystemSettingManager systemSettingManager;
+    
     private OrganisationUnit unit1;
     private OrganisationUnit unit2;
 
@@ -387,6 +392,8 @@
     @Test
     public void testGetManagedGroupsLessAuthoritiesDisjointRoles()
     {
+        systemSettingManager.saveSystemSetting( KEY_CAN_GRANT_OWN_USER_AUTHORITY_GROUPS, true );
+        
         User userA = createUser( 'A' );
         User userB = createUser( 'B' );
         User userC = createUser( 'C' );
@@ -443,7 +450,6 @@
         UserQueryParams params = new UserQueryParams();
         params.setCanManage( true );
         params.setAuthSubset( true );
-        params.setDisjointRoles( true );
         params.setUser( userA );
         
         Collection<User> users = userService.getUsers( params );
@@ -503,7 +509,7 @@
         userService.addUserCredentials( credentialsF );
 
         UserQueryParams params = new UserQueryParams();
-        params.setSearchKey( "rstnameA" );
+        params.setQuery( "rstnameA" );
         
         Collection<User> users = userService.getUsers( params );
         

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java	2014-12-28 14:15:49 +0000
@@ -151,7 +151,7 @@
     }
 
     //--------------------------------------------------------------------------
-    // Get options for classes/strings etc
+    // Object helpers
     //--------------------------------------------------------------------------
 
     /**
@@ -174,6 +174,10 @@
         return !isEnabled( type );
     }
 
+    //--------------------------------------------------------------------------
+    // Options helpers
+    //--------------------------------------------------------------------------
+
     public Date getDate( String key )
     {
         return stringAsDate( options.get( key ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-12-28 11:48:55 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-12-28 14:15:49 +0000
@@ -31,7 +31,6 @@
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -43,6 +42,7 @@
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
 import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.schema.descriptors.UserSchemaDescriptor;
 import org.hisp.dhis.security.RestoreOptions;
 import org.hisp.dhis.security.SecurityService;
@@ -95,6 +95,9 @@
     @Autowired
     private SystemSettingManager systemSettingManager;
     
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+    
     // -------------------------------------------------------------------------
     // GET
     // -------------------------------------------------------------------------
@@ -102,49 +105,39 @@
     @Override
     protected List<User> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters )
     {
-        User user = currentUserService.getCurrentUser();
-        
-        List<User> entityList;
-
-        if ( options.getOptions().containsKey( "query" ) )
-        {
-            entityList = Lists.newArrayList( manager.filter( getEntityClass(), options.getOptions().get( "query" ) ) );
-        }
-        else if ( options.hasPaging() )
-        {
-            int count = userService.getUserCount();
-
-            Pager pager = new Pager( options.getPage(), count );
+        UserQueryParams params = new UserQueryParams();
+        params.setQuery( options.get( "query" ) );
+        params.setCanManage( options.isTrue( "canManage" ) );
+        params.setAuthSubset( options.isTrue( "authSubset" ) );
+        params.setInactiveMonths( options.getInt( "inactiveMonths" ) );
+        params.setSelfRegistered( options.isTrue( "selfRegistered" ) );
+        params.setFirst( options.getInt( "first" ) );
+        params.setMax( options.getInt( "max" ) );
+        
+        String ou = options.get( "ou" );
+        
+        if ( ou != null )
+        {
+            params.setOrganisationUnit( organisationUnitService.getOrganisationUnit( ou ) );    
+        }
+        
+        if ( options.isManage() )
+        {
+            params.setCanManage( true );
+            params.setAuthSubset( true );
+        }
+        
+        int count = userService.getUserCount( params );
+        
+        if ( options.hasPaging() )
+        {
+            Pager pager = new Pager( options.getPage(), count, options.getPageSize() );
             metaData.setPager( pager );
-
-            if ( options.isManage() )
-            {
-                UserQueryParams params = new UserQueryParams( user );
-                params.setCanManage( true );
-                params.setAuthSubset( true );
-                params.setFirst( pager.getOffset() );
-                params.setMax( pager.getPageSize() );
-                
-                entityList = userService.getUsers( params );
-            }
-            else
-            {
-                entityList = new ArrayList<>( userService.getAllUsersBetween( pager.getOffset(), pager.getPageSize() ) );
-            }
-        }
-        else
-        {
-            if ( options.isManage() )
-            {
-                entityList = new ArrayList<>( userService.getManagedUsers( user ) );
-            }
-            else
-            {
-                entityList = new ArrayList<>( userService.getAllUsers() );
-            }
-        }
-
-        return entityList;
+            params.setFirst( pager.getOffset() );
+            params.setMax( pager.getPageSize() );
+        }
+        
+        return userService.getUsers( params );
     }
 
     @Override

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetOrgunitUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetOrgunitUserListAction.java	2014-12-27 11:19:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetOrgunitUserListAction.java	2014-12-28 14:15:49 +0000
@@ -28,23 +28,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.apache.commons.lang.StringUtils.isNotBlank;
-
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserService;
-import org.hisp.dhis.user.comparator.UsernameComparator;
 
 /**
  * @author Torgeir Lorange Ostby
- * @version $Id: GetOrgunitUserListAction.java 5549 2008-08-20 05:23:35Z abyot $
  */
 public class GetOrgunitUserListAction
     extends ActionPagingSupport<User>
@@ -71,11 +66,11 @@
     // Output
     // -------------------------------------------------------------------------
 
-    private List<UserCredentials> userCredentialsList;
+    private List<User> users = new ArrayList<>();
 
-    public List<UserCredentials> getUserCredentialsList()
+    public List<User> getUsers()
     {
-        return userCredentialsList;
+        return users;
     }
 
     private String key;
@@ -99,24 +94,20 @@
         throws Exception
     {
         OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
-
-        if ( isNotBlank( key ) ) // Filter on key only if set
-        {
-            this.paging = createPaging( userService.getUsersByOrganisationUnitCountByName( organisationUnit, key ) );
-                
-            userCredentialsList = new ArrayList<>( userService.getUsersByOrganisationUnitBetweenByName( organisationUnit, key, paging.getStartPos(), paging.getPageSize() ) );
-        }
-        else
-        {
-            this.paging = createPaging( userService.getUsersByOrganisationUnitCount( organisationUnit ) );
-                
-            userCredentialsList = new ArrayList<>( userService.getUsersByOrganisationUnitBetween( organisationUnit, paging.getStartPos(), paging.getPageSize() ) );
-        }
-        
-        userService.canUpdateUserCredentialsFilter( userCredentialsList );
-        
-        Collections.sort( userCredentialsList, new UsernameComparator() );
-
+        
+        UserQueryParams params = new UserQueryParams();
+        
+        params.setQuery( key );
+        params.setOrganisationUnit( organisationUnit );
+
+        int count = userService.getUserCount( params );
+        
+        this.paging = createPaging( count );        
+        params.setFirst( paging.getStartPos() );
+        params.setMax( paging.getPageSize() );
+        
+        users = userService.getUsers( params );
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java	2014-12-26 13:22:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java	2014-12-28 14:15:49 +0000
@@ -28,21 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.apache.commons.lang.StringUtils.isNotBlank;
-
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserService;
-import org.hisp.dhis.user.comparator.UsernameComparator;
 
 /**
  * @author Torgeir Lorange Ostby
- * @version $Id: GetUserListAction.java 2869 2007-02-20 14:26:09Z andegje $
  */
 public class GetUserListAction
     extends ActionPagingSupport<User>
@@ -62,11 +57,11 @@
     // Input & Output
     // -------------------------------------------------------------------------
 
-    private List<UserCredentials> userCredentialsList;
+    private List<User> users = new ArrayList<>();
 
-    public List<UserCredentials> getUserCredentialsList()
+    public List<User> getUsers()
     {
-        return userCredentialsList;
+        return users;
     }
 
     private String key;
@@ -93,14 +88,14 @@
         this.months = months;
     }
 
-    private Boolean selfRegistered;
+    private boolean selfRegistered;
 
-    public Boolean getSelfRegistered()
+    public boolean getSelfRegistered()
     {
         return selfRegistered;
     }
 
-    public void setSelfRegistered( Boolean selfRegistered )
+    public void setSelfRegistered( boolean selfRegistered )
     {
         this.selfRegistered = selfRegistered;
     }
@@ -113,41 +108,20 @@
     public String execute()
         throws Exception
     {
-        if ( isNotBlank( key ) ) // Filter on key only if set
-        {
-            this.paging = createPaging( userService.getUserCountByName( key ) );
-
-            userCredentialsList = new ArrayList<>( userService.searchUsersByName( key, paging.getStartPos(),
-                paging.getPageSize() ) );
-
-            Collections.sort( userCredentialsList, new UsernameComparator() );
-        }
-        else if ( months != null && months != 0 )
-        {
-            this.paging = createPaging( userService.getInactiveUsersCount( months ) );
-
-            userCredentialsList = new ArrayList<>( userService.getInactiveUsers( months, paging
-                .getStartPos(), paging.getPageSize() ) );
-        }
-        else if ( Boolean.TRUE.equals( selfRegistered ) )
-        {
-            this.paging = createPaging( userService.getSelfRegisteredUserCredentialsCount() );
-
-            userCredentialsList = new ArrayList<>( userService.getSelfRegisteredUserCredentials( paging.
-                getStartPos(), paging.getPageSize() ) );
-        }
-        else
-        {
-            this.paging = createPaging( userService.getUserCount() );
-
-            userCredentialsList = new ArrayList<>( userService.getUsersBetween( paging.getStartPos(),
-                paging.getPageSize() ) );
-
-            Collections.sort( userCredentialsList, new UsernameComparator() );
-        }
-
-        userService.canUpdateUserCredentialsFilter( userCredentialsList );
-
+        UserQueryParams params = new UserQueryParams();
+        
+        params.setQuery( key );
+        params.setInactiveMonths( months );
+        params.setSelfRegistered( selfRegistered );
+        
+        int count = userService.getUserCount( params );
+        
+        this.paging = createPaging( count );        
+        params.setFirst( paging.getStartPos() );
+        params.setMax( paging.getPageSize() );
+        
+        users = userService.getUsers( params );
+        
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm	2014-06-13 08:08:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm	2014-12-28 14:15:49 +0000
@@ -53,22 +53,22 @@
 			<table class="listTable" id="userList" width='100%'>
 				<thead>
 				<tr>
+					<th>$i18n.getString( "name" )</th>
 					<th>$i18n.getString( "username" )</th>
-					<th>$i18n.getString( "name" )</th>
 				</tr>
 				</thead>
 				<tbody id="list">
-				#foreach( $userCredentials in $userCredentialsList )
-				<tr id="tr${userCredentials.id}" data-id="$!userCredentials.id" data-uid="$!userCredentials.uid" data-type="UserCredentials"
-                    data-name="$encoder.htmlEncode( $!userCredentials.displayName )"
-                    data-username="$encoder.htmlEncode( $!userCredentials.username )"
-				    data-can-manage="$security.canManage( $userCredentials )"
-				    data-can-update="$security.canUpdate( $userCredentials )"
-				    data-can-delete="$security.canDelete( $userCredentials )"
-                    data-user-enabled="#if( !$userCredentials.disabled )true#{else}false#end"
-                    data-user-disabled="$userCredentials.disabled">
-				    <td>$encoder.htmlEncode( $!userCredentials.username )</td>
-				    <td>$encoder.htmlEncode( $!userCredentials.displayName )</td>
+				#foreach( $user in $users )
+				<tr id="tr${user.id}" data-id="$!user.id" data-uid="$!user.uid" data-type="UserCredentials"
+                    data-name="$encoder.htmlEncode( $!user.displayName )"
+                    data-username="$encoder.htmlEncode( $!user.userCredentials.username )"
+				    data-can-manage="$security.canManage( $user.userCredentials )"
+				    data-can-update="$security.canUpdate( $user.userCredentials )"
+				    data-can-delete="$security.canDelete( $user.userCredentials )"
+                    data-user-enabled="#if( !$user.userCredentials.disabled )true#{else}false#end"
+                    data-user-disabled="$user.userCredentials.disabled">
+				    <td>$encoder.htmlEncode( $!user.surname ), $encoder.htmlEncode( $!user.firstName )</td>
+				    <td>$encoder.htmlEncode( $!user.userCredentials.username )</td>
                 </tr>
 				#end
 				</tbody>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm	2014-06-13 08:08:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm	2014-12-28 14:15:49 +0000
@@ -35,18 +35,18 @@
 			<table class="listTable" id="userList" width='100%'>
 				<thead>
 				<tr>
+					<th>$i18n.getString( "name" )</th>
 					<th>$i18n.getString( "username" )</th>
-					<th>$i18n.getString( "name" )</th>
 				</tr>
 				</thead>
 				<tbody id="list">
-				#foreach( $userCredentials in $userCredentialsList )
-				<tr id="tr${userCredentials.id}" data-id="$!userCredentials.id" data-uid="$!userCredentials.uid" data-type="UserCredentials" data-name="$encoder.htmlEncode( $!userCredentials.displayName )"
-				    data-can-manage="$security.canManage( $userCredentials )"
-				    data-can-update="$security.canUpdate( $userCredentials )"
-				    data-can-delete="#if( $currentUsername != $userCredentials.username )true#{else}false#end">
-				    <td>$encoder.htmlEncode( $!userCredentials.username )</td>
-				    <td>$encoder.htmlEncode( $!userCredentials.displayName )</td>
+				#foreach( $user in $users )
+				<tr id="tr${user.id}" data-id="$!user.id" data-uid="$!user.uid" data-type="UserCredentials" data-name="$encoder.htmlEncode( $!user.displayName )"
+				    data-can-manage="$security.canManage( $user.userCredentials )"
+				    data-can-update="$security.canUpdate( $user.userCredentials )"
+				    data-can-delete="#if( $currentUsername != $user.userCredentials.username )true#{else}false#end">
+				    <td>$encoder.htmlEncode( $!user.surname ), $encoder.htmlEncode( $!user.firstName )</td>
+				    <td>$encoder.htmlEncode( $!user.userCredentials.username )</td>
 				</tr>
 				#end
 				</tbody>