dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19815
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8799: Improved organisation unit search so that you can search on name, code or identifier
------------------------------------------------------------
revno: 8799
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-10-31 20:24:33 +0300
message:
Improved organisation unit search so that you can search on name, code or identifier
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-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 2012-05-28 14:25:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2012-10-31 17:24:33 +0000
@@ -239,25 +239,24 @@
Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
/**
- * 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.
+ * Returns all OrganisationUnit which names are like the given name, or which
+ * code or uid are equal the given name, and are within the given groups.
+ *
+ * @param query the query to match on name, code or uid.
* @param groups the organisation unit groups.
- * @return a collection of organisation units.
+ * @param limit the limit of returned objects.
+ * @return a collection of OrganisationUnits.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
/**
- * Get the units which name are like the given name, are members of the
- * given groups and children of the given parent organisation unit. If name
- * or groups are null or empty they are ignored in the sarch. If name and
- * groups are null an empty collection is returned.
- *
- * @param name the name.
+ * Returns all OrganisationUnit which names are like the given name, or which
+ * code or uid are equal the given name, and are within the given groups.
+ *
+ * @param query the query to match on name, code or uid.
* @param groups the organisation unit groups.
- * @return a collection of organisation units.
+ * @param limit the limit of returned objects.
+ * @return a collection of OrganisationUnits.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit );
=== 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 2012-05-24 05:13:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2012-10-31 17:24:33 +0000
@@ -72,7 +72,16 @@
*/
Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups();
- Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
+ /**
+ * Returns all OrganisationUnit which names are like the given name, or which
+ * code or uid are equal the given name, and are within the given groups.
+ *
+ * @param query the query to match on name, code or uid.
+ * @param groups the organisation unit groups.
+ * @param limit the limit of returned objects.
+ * @return a collection of OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String query, Collection<OrganisationUnitGroup> groups, boolean limit );
Map<Integer, Set<Integer>> getOrganisationUnitDataSetAssocationMap();
=== 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 2012-09-26 04:56:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2012-10-31 17:24:33 +0000
@@ -430,10 +430,10 @@
return organisationUnitStore.getOrganisationUnitsWithoutGroups();
}
- public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
+ public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String query,
Collection<OrganisationUnitGroup> groups, boolean limit )
{
- return organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups, limit );
+ return organisationUnitStore.getOrganisationUnitsByNameAndGroups( query, groups, limit );
}
@SuppressWarnings( "unchecked" )
=== 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 2012-05-24 05:13:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2012-10-31 17:24:33 +0000
@@ -80,19 +80,19 @@
}
@SuppressWarnings( "unchecked" )
- public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
+ public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String query,
Collection<OrganisationUnitGroup> groups, boolean limit )
{
boolean first = true;
- name = StringUtils.trimToNull( name );
+ query = StringUtils.trimToNull( query );
groups = CollectionUtils.isEmpty( groups ) ? null : groups;
StringBuilder hql = new StringBuilder( "from OrganisationUnit o" );
- if ( name != null )
+ if ( query != null )
{
- hql.append( " where lower(name) like :name" );
+ hql.append( " where ( lower(o.name) like :expression or o.code = :query or o.uid = :query )" );
first = false;
}
@@ -109,11 +109,12 @@
}
}
- Query query = sessionFactory.getCurrentSession().createQuery( hql.toString() );
-
- if ( name != null )
+ Query q = sessionFactory.getCurrentSession().createQuery( hql.toString() );
+
+ if ( query != null )
{
- query.setString( "name", "%" + name.toLowerCase() + "%" );
+ q.setString( "expression", "%" + query.toLowerCase() + "%" );
+ q.setString( "query", query );
}
if ( groups != null )
@@ -122,16 +123,16 @@
for ( OrganisationUnitGroup group : groups )
{
- query.setEntity( "g" + i++, group );
+ q.setEntity( "g" + i++, group );
}
}
if ( limit )
{
- query.setMaxResults( OrganisationUnitService.MAX_LIMIT );
+ q.setMaxResults( OrganisationUnitService.MAX_LIMIT );
}
- return query.list();
+ return q.list();
}
public Map<Integer, Set<Integer>> getOrganisationUnitDataSetAssocationMap()
=== 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 2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java 2012-10-31 17:24:33 +0000
@@ -236,7 +236,8 @@
private Grid generateGrid()
{
final Grid orgUnitGrid = new ListGrid().setTitle( "Organisation unit search result" );
-
+
+ orgUnitGrid.addHeader( new GridHeader( "Identifier", false, true ) );
orgUnitGrid.addHeader( new GridHeader( "Code", false, true ) );
orgUnitGrid.addHeader( new GridHeader( "Name", false, true ) );
@@ -249,6 +250,7 @@
{
orgUnitGrid.addRow();
+ orgUnitGrid.addValue( unit.getUid() );
orgUnitGrid.addValue( unit.getCode() );
orgUnitGrid.addValue( unit.getName() );
=== 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 2012-10-31 08:31:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2012-10-31 17:24:33 +0000
@@ -99,4 +99,6 @@
select_group=Select group
phone_number=Phone number
select_symbol=Select symbol
-symbol=Symbol
\ No newline at end of file
+symbol=Symbol
+name_code_identifier=Name, code or identifier
+identifier=Identifier
\ 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 2012-02-22 15:04:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm 2012-10-31 17:24:33 +0000
@@ -25,7 +25,7 @@
<td><input type="text" id="selectedOrganisationUnit" style="width:360px" readonly="true" value="${orgUnitText}"/></td>
</tr>
<tr>
- <td>$i18n.getString( "name" )</th>
+ <td>$i18n.getString( "name_code_identifier" )</th>
<td><input type="text" name="name" style="width:360px" value="$!{name}"/></td>
</tr>
#foreach( $groupSet in $groupSets )
@@ -47,15 +47,18 @@
</tr>
<tr>
<td></td>
- <td><input type="button" value="$i18n.getString( 'search' )" style="width:120px" onclick="download( '' )"/><input
- type="button" onclick="window.location.href='organisationUnitSearch.action?skipSearch=true'" value="$i18n.getString( 'clear' )" style="width:120px"/></td>
+ <td>
+ <input type="button" value="$i18n.getString( 'search' )" style="width:120px" onclick="download( '' )"/>
+ <input type="button" onclick="window.location.href='organisationUnitSearch.action?skipSearch=true'" value="$i18n.getString( 'clear' )" style="width:120px"/>
+ </td>
</tr>
<tr>
<td style="height:2px" colspan="2"></td>
</tr>
<tr>
<td></td>
- <td><input type="button" value="$i18n.getString( 'get_report_as_pdf' )" style="width:120px" onclick="download( 'pdf' )"/>
+ <td>
+ <input type="button" value="$i18n.getString( 'get_report_as_pdf' )" style="width:120px" onclick="download( 'pdf' )"/>
<input type="button" value="$i18n.getString( 'get_report_as_xls' )" style="width:120px" onclick="download( 'xls' )"/>
<input type="button" value="$i18n.getString( 'get_report_as_csv' )" style="width:120px" onclick="download( 'csv' )"/>
</td>
@@ -77,6 +80,7 @@
<table class="listTable" style="width:95%">
<thead>
<tr>
+ <th style="width:100px">$i18n.getString( "identifier" )</th>
<th style="width:100px">$i18n.getString( "code" )</th>
<th style="min-width:300px">$i18n.getString( "name" )</th>
#foreach( $groupSet in $groupSets )
@@ -89,6 +93,7 @@
<tbody id="list">
#foreach( $unit in $organisationUnits )
<tr>
+ <td>$!encoder.htmlEncode( $unit.uid )</td>
<td>$!encoder.htmlEncode( $unit.code )</td>
<td>$!encoder.htmlEncode( $unit.name )</td>
#foreach( $groupSet in $groupSets )