=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-11-19 16:48:11 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-11-19 16:59:04 +0000 @@ -256,6 +256,8 @@ @RequestParam( value = "active", required = false ) List activeList, @RequestParam( value = "name", required = false ) List nameList, @RequestParam( value = "uuid", required = false ) List uuidList, + @RequestParam( value = "properties.parent", required = false ) List parentList, + @RequestParam( value = "properties.level", required = false ) List levelList, HttpServletRequest request, HttpServletResponse response ) throws IOException { Facilities facilities = new Facilities(); @@ -280,6 +282,8 @@ filterByActiveList( activeList, allOrganisationUnits ); filterByNameList( nameList, allOrganisationUnits ); filterByUuidList( uuidList, allOrganisationUnits ); + filterByPropertiesParent( parentList, allOrganisationUnits ); + filterByPropertiesLevel( levelList, allOrganisationUnits ); filterByLimit( offset, limitValue, allOrganisationUnits ); @@ -329,6 +333,76 @@ allOrganisationUnits.addAll( organisationUnits ); } + private void filterByPropertiesLevel( List levelList, List allOrganisationUnits ) + { + if ( levelList == null || levelList.isEmpty() ) + { + return; + } + + Iterator organisationUnitIterator = allOrganisationUnits.iterator(); + + while ( organisationUnitIterator.hasNext() ) + { + OrganisationUnit organisationUnit = organisationUnitIterator.next(); + + boolean shouldRemove = true; + + for ( String level : levelList ) + { + try + { + int l = Integer.parseInt( level ); + + if ( organisationUnit.getOrganisationUnitLevel() == l ) + { + shouldRemove = false; + break; + } + } + catch ( NumberFormatException ignored ) + { + } + } + + if ( shouldRemove ) + { + organisationUnitIterator.remove(); + } + } + } + + private void filterByPropertiesParent( List parentList, List allOrganisationUnits ) + { + if ( parentList == null || parentList.isEmpty() ) + { + return; + } + + Iterator organisationUnitIterator = allOrganisationUnits.iterator(); + + while ( organisationUnitIterator.hasNext() ) + { + OrganisationUnit organisationUnit = organisationUnitIterator.next(); + + boolean shouldRemove = true; + + for ( String parent : parentList ) + { + if ( organisationUnit.getParent() != null && organisationUnit.getParent().getUid().equals( parent ) ) + { + shouldRemove = false; + break; + } + } + + if ( shouldRemove ) + { + organisationUnitIterator.remove(); + } + } + } + private void filterByUuidList( List uuidList, List allOrganisationUnits ) { if ( uuidList == null || uuidList.isEmpty() )