dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09121
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2344: Impl method getOrganisationUnitsByGroups
------------------------------------------------------------
revno: 2344
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2010-12-12 08:34:08 +0100
message:
Impl method getOrganisationUnitsByGroups
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.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/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-11-29 13:06:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-12-12 07:34:08 +0000
@@ -232,6 +232,8 @@
*/
Set<Source> convert( Collection<OrganisationUnit> organisationUnits );
+ Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups );
+
/**
* Get the units in tree by the collection of given roots
*
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2010-11-29 13:06:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2010-12-12 07:34:08 +0000
@@ -91,6 +91,8 @@
*/
Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
+ Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups );
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-11-27 09:37:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-12-12 07:34:08 +0000
@@ -169,18 +169,17 @@
return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ConversionUtils.getIdentifiers( Source.class, sources ) ).list();
}
-
+
@SuppressWarnings( "unchecked" )
- public Collection<DataSet> getDataSetsForMobile(Source source) {
- System.out.println("received Source: "+source.getName());
+ public Collection<DataSet> getDataSetsForMobile( Source source )
+ {
String hql = "from DataSet d where :source in elements(d.sources) and d.mobile = true";
Query query = sessionFactory.getCurrentSession().createQuery( hql );
query.setEntity( "source", source );
-
+
return query.list();
-
- }
-
+ }
+
// -------------------------------------------------------------------------
// FrequencyOverrideAssociation
// -------------------------------------------------------------------------
@@ -273,6 +272,5 @@
public Collection<DataSet> getDataSetsBetweenByName( String name, int first, int max )
{
return getBetweenByName( name, first, max );
- }
-
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2010-11-29 13:06:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2010-12-12 07:34:08 +0000
@@ -405,6 +405,11 @@
return organisationUnitStore.getOrganisationUnitsWithoutGroups();
}
+ public Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups )
+ {
+ return organisationUnitStore.getOrganisationUnitsByGroups( groups );
+ }
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2010-11-29 13:06:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2010-12-12 07:34:08 +0000
@@ -28,6 +28,7 @@
*/
import java.util.Collection;
+import java.util.HashSet;
import org.amplecode.quick.StatementHolder;
import org.amplecode.quick.StatementManager;
@@ -37,6 +38,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.organisationunit.OrganisationUnitStore;
@@ -134,6 +136,35 @@
return sessionFactory.getCurrentSession().createQuery( hql ).list();
}
+ @SuppressWarnings( "unchecked" )
+ public Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups )
+ {
+ if ( groups != null && groups.size() > 0 )
+ {
+ StringBuilder hql = new StringBuilder( "from OrganisationUnit o where" );
+
+ for ( int i = 0; i < groups.size(); i++ )
+ {
+ hql.append( " :g" ).append( i ).append( " in elements( o.groups ) and" );
+ }
+
+ hql.delete( hql.length() - 4, hql.length() );
+
+ Query query = sessionFactory.getCurrentSession().createQuery( hql.toString() );
+
+ int i = 0;
+
+ for ( OrganisationUnitGroup group : groups )
+ {
+ query.setEntity( "g" + i++, group );
+ }
+
+ return query.list();
+ }
+
+ return new HashSet<OrganisationUnit>();
+ }
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java 2010-08-27 10:58:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java 2010-12-12 07:34:08 +0000
@@ -32,6 +32,7 @@
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
@@ -355,6 +356,43 @@
assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 3, unitB ), unitD, unitE ) );
assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 4, unitB ), unitH, unitI, unitJ, unitK ) );
}
+ @Test
+ public void testGetOrganisationUnitsByGroups()
+ {
+ OrganisationUnit unitA = createOrganisationUnit( 'A' );
+ OrganisationUnit unitB = createOrganisationUnit( 'B' );
+ OrganisationUnit unitC = createOrganisationUnit( 'C' );
+ organisationUnitService.addOrganisationUnit( unitA );
+ organisationUnitService.addOrganisationUnit( unitB );
+ organisationUnitService.addOrganisationUnit( unitC );
+
+ OrganisationUnitGroup groupA = createOrganisationUnitGroup( 'A' );
+ OrganisationUnitGroup groupB = createOrganisationUnitGroup( 'B' );
+ OrganisationUnitGroup groupC = createOrganisationUnitGroup( 'C' );
+
+ groupA.getMembers().add( unitA );
+ groupA.getMembers().add( unitB );
+ groupA.getMembers().add( unitC );
+ groupB.getMembers().add( unitA );
+ groupB.getMembers().add( unitB );
+ groupC.getMembers().add( unitA );
+
+ organisationUnitGroupService.addOrganisationUnitGroup( groupA );
+ organisationUnitGroupService.addOrganisationUnitGroup( groupB );
+ organisationUnitGroupService.addOrganisationUnitGroup( groupC );
+
+ List<OrganisationUnitGroup> groups = Arrays.asList( groupA );
+ Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByGroups( groups );
+ assertEquals( 3, units.size() );
+
+ groups = Arrays.asList( groupA, groupB );
+ units = organisationUnitService.getOrganisationUnitsByGroups( groups );
+ assertEquals( 2, units.size() );
+
+ groups = Arrays.asList( groupA, groupB, groupC );
+ units = organisationUnitService.getOrganisationUnitsByGroups( groups );
+ assertEquals( 1, units.size() );
+ }
// -------------------------------------------------------------------------
// OrganisationUnitGroup
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java 2010-05-17 21:54:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitStoreTest.java 2010-12-12 07:34:08 +0000
@@ -108,4 +108,4 @@
assertNull( organisationUnitStore.getOrganisationUnitLevel( idA ) );
assertNull( organisationUnitStore.getOrganisationUnitLevel( idB ) );
}
-}
+}
\ No newline at end of file