=== 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 2010-12-30 09:13:41 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-04-24 13:44:20 +0000 @@ -82,15 +82,6 @@ Collection getAllUsers(); /** - * Returns a Collection of the Users associated with the given - * OrganisationUnit. - * - * @param organisationUnit the OrganisationUnit. - * @return a Collection of Users. - */ - Collection getUsersByOrganisationUnit( OrganisationUnit organisationUnit ); - - /** * Returns a Collection of the Users which are not associated with any * OrganisationUnits. * === 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 2010-12-30 09:13:41 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2011-04-24 13:44:20 +0000 @@ -74,15 +74,6 @@ Collection getAllUsers(); /** - * Returns a Collection of the Users associated with the given - * OrganisationUnit. - * - * @param organisationUnit the OrganisationUnit. - * @return a Collection of Users. - */ - Collection getUsersByOrganisationUnit( OrganisationUnit organisationUnit ); - - /** * Returns a Collection of the Users which are not associated with any * OrganisationUnits. * === 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 2011-04-19 14:37:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-04-24 13:44:20 +0000 @@ -177,11 +177,6 @@ return userStore.getUserCountByName( userName ); } - public Collection getUsersByOrganisationUnit( OrganisationUnit unit ) - { - return userStore.getUsersByOrganisationUnit( unit ); - } - public Collection getUsersByOrganisationUnitBetween( OrganisationUnit unit, int first, int max ) { return userStore.getUsersByOrganisationUnitBetween( unit, 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 2011-04-19 14:37:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-04-24 13:44:20 +0000 @@ -112,23 +112,6 @@ return session.createQuery( "from User" ).list(); } - public Collection getUsersByOrganisationUnit( OrganisationUnit organisationUnit ) - { - Collection users = getAllUsers(); - - Iterator iterator = users.iterator(); - - while( iterator.hasNext() ) - { - if( ! iterator.next().getOrganisationUnits().contains( organisationUnit ) ) - { - iterator.remove(); - } - } - - return users; - } - public Collection getUsersWithoutOrganisationUnit() { Collection users = getAllUsers(); @@ -403,23 +386,23 @@ public Collection getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max ) { - return getBlockUser( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), first, max ); + return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max ); } public Collection getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name, int first, int max ) { - return getBlockUser( findByName( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), name ), first, max ); + return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max ); } public int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit ) { - return getUsersByOrganisationUnit( orgUnit ).size(); + return orgUnit.getUsers().size(); } public int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name ) { - return findByName( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), name ).size(); + return findByName( toUserCredentials( orgUnit.getUsers() ), name ).size(); } public Collection getUsersWithoutOrganisationUnitBetween( int first, int max ) @@ -446,6 +429,8 @@ // Supportive methods // ------------------------------------------------------------------------- + // TODO All this user / credentials search stuff is horrible and must be improved + private Collection findByName( Collection users, String key ) { List returnList = new ArrayList(); @@ -480,12 +465,13 @@ private List toUserCredentials( Collection users ) { - List returnUserCredentials = new ArrayList(); + List credentials = new ArrayList(); for ( User user : users ) { - returnUserCredentials.add( getUserCredentials( user ) ); + credentials.add( getUserCredentials( user ) ); } - return returnUserCredentials; + + return credentials; } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java 2011-03-31 16:28:24 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java 2011-04-24 13:44:20 +0000 @@ -87,8 +87,6 @@ assertEquals( userStore.getUser( id ).getSurname(), userName ); assertEquals( userStore.getUser( id ).getFirstName(), userName ); assertEquals( 1, userStore.getAllUsers().size(), 1 ); - assertEquals( 0, userStore.getUsersByOrganisationUnit( unit1 ).size() ); - assertEquals( 0, userStore.getUsersByOrganisationUnit( unit2 ).size() ); assertEquals( 1, userStore.getUsersWithoutOrganisationUnit().size() ); // Test updateUser @@ -97,8 +95,6 @@ userStore.updateUser( user ); assertEquals( userStore.getUser( id ).getSurname(), "User1" ); - assertEquals( 1, userStore.getUsersByOrganisationUnit( unit1 ).size() ); - assertEquals( 1, userStore.getUsersByOrganisationUnit( unit2 ).size() ); assertEquals( 0, userStore.getUsersWithoutOrganisationUnit().size() ); // Test getUser @@ -119,8 +115,6 @@ assertEquals( userStore.getAllUsers().size(), 2 ); - assertEquals( 1, userStore.getUsersByOrganisationUnit( unit1 ).size() ); - assertEquals( 2, userStore.getUsersByOrganisationUnit( unit2 ).size() ); assertEquals( 0, userStore.getUsersWithoutOrganisationUnit().size() ); // Test deleteUser