← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3465: Replaced ineffective store method

 

------------------------------------------------------------
revno: 3465
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-04-24 15:44:20 +0200
message:
  Replaced ineffective store method
modified:
  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/HibernateUserStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.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-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<User> getAllUsers();
 
     /**
-     * Returns a Collection of the Users associated with the given
-     * OrganisationUnit.
-     * 
-     * @param organisationUnit the OrganisationUnit.
-     * @return a Collection of Users.
-     */
-    Collection<User> 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<User> getAllUsers();
 
     /**
-     * Returns a Collection of the Users associated with the given
-     * OrganisationUnit.
-     * 
-     * @param organisationUnit the OrganisationUnit.
-     * @return a Collection of Users.
-     */
-    Collection<User> 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<User> getUsersByOrganisationUnit( OrganisationUnit unit )
-    {
-        return userStore.getUsersByOrganisationUnit( unit );
-    }
-
     public Collection<UserCredentials> 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<User> getUsersByOrganisationUnit( OrganisationUnit organisationUnit )
-    {   
-        Collection<User> users = getAllUsers();
-        
-        Iterator<User> iterator = users.iterator();
-        
-        while( iterator.hasNext() )
-        {
-            if( ! iterator.next().getOrganisationUnits().contains( organisationUnit ) )
-            {
-        	iterator.remove();
-            }
-        }
-        
-        return users;
-    }
-
     public Collection<User> getUsersWithoutOrganisationUnit()
     {    	
     	Collection<User> users = getAllUsers();
@@ -403,23 +386,23 @@
 
     public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max )
     {
-        return getBlockUser( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), first, max );
+        return getBlockUser( toUserCredentials( orgUnit.getUsers() ), first, max );
     }
 
     public Collection<UserCredentials> 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<UserCredentials> 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<UserCredentials> findByName( Collection<UserCredentials> users, String key )
     {
         List<UserCredentials> returnList = new ArrayList<UserCredentials>();
@@ -480,12 +465,13 @@
     
     private List<UserCredentials> toUserCredentials( Collection<User> users )
     {
-        List<UserCredentials> returnUserCredentials = new ArrayList<UserCredentials>();
+        List<UserCredentials> credentials = new ArrayList<UserCredentials>();
 
         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