dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12316
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3756: updated GetOrganisationUnitGroupsAction to include filters, removeIds, etc
------------------------------------------------------------
revno: 3756
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-05-26 14:49:27 +0200
message:
updated GetOrganisationUnitGroupsAction to include filters, removeIds, etc
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitGroupsAction.java
--
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-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitGroupsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitGroupsAction.java 2011-05-06 10:59:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitGroupsAction.java 2011-05-26 12:49:27 +0000
@@ -1,14 +1,5 @@
package org.hisp.dhis.commons.action;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupNameComparator;
-import org.hisp.dhis.paging.ActionPagingSupport;
-
/*
* Copyright (c) 2004-2010, University of Oslo
* All rights reserved.
@@ -35,8 +26,23 @@
* (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.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupNameComparator;
+import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.system.filter.OrganisationUnitGroupWithoutGroupSetFilter;
+import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.system.util.IdentifiableObjectUtils;
+
/**
* @author Tran Thanh Tri
+ * @author mortenoh
*/
public class GetOrganisationUnitGroupsAction
extends ActionPagingSupport<OrganisationUnitGroup>
@@ -53,9 +59,38 @@
}
// -------------------------------------------------------------------------
- // Output
+ // Input & output
// -------------------------------------------------------------------------
+ private String key;
+
+ public void setKey( String key )
+ {
+ this.key = key;
+ }
+
+ public boolean filterNoGroupSet;
+
+ public void setFilterNoGroupSet( boolean filterNoGroupSet )
+ {
+ this.filterNoGroupSet = filterNoGroupSet;
+ }
+
+ private List<Integer> removeOrganisationUnitGroups = new ArrayList<Integer>();
+
+ public void setRemoveOrganisationUnitGroups( String removeOrganisationUnitGroups )
+ {
+ if ( removeOrganisationUnitGroups.length() > 0 )
+ {
+ List<String> stringList = Arrays.asList( removeOrganisationUnitGroups.split( "," ) );
+
+ for ( String s : stringList )
+ {
+ this.removeOrganisationUnitGroups.add( Integer.parseInt( s ) );
+ }
+ }
+ }
+
private List<OrganisationUnitGroup> organisationUnitGroups;
public List<OrganisationUnitGroup> getOrganisationUnitGroups()
@@ -63,6 +98,10 @@
return organisationUnitGroups;
}
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
@Override
public String execute()
throws Exception
@@ -70,6 +109,26 @@
organisationUnitGroups = new ArrayList<OrganisationUnitGroup>(
organisationUnitGroupService.getAllOrganisationUnitGroups() );
+ if ( filterNoGroupSet )
+ {
+ FilterUtils.filter( organisationUnitGroups, new OrganisationUnitGroupWithoutGroupSetFilter() );
+ }
+
+ if ( removeOrganisationUnitGroups.size() > 0 )
+ {
+ for ( Integer id : removeOrganisationUnitGroups )
+ {
+ OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService
+ .getOrganisationUnitGroup( id );
+ organisationUnitGroups.remove( organisationUnitGroup );
+ }
+ }
+
+ if ( key != null )
+ {
+ organisationUnitGroups = IdentifiableObjectUtils.filterNameByKey( organisationUnitGroups, key, true );
+ }
+
Collections.sort( organisationUnitGroups, new OrganisationUnitGroupNameComparator() );
if ( usePaging )