dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09151
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2364: Finished orgunit search
------------------------------------------------------------
revno: 2364
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2010-12-13 18:03:08 +0100
message:
Finished orgunit search
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.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/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/META-INF/dhis/beans.xml
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/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js
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 2010-12-12 17:09:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2010-12-13 17:03:08 +0000
@@ -242,6 +242,18 @@
* @return a collection of organisation units.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups );
+
+ /**
+ * 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.
+ * @param groups the organisation unit groups.
+ * @return a collection of organisation units.
+ */
+ Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent );
/**
* Get the units in tree by the collection of given roots
=== 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 13:35:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2010-12-13 17:03:08 +0000
@@ -37,6 +37,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.organisationunit.comparator.OrganisationUnitLevelComparator;
@@ -409,6 +410,21 @@
{
return organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups );
}
+
+ @SuppressWarnings("unchecked")
+ public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent )
+ {
+ final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups );
+
+ if ( parent == null )
+ {
+ return result;
+ }
+
+ final Collection<OrganisationUnit> subTree = getOrganisationUnitWithChildren( parent.getId() );
+
+ return CollectionUtils.intersection( subTree, result );
+ }
// -------------------------------------------------------------------------
// 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-12-12 17:09:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java 2010-12-13 17:03:08 +0000
@@ -31,6 +31,7 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertFalse;
import java.util.Arrays;
import java.util.Collection;
@@ -360,8 +361,9 @@
public void testGetOrganisationUnitsByNameAndGroups()
{
OrganisationUnit unitA = createOrganisationUnit( 'A' );
- OrganisationUnit unitB = createOrganisationUnit( 'B' );
- OrganisationUnit unitC = createOrganisationUnit( 'C' );
+ OrganisationUnit unitB = createOrganisationUnit( 'B', unitA );
+ unitA.getChildren().add( unitB );
+ OrganisationUnit unitC = createOrganisationUnit( 'C' );
organisationUnitService.addOrganisationUnit( unitA );
organisationUnitService.addOrganisationUnit( unitB );
organisationUnitService.addOrganisationUnit( unitC );
@@ -386,10 +388,13 @@
assertEquals( 3, units.size() );
units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName().toLowerCase(), groups );
assertEquals( 1, units.size() );
+ assertTrue( units.contains( unitA ) );
+ units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName(), null );
+ assertEquals( 1, units.size() );
assertEquals( unitA, units.iterator().next() );
- units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitA.getName(), null );
- assertEquals( 1, units.size() );
- assertEquals( unitA, units.iterator().next() );
+ units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA );
+ assertEquals( 2, units.size() );
+ assertFalse( units.contains( unitC ) );
groups = Arrays.asList( groupA, groupB );
units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
@@ -400,10 +405,12 @@
units = organisationUnitService.getOrganisationUnitsByNameAndGroups( unitB.getName(), null );
assertEquals( 1, units.size() );
assertEquals( unitB, units.iterator().next() );
+ units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups, unitA );
+ assertEquals( 2, units.size() );
groups = Arrays.asList( groupA, groupB, groupC );
units = organisationUnitService.getOrganisationUnitsByNameAndGroups( null, groups );
- assertEquals( 1, units.size() );
+ 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 2010-12-12 18:39:35 +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-13 17:03:08 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
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;
@@ -70,6 +71,13 @@
this.organisationUnitService = organisationUnitService;
}
+ private OrganisationUnitSelectionManager selectionManager;
+
+ public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+ {
+ this.selectionManager = selectionManager;
+ }
+
// -------------------------------------------------------------------------
// Input and output
// -------------------------------------------------------------------------
@@ -116,6 +124,13 @@
return organisationUnits;
}
+ private OrganisationUnit selectedOrganisationUnit;
+
+ public OrganisationUnit getSelectedOrganisationUnit()
+ {
+ return selectedOrganisationUnit;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -127,6 +142,8 @@
// Assemble groups and get search result
// ---------------------------------------------------------------------
+ selectedOrganisationUnit = selectionManager.getSelectedOrganisationUnit();
+
if ( StringUtils.isNotBlank( name ) || !CollectionUtils.isEmpty( groupId ) )
{
Collection<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
@@ -140,7 +157,7 @@
}
}
- organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups );
+ organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups, selectedOrganisationUnit );
}
// ---------------------------------------------------------------------
=== 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-12-12 20:39:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml 2010-12-13 17:03:08 +0000
@@ -322,6 +322,8 @@
ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
<property name="organisationUnitService"
ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="selectionManager"
+ ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
</bean>
<bean
=== 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-12 17:09:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2010-12-13 17:03:08 +0000
@@ -105,4 +105,6 @@
search_result = Search result
search = Search
organisation_units = organisation units
-found = Found
\ No newline at end of file
+found = Found
+all = All
+please_select_from_tree = Please select from tree (optional)
\ 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-12-12 20:39:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml 2010-12-13 17:03:08 +0000
@@ -300,8 +300,9 @@
class="org.hisp.dhis.oum.action.search.SearchOrganisationUnitsAction">
<result name="success" type="velocity">/main.vm</result>
<param name="page">/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm</param>
- <param name="menu">/dhis-web-maintenance-organisationunit/menu.vm</param>
- <param name="javascripts">javascript/organisationUnitSearch.js</param>
+ <param name="menu">/dhis-web-maintenance-organisationunit/menuWithTree.vm</param>
+ <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,javascript/organisationUnitSearch.js</param>
+ <interceptor-ref name="organisationUnitTreeStack" />
</action>
<action name="getOrganisationUnitDetails"
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js 2010-12-12 20:39:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js 2010-12-13 17:03:08 +0000
@@ -1,4 +1,18 @@
+function organisationUnitSelected( orgUnitIds )
+{
+ if ( orgUnitIds[0] && orgUnitIds[0] > 0 ) {
+ $.getJSON( "../dhis-web-commons-ajax-json/getOrganisationUnit.action?id=" + orgUnitIds[0], function( data ) {
+ $( "#selectedOrganisationUnit" ).val( "[ " + data.organisationUnit.name + " ]" );
+ } );
+ }
+ else {
+ $( "#selectedOrganisationUnit" ).val( "[ " + i18n_all + " ]" );
+ }
+}
+
+selection.setListenerFunction( organisationUnitSelected );
+
function initOrgUnitDetails()
{
$( "#organisationUnitDetails" ).dialog( {
=== 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 2010-12-12 20:39:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm 2010-12-13 17:03:08 +0000
@@ -1,4 +1,10 @@
+#if( $selectedOrganisationUnit )
+#set( $orgUnitText = "[ $!encoder.htmlEncode( $selectedOrganisationUnit.name ) ]" )
+#else
+#set( $orgUnitText = $i18n.getString( 'please_select_from_tree' ) )
+#end
+
<h3>$i18n.getString( "org_unit_search_management" )</h3>
<form action="organisationUnitSearch.action" method="get">
@@ -9,6 +15,11 @@
</tr>
<tr>
+<td>$i18n.getString( "organisation_unit" )</td>
+<td><input type="text" id="selectedOrganisationUnit" style="width:325px" readonly="true" value="${orgUnitText}"></td>
+</tr>
+
+<tr>
<td>$i18n.getString( "name" )</th>
<td><input type="text" name="name" style="width:325px" value="$!{name}"></td>
</tr>
@@ -88,4 +99,6 @@
initOrgUnitDetails();
} );
+var i18n_all = '$encoder.jsEscape( $i18n.getString( "all" ) , "'" )';
+
</script>