dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34724
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17802: Re-implemented getUsersWithoutOrganisationUnit using query
------------------------------------------------------------
revno: 17802
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-12-26 17:55:20 +0100
message:
Re-implemented getUsersWithoutOrganisationUnit using query
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.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
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.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 2014-12-26 13:22:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2014-12-26 16:55:20 +0000
@@ -101,6 +101,10 @@
*/
Collection<User> getUsersWithoutOrganisationUnit();
+ int getUsersWithoutOrganisationUnitCount();
+
+ int getUsersWithoutOrganisationUnitCountByName( String name );
+
/**
* Returns a Collection of Users which are having given Phone number.
*
@@ -120,10 +124,6 @@
int getUserCountByName( String name );
- int getUsersWithoutOrganisationUnitCount();
-
- int getUsersWithoutOrganisationUnitCountByName( String name );
-
int getUsersByOrganisationUnitCount( OrganisationUnit orgUnit );
int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
=== 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-26 12:27:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2014-12-26 16:55:20 +0000
@@ -29,7 +29,6 @@
*/
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
@@ -77,21 +76,12 @@
}
@Override
+ @SuppressWarnings("unchecked")
public List<User> getUsersWithoutOrganisationUnit()
{
- List<User> users = getAll();
-
- Iterator<User> iterator = users.iterator();
-
- while ( iterator.hasNext() )
- {
- if ( iterator.next().getOrganisationUnits().size() > 0 )
- {
- iterator.remove();
- }
- }
-
- return users;
+ String hql = "from User u where u.organisationUnits.size = 0";
+
+ return sessionFactory.getCurrentSession().createQuery( hql ).list();
}
@Override
=== 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 2014-12-25 10:43:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserStoreTest.java 2014-12-26 16:55:20 +0000
@@ -31,7 +31,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -146,4 +148,30 @@
assertEquals( credentialsA, userCredentialsStore.getUserCredentials( idA ) );
assertEquals( credentialsB, userCredentialsStore.getUserCredentials( idB ) );
}
+
+ @Test
+ public void testGetUsersWithoutOrganisationUnit()
+ {
+ User userA = createUser( 'A' );
+ User userB = createUser( 'B' );
+ User userC = createUser( 'C' );
+ User userD = createUser( 'D' );
+
+ userA.getOrganisationUnits().add( unit1 );
+ userA.getOrganisationUnits().add( unit2 );
+
+ userC.getOrganisationUnits().add( unit1 );
+ userC.getOrganisationUnits().add( unit2 );
+
+ userStore.save( userA );
+ userStore.save( userB );
+ userStore.save( userC );
+ userStore.save( userD );
+
+ Collection<User> users = userStore.getUsersWithoutOrganisationUnit();
+
+ assertEquals( 2, users.size() );
+ assertTrue( users.contains( userB ) );
+ assertTrue( users.contains( userD ) );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java 2014-12-23 18:03:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/ShowAddProgramFormAction.java 2014-12-26 16:55:20 +0000
@@ -36,7 +36,6 @@
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.relationship.RelationshipType;
import org.hisp.dhis.relationship.RelationshipTypeService;
-import org.hisp.dhis.system.util.AttributeUtils;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;