=== 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 13:35:21 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-12-12 17:09:27 +0000 @@ -232,6 +232,15 @@ */ Set convert( Collection organisationUnits ); + /** + * Get the units which name are like the given name and are members of the + * given groups. If name or groups are null or empty they are ignored in the + * search. If name and groups are null an empty collection is returned. + * + * @param name the name. + * @param groups the organisation unit groups. + * @return a collection of organisation units. + */ Collection getOrganisationUnitsByNameAndGroups( String name, Collection 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 13:35:21 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2010-12-12 17:09:27 +0000 @@ -32,6 +32,8 @@ import org.amplecode.quick.StatementHolder; import org.amplecode.quick.StatementManager; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.Session; @@ -139,40 +141,50 @@ @SuppressWarnings( "unchecked" ) public Collection getOrganisationUnitsByNameAndGroups( String name, Collection 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" ); - } - + name = StringUtils.trimToNull( name ); + groups = CollectionUtils.isEmpty( groups ) ? null : groups; + + if ( name == null && groups == null ) + { + return new HashSet(); + } + + StringBuilder hql = new StringBuilder( "from OrganisationUnit o where" ); + + if ( name != null ) + { + hql.append( " lower(name) like :name and" ); + } + + if ( groups != null ) + { 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() ); - - if ( name != null && !name.trim().isEmpty() ) - { - query.setString( "name", "%" + name.toLowerCase() + "%" ); - } - + } + + hql.delete( hql.length() - " and".length(), hql.length() ); + + Query query = sessionFactory.getCurrentSession().createQuery( hql.toString() ); + + if ( name != null ) + { + query.setString( "name", "%" + name.toLowerCase() + "%" ); + } + + if ( groups != null ) + { int i = 0; for ( OrganisationUnitGroup group : groups ) { query.setEntity( "g" + i++, group ); } - - return query.list(); } - return new HashSet(); + 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-12 13:35:21 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java 2010-12-12 17:09:27 +0000 @@ -357,7 +357,7 @@ assertTrue( equals( organisationUnitService.getOrganisationUnitsAtLevel( 4, unitB ), unitH, unitI, unitJ, unitK ) ); } @Test - public void testGetOrganisationUnitsByGroups() + public void testGetOrganisationUnitsByNameAndGroups() { OrganisationUnit unitA = createOrganisationUnit( 'A' ); OrganisationUnit unitB = createOrganisationUnit( 'B' ); @@ -387,6 +387,9 @@ units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups ); assertEquals( 1, units.size() ); assertEquals( unitA, units.iterator().next() ); + units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName(), null ); + assertEquals( 1, units.size() ); + assertEquals( unitA, units.iterator().next() ); groups = Arrays.asList( groupA, groupB ); units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups ); @@ -394,6 +397,9 @@ 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() ); groups = Arrays.asList( groupA, groupB, groupC ); units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups ); === added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/hierarchy.png' Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/hierarchy.png 1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/hierarchy.png 2010-12-12 17:09:27 +0000 differ === added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/search.png' Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/search.png 1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/search.png 2010-12-12 17:09:27 +0000 differ === added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search' === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/GetCompulsoryGroupSetsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/GetCompulsoryGroupSetsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/GetCompulsoryGroupSetsAction.java 2010-12-12 17:09:27 +0000 @@ -0,0 +1,68 @@ +package org.hisp.dhis.oum.action.search; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + */ +public class GetCompulsoryGroupSetsAction + implements Action +{ + private OrganisationUnitGroupService organisationUnitGroupService; + + public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService ) + { + this.organisationUnitGroupService = organisationUnitGroupService; + } + + private List groupSets; + + public List getGroupSets() + { + return groupSets; + } + + public String execute() + { + groupSets = new ArrayList( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ); + + Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() ); + + return SUCCESS; + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java 2010-12-12 17:09:27 +0000 @@ -0,0 +1,117 @@ +package org.hisp.dhis.oum.action.search; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.HashSet; + +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitGroup; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + */ +public class SearchOrganisationUnitsAction + implements Action +{ + private static final int ANY = -1; + + // ------------------------------------------------------------------------- + // Depdencies + // ------------------------------------------------------------------------- + + private OrganisationUnitGroupService organisationUnitGroupService; + + public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService ) + { + this.organisationUnitGroupService = organisationUnitGroupService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + private Collection group = new HashSet(); + + public void setGroup( Collection group ) + { + this.group = group; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Collection organisationUnits; + + public Collection getOrganisationUnits() + { + return organisationUnits; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + Collection groups = new HashSet(); + + for ( Integer id : group ) + { + if ( id != ANY ) + { + OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( id ); + groups.add( group ); + } + } + + organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml 2010-09-14 09:03:41 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml 2010-12-12 17:09:27 +0000 @@ -247,7 +247,7 @@ - + + + + + + + + + + + + === 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 2010-12-09 06:15:40 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2010-12-12 17:09:27 +0000 @@ -93,6 +93,16 @@ intro_org_unit_group = Create, modify, view and delete organisation unit groups. Groups are used for improved analysis. intro_org_unit_group_set = Create, modify, view and delete organisation unit group sets. Group sets are used for improved analysis. intro_org_unit_level = Create, modify, view and delete descriptive names for the organisation unit levels in the system. +intro_org_unit_search = Search organisation units based on name and group sets. View extended information for individual units. intro_hierarchy_operations_menu = Move organisation units in the organisation unit tree. All children will be moved along with the unit. loading = Loading -coordinates = Coordinates \ No newline at end of file +coordinates = Coordinates +org_unit_search = Organisation Unit Search +org_unit_search_management = Organisation unit search +criteria = Criteria +options = Options +any = Any +search_result = Search result +search = Search +organisation_units = organisation units +found = Found \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml 2010-11-29 13:06:19 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml 2010-12-12 17:09:27 +0000 @@ -22,7 +22,7 @@ /main.vm /dhis-web-maintenance-organisationunit/organisationUnit.vm /dhis-web-maintenance-organisationunit/menuWithTree.vm - 358 + 328 ../dhis-web-commons/ouwt/ouwt.js, javascript/organisationUnit.js @@ -293,6 +293,20 @@ class="org.hisp.dhis.oum.action.organisationunitlevel.SaveOrganisationUnitLevelsAction"> index.action + + + + + /main.vm + /dhis-web-maintenance-organisationunit/organisationUnitSearch.vm + /dhis-web-maintenance-organisationunit/menu.vm + + + + organisationUnitSearch + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm 2010-12-09 22:05:52 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm 2010-12-12 17:09:27 +0000 @@ -6,5 +6,6 @@ #introListImgItem( "organisationUnitGroup.action" "org_unit_group" "organisationunit" ) #introListImgItem( "organisationUnitGroupSet.action" "org_unit_group_set" "organisationunit" ) #introListImgItem( "organisationUnitLevel.action" "org_unit_level" "organisationunit" ) - #introListImgItem( "hierarchyOperations.action" "hierarchy_operations_menu" "organisationunit" ) + #introListImgItem( "organisationUnitSearch.action" "org_unit_search" "search" ) + #introListImgItem( "hierarchyOperations.action" "hierarchy_operations_menu" "hierarchy" ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm 2009-03-03 16:46:36 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm 2010-12-12 17:09:27 +0000 @@ -6,5 +6,6 @@
  • $i18n.getString( "org_unit_group" ) 
  • $i18n.getString( "org_unit_group_set" ) 
  • $i18n.getString( "org_unit_level" ) 
  • +
  • $i18n.getString( "org_unit_search" ) 
  • $i18n.getString( "hierarchy_operations_menu" ) 
  • === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm 2010-12-12 17:09:27 +0000 @@ -0,0 +1,65 @@ + +

    $i18n.getString( "org_unit_search_management" )

    + +
    + + + + + + + + + + +#foreach( $groupSet in $groupSets ) + + + + +#end + + + + + + + + + + + + + + + + +
    $i18n.getString( "criteria" )$i18n.getString( "options" )
    $i18n.getString( "name" ) +
    $encoder.htmlEncode( $groupSet.name ) + +
    +
    + +#if ( $organisationUnits ) + +

    $i18n.getString( "found" ) $organisationUnits.size() $i18n.getString( "organisation_units" )

    + + + + + + +#foreach( $unit in $organisationUnits ) + + + +#end + +
    $i18n.getString( "name" )
    $encoder.htmlEncode( $unit.name )
    + +#end === modified file 'resources/sql/integritychecks.sql' --- resources/sql/integritychecks.sql 2010-11-08 13:02:47 +0000 +++ resources/sql/integritychecks.sql 2010-12-12 17:09:27 +0000 @@ -34,3 +34,10 @@ select dm.dataelementid from datasetmembers dm join dataset ds on(dm.datasetid=ds.datasetid) where sc.datasetid=ds.datasetid); + +-- Get orgunit groups which an orgunit member of + +select * from orgunitgroup g +join orgunitgroupmembers m using(orgunitgroupid) +join organisationunit o using (organisationunitid) +where o.name = 'Mandera District Hospital';