← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2347: Work in progress on orgunit search

 

------------------------------------------------------------
revno: 2347
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2010-12-12 19:39:35 +0100
message:
  Work in progress on orgunit search
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/GetCompulsoryGroupSetsAction.java
modified:
  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/META-INF/dhis/beans.xml
  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/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-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 17:09:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2010-12-12 18:39:35 +0000
@@ -183,8 +183,7 @@
             }
         }
         
-        return query.list();
-        
+        return query.list();        
     }
 
     // -------------------------------------------------------------------------

=== removed 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	2010-12-12 17:09:27 +0000
+++ 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
@@ -1,68 +0,0 @@
-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<OrganisationUnitGroupSet> groupSets;
-
-    public List<OrganisationUnitGroupSet> getGroupSets()
-    {
-        return groupSets;
-    }
-    
-    public String execute()
-    {
-        groupSets = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() );
-        
-        Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
-        
-        return SUCCESS;
-    }
-}

=== 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 17:09:27 +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 18:39:35 +0000
@@ -27,13 +27,20 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator;
+import org.springframework.util.CollectionUtils;
 
 import com.opensymphony.xwork2.Action;
 
@@ -43,7 +50,7 @@
 public class SearchOrganisationUnitsAction
     implements Action
 {
-    private static final int ANY = -1;
+    private static final int ANY = 0;
 
     // -------------------------------------------------------------------------
     // Depdencies
@@ -64,34 +71,51 @@
     }
 
     // -------------------------------------------------------------------------
-    // Input
+    // Input and output
     // -------------------------------------------------------------------------
 
     private String name;
     
+    public String getName()
+    {
+        return name;
+    }
+
     public void setName( String name )
     {
         this.name = name;
     }
 
-    private Collection<Integer> group = new HashSet<Integer>();
-
-    public void setGroup( Collection<Integer> group )
-    {
-        this.group = group;
+    private Collection<Integer> groupId = new HashSet<Integer>();
+
+    public Collection<Integer> getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setGroupId( Collection<Integer> groupId )
+    {
+        this.groupId = groupId;
     }
 
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
+    private List<OrganisationUnitGroupSet> groupSets;
+
+    public List<OrganisationUnitGroupSet> getGroupSets()
+    {
+        return groupSets;
+    }
+    
     private Collection<OrganisationUnit> organisationUnits;
 
     public Collection<OrganisationUnit> getOrganisationUnits()
     {
         return organisationUnits;
     }
-
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -99,18 +123,33 @@
     public String execute()
         throws Exception
     {
-        Collection<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
-        
-        for ( Integer id : group )
+        // ---------------------------------------------------------------------
+        // Assemble groups and get search result
+        // ---------------------------------------------------------------------
+
+        if ( StringUtils.isNotBlank( name ) || !CollectionUtils.isEmpty( groupId ) )
         {
-            if ( id != ANY )
+            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 );
+                }
             }
+    
+            organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups );
         }
+        
+        // ---------------------------------------------------------------------
+        // Get group sets
+        // ---------------------------------------------------------------------
 
-        organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups );
+        groupSets = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() );
+        
+        Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
         
         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-12-12 17:09:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2010-12-12 18:39:35 +0000
@@ -315,14 +315,6 @@
 	<!-- OrganisationUnit Search -->
 	
 	<bean
-		id="org.hisp.dhis.oum.action.search.GetCompulsoryGroupSetsAction"
-		class="org.hisp.dhis.oum.action.search.GetCompulsoryGroupSetsAction"
-		scope="prototype">
-		<property name="organisationUnitGroupService"
-			ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
-	</bean>
-	
-	<bean
 		id="org.hisp.dhis.oum.action.search.SearchOrganisationUnitsAction"
 		class="org.hisp.dhis.oum.action.search.SearchOrganisationUnitsAction"
 		scope="prototype">

=== 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 17:09:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2010-12-12 18:39:35 +0000
@@ -297,17 +297,12 @@
 		<!-- OrganisationUnit Search -->
 		
 		<action name="organisationUnitSearch"
-			class="org.hisp.dhis.oum.action.search.GetCompulsoryGroupSetsAction">
+			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>
 		</action>
 		
-		<action name="searchOrganisationUnits"
-			class="org.hisp.dhis.oum.action.search.SearchOrganisationUnitsAction">
-			<result name="success" type="chain">organisationUnitSearch</result>
-		</action>
-
 	</package>
 
 </struts>

=== 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 17:09:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm	2010-12-12 18:39:35 +0000
@@ -1,7 +1,7 @@
 
 <h3>$i18n.getString( "org_unit_search_management" )</h3>
 
-<form action="searchOrganisationUnits.action" method="get">
+<form action="organisationUnitSearch.action" method="get">
 <table>
 <tr>
 <th>$i18n.getString( "criteria" )</th>
@@ -10,30 +10,33 @@
 
 <tr>
 <td>$i18n.getString( "name" )</th>
-<td><input type="text" name="name" style="width:325px"></td>
+<td><input type="text" name="name" style="width:325px" value="$!{name}"></td>
 </tr>
 
 #foreach( $groupSet in $groupSets )
 <tr>
 <td>$encoder.htmlEncode( $groupSet.name )</td>
 <td>
-  <select name="group" style="width:325px">
-  <option value="-1">[ $i18n.getString( "any" ) ]</option>
-  #foreach( $group in $groupSet.organisationUnitGroups )
-  <option value="$group.id">$encoder.htmlEncode( $group.name )</option>
-  #end
+  <select name="groupId" style="width:325px">
+  <option value="0">[ $i18n.getString( "any" ) ]</option>
+    #foreach( $group in $groupSet.organisationUnitGroups )
+    <option value="$group.id"
+    #if( $groupId && $groupId.contains( $group.id ) )selected="selected"#end
+    >$encoder.htmlEncode( $group.name )</option>
+    #end
   </select>
 </td>
 </tr>
 #end
 
 <tr>
-<td style="height:15px" colspan="2"></td>
+<td style="height:10px" colspan="2"></td>
 </tr>
 <tr>
 
 <td></td>
-<td><input type="submit" value="$i18n.getString( 'search' )" style="width:100px"></td>
+<td><input type="submit" value="$i18n.getString( 'search' )" style="width:100px">
+<input type="button" onclick="window.location.href='organisationUnitSearch.action'" value="$i18n.getString( 'clear' )"></td>
 
 <tr>
 <td style="height:15px" colspan="2"></td>