← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3062: Organisation unit search: allowing search without restrictions. Limiting search at 500 hits.

 

------------------------------------------------------------
revno: 3062
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-17 21:59:33 +0100
message:
  Organisation unit search: allowing search without restrictions. Limiting search at 500 hits.
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/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-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm


--
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	2011-02-17 02:14:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2011-03-17 20:59:33 +0000
@@ -44,6 +44,8 @@
 {
     String ID = OrganisationUnitService.class.getName();
 
+    final int MAX_LIMIT = 500;
+    
     // -------------------------------------------------------------------------
     // OrganisationUnit
     // -------------------------------------------------------------------------
@@ -233,7 +235,7 @@
      * @param groups the organisation unit groups.
      * @return a collection of organisation units.
      */
-    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups );
+    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
 
     /**
      * Get the units which name are like the given name, are members of the
@@ -245,7 +247,7 @@
      * @param groups the organisation unit groups.
      * @return a collection of organisation units.
      */
-    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent );
+    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit );
     
     /**
      * 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	2011-02-17 02:14:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java	2011-03-17 20:59:33 +0000
@@ -83,7 +83,7 @@
      */
     Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
     
-    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups );
+    Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
     
     // -------------------------------------------------------------------------
     // 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	2011-02-17 02:14:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-03-17 20:59:33 +0000
@@ -405,15 +405,15 @@
         return organisationUnitStore.getOrganisationUnitsWithoutGroups();
     }
 
-    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups )
+    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit )
     {
-        return organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups );
+        return organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups, limit );
     }
 
     @SuppressWarnings("unchecked")    
-    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent )
+    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
     {
-        final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups );
+        final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups, limit );
         
         if ( parent == null )
         {

=== 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	2011-02-17 02:14:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2011-03-17 20:59:33 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.util.Collection;
-import java.util.HashSet;
 
 import org.amplecode.quick.StatementHolder;
 import org.amplecode.quick.StatementManager;
@@ -43,6 +42,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.OrganisationUnitStore;
 import org.hisp.dhis.system.objectmapper.OrganisationUnitRelationshipRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -128,33 +128,34 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups )
+    public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit )
     {
+        boolean first = true;
+        
         name = StringUtils.trimToNull( name );
         groups = CollectionUtils.isEmpty( groups ) ? null : groups;
         
-        if ( name == null && groups == null )
-        {
-            return new HashSet<OrganisationUnit>();
-        }
-        
-        StringBuilder hql = new StringBuilder( "from OrganisationUnit o where" );
+        StringBuilder hql = new StringBuilder( "from OrganisationUnit o" );
         
         if ( name != null )
         {
-            hql.append(  " lower(name) like :name and" );
+            hql.append(  " where lower(name) like :name" );
+            
+            first = false;
         }
         
         if ( groups != null )
         {
             for ( int i = 0; i < groups.size(); i++ )
             {
-                hql.append( " :g" ).append( i ).append( " in elements( o.groups ) and" );
+                String clause = first ? " where" : " and";
+                
+                hql.append( clause ).append( " :g" ).append( i ).append( " in elements( o.groups )" );
+                
+                first = false;
             }
         }
 
-        hql.delete( hql.length() - " and".length(), hql.length() );
-        
         Query query = sessionFactory.getCurrentSession().createQuery( hql.toString() );
         
         if ( name != null )
@@ -172,6 +173,11 @@
             }
         }
         
+        if ( limit )
+        {
+            query.setMaxResults( OrganisationUnitService.MAX_LIMIT );
+        }
+        
         return query.list();        
     }
 

=== 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-13 21:21:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2011-03-17 20:59:33 +0000
@@ -385,32 +385,32 @@
         organisationUnitGroupService.addOrganisationUnitGroup( groupC );
         
         List<OrganisationUnitGroup> groups = Arrays.asList( groupA );        
-        Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
+        Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );
         assertEquals( 3, units.size() );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups, false );
         assertEquals( 1, units.size() );
         assertTrue( units.contains( unitA ) );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName(), null );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName(), null, false );
         assertEquals( 1, units.size() );
         assertEquals( unitA, units.iterator().next() );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA, false );
         assertEquals( 2, units.size() );
         assertFalse( units.contains( unitC ) );
 
         groups = Arrays.asList( groupA, groupB );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );
         assertEquals( 2, units.size() );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName().toUpperCase(), groups );
-        assertEquals( 1, units.size() );
-        assertEquals( unitB, units.iterator().next() );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName(), null );
-        assertEquals( 1, units.size() );
-        assertEquals( unitB, units.iterator().next() );
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName().toUpperCase(), groups, false );
+        assertEquals( 1, units.size() );
+        assertEquals( unitB, units.iterator().next() );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName(), null, false );
+        assertEquals( 1, units.size() );
+        assertEquals( unitB, units.iterator().next() );
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA, false );
         assertEquals( 2, units.size() );
 
         groups = Arrays.asList( groupA, groupB, groupC );        
-        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );        
+        units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, false );        
         assertEquals( 1, units.size() );
     }
     

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java	2011-01-19 11:18:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java	2011-03-17 20:59:33 +0000
@@ -41,7 +41,6 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
-import org.springframework.util.CollectionUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -82,6 +81,13 @@
     // Input and output
     // -------------------------------------------------------------------------
 
+    private boolean search;
+    
+    public void setSearch( boolean search )
+    {
+        this.search = search;
+    }
+
     private String name;
     
     public String getName()
@@ -130,6 +136,13 @@
     {
         return selectedOrganisationUnit;
     }
+    
+    boolean limited = false;
+
+    public boolean isLimited()
+    {
+        return limited;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -142,24 +155,26 @@
         // Assemble groups and get search result
         // ---------------------------------------------------------------------
 
-        name = StringUtils.trimToNull( name );
-        
-        selectedOrganisationUnit = selectionManager.getSelectedOrganisationUnit();
-        
-        Collection<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
-        
-        for ( Integer id : groupId )
+        if ( search )
         {
-            if ( id != ANY )
+            name = StringUtils.trimToNull( name );
+            
+            selectedOrganisationUnit = selectionManager.getSelectedOrganisationUnit();
+            
+            Collection<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
+            
+            for ( Integer id : groupId )
             {
-                OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( id );
-                groups.add( group );
+                if ( id != ANY )
+                {
+                    OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( id );
+                    groups.add( group );
+                }
             }
-        }
-                
-        if ( !( name == null && CollectionUtils.isEmpty( groups ) ) )
-        {
-            organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups, selectedOrganisationUnit );
+        
+            organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups, selectedOrganisationUnit, true );
+            
+            limited = organisationUnits != null && organisationUnits.size() == OrganisationUnitService.MAX_LIMIT;
         }
         
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-03-17 10:20:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-03-17 20:59:33 +0000
@@ -110,4 +110,5 @@
 please_select_from_tree								= Please select from tree (optional)
 feature_type										= Feature type
 available_data_sets									= Available data sets
-selected_data_sets									= Selected data sets
\ No newline at end of file
+selected_data_sets									= Selected data sets
+limited												= Limited
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm	2011-01-19 11:18:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm	2011-03-17 20:59:33 +0000
@@ -8,6 +8,9 @@
 <h3>$i18n.getString( "org_unit_search_management" )</h3>
 
 <form action="organisationUnitSearch.action" method="post">
+
+<input type="hidden" name="search" value="true">
+
 <table>
 <tr>
 <th>$i18n.getString( "criteria" )</th>
@@ -61,7 +64,7 @@
 
 #if ( $organisationUnits )
 
-<h4>$i18n.getString( "found" ) $organisationUnits.size() $i18n.getString( "organisation_units" )</h4>
+<h4>$i18n.getString( "found" ) $organisationUnits.size() $i18n.getString( "organisation_units" ) #if( $limited )($i18n.getString( "limited" ))#end</h4>
 
 <table class="listTable" style="width:90%">
 <thead>