← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2345: Work in progress

 

------------------------------------------------------------
revno: 2345
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2010-12-12 14:35:21 +0100
message:
  Work in progress
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  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/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


--
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/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-11-23 14:22:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-12-12 13:35:21 +0000
@@ -263,6 +263,29 @@
     {
         return coordinates != null && !coordinates.isEmpty() ? coordinates : "[]";
     }
+    
+    public OrganisationUnitGroup getGroupInGroupSet( OrganisationUnitGroupSet groupSet )
+    {
+        if ( groupSet != null )
+        {
+            for ( OrganisationUnitGroup group : groups )
+            {
+                if ( groupSet.getOrganisationUnitGroups().contains( group ) )
+                {
+                    return group;
+                }   
+            }
+        }
+        
+        return null;
+    }
+    
+    public String getGroupNameInGroupSet( OrganisationUnitGroupSet groupSet )
+    {
+        final OrganisationUnitGroup group = getGroupInGroupSet( groupSet );
+        
+        return group != null ? group.getName() : null;
+    }
         
     // -------------------------------------------------------------------------
     // hashCode, equals and toString

=== 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-12-12 07:34:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2010-12-12 13:35:21 +0000
@@ -232,7 +232,7 @@
      */
     Set<Source> convert( Collection<OrganisationUnit> organisationUnits );
     
-    Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups );
+    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, 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-12-12 07:34:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2010-12-12 13:35:21 +0000
@@ -91,7 +91,7 @@
      */
     Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
     
-    Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups );
+    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups );
     
     // -------------------------------------------------------------------------
     // OrganisationUnitHierarchy

=== 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-12-12 07:34:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2010-12-12 13:35:21 +0000
@@ -405,9 +405,9 @@
         return organisationUnitStore.getOrganisationUnitsWithoutGroups();
     }
 
-    public Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups )
+    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups )
     {
-        return organisationUnitStore.getOrganisationUnitsByGroups( groups );
+        return organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups );
     }
     
     // -------------------------------------------------------------------------

=== 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-12-12 07:34:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2010-12-12 13:35:21 +0000
@@ -137,11 +137,16 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<OrganisationUnit> getOrganisationUnitsByGroups( Collection<OrganisationUnitGroup> groups )
+    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups )
     {
         if ( groups != null && groups.size() > 0 )
         {
             StringBuilder hql = new StringBuilder( "from OrganisationUnit o where" );
+            
+            if ( name != null && !name.trim().isEmpty() )
+            {
+                hql.append(  " lower(name) like :name and" );
+            }
                         
             for ( int i = 0; i < groups.size(); i++ )
             {
@@ -152,6 +157,11 @@
             
             Query query = sessionFactory.getCurrentSession().createQuery( hql.toString() );
             
+            if ( name != null && !name.trim().isEmpty() )
+            {
+                query.setString( "name", "%" + name.toLowerCase() + "%" );
+            }
+            
             int i = 0;
             
             for ( OrganisationUnitGroup group : groups )

=== 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-12-12 07:34:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2010-12-12 13:35:21 +0000
@@ -382,16 +382,22 @@
         organisationUnitGroupService.addOrganisationUnitGroup( groupC );
         
         List<OrganisationUnitGroup> groups = Arrays.asList( groupA );        
-        Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByGroups( groups );        
+        Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
         assertEquals( 3, units.size() );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups );
+        assertEquals( 1, units.size() );
+        assertEquals( unitA, units.iterator().next() );
 
-        groups = Arrays.asList( groupA, groupB );        
-        units = organisationUnitService.getOrganisationUnitsByGroups( groups );        
+        groups = Arrays.asList( groupA, groupB );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
         assertEquals( 2, units.size() );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName().toUpperCase(), groups );
+        assertEquals( 1, units.size() );
+        assertEquals( unitB, units.iterator().next() );
 
         groups = Arrays.asList( groupA, groupB, groupC );        
-        units = organisationUnitService.getOrganisationUnitsByGroups( groups );        
-        assertEquals( 1, units.size() );        
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );        
+        assertEquals( 1, units.size() ); 
     }
     
     // -------------------------------------------------------------------------