dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33618
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17192: more flexible geojson output parameters, now defaults parent to roots (multiple parents can be gi...
------------------------------------------------------------
revno: 17192
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-21 16:19:07 +0700
message:
more flexible geojson output parameters, now defaults parent to roots (multiple parents can be given), alså multiple levels can be given.. so to export all polygons/points at level 2,4: /api/organisationUnits.geojson?level=2&level=4
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.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-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java 2014-10-21 08:46:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java 2014-10-21 09:19:07 +0000
@@ -234,21 +234,26 @@
@RequestMapping( value = "", method = RequestMethod.GET, produces = { "application/json+geo", "application/json+geojson" } )
public void getGeoJson(
- @RequestParam( value = "level", defaultValue = "1" ) int rpLevel,
- @RequestParam( value = "parent", required = false ) String rpParent,
+ @RequestParam( value = "level", required = false ) List<Integer> rpLevels,
+ @RequestParam( value = "parent", required = false ) List<String> rpParents,
HttpServletResponse response ) throws IOException
{
- OrganisationUnit parent = manager.search( OrganisationUnit.class, rpParent );
- List<OrganisationUnit> organisationUnits;
-
- if ( parent != null )
- {
- organisationUnits = new ArrayList<>( organisationUnitService.getOrganisationUnitsAtLevel( rpLevel, parent ) );
- }
- else
- {
- organisationUnits = new ArrayList<>( organisationUnitService.getOrganisationUnitsAtLevel( rpLevel ) );
- }
+ rpLevels = rpLevels != null ? rpLevels : new ArrayList<Integer>();
+ rpParents = rpParents != null ? rpParents : new ArrayList<String>();
+
+ List<OrganisationUnit> parents = new ArrayList<>( manager.getByUid( OrganisationUnit.class, rpParents ) );
+
+ if ( rpLevels.isEmpty() )
+ {
+ rpLevels.add( 1 );
+ }
+
+ if ( parents.isEmpty() )
+ {
+ parents.addAll( organisationUnitService.getRootOrganisationUnits() );
+ }
+
+ List<OrganisationUnit> organisationUnits = new ArrayList<>( organisationUnitService.getOrganisationUnitsAtLevels( rpLevels, parents ) );
response.setContentType( "application/json" );