dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32134
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16418: Web API for getting organisation unit parents list
------------------------------------------------------------
revno: 16418
committer: James Chang <jamesbchang@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-08-15 22:23:25 +0700
message:
Web API for getting organisation unit parents list
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-08-07 09:15:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java 2014-08-15 15:23:25 +0000
@@ -28,7 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -41,11 +48,13 @@
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import com.google.common.collect.Lists;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -195,4 +204,41 @@
return organisationUnits;
}
+
+ @RequestMapping( value = "/{uid}/parents", method = RequestMethod.GET )
+ public List<OrganisationUnit> getEntityList( @PathVariable( "uid" ) String uid
+ , @RequestParam Map<String, String> parameters
+ , Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ {
+ OrganisationUnit organisationUnit = manager.get( getEntityClass(), uid );
+
+ List<OrganisationUnit> organisationUnits = Lists.newArrayList();
+
+ // Add organisation unit parents
+ if ( organisationUnits != null )
+ {
+ OrganisationUnit organisationUnitParent = organisationUnit.getParent();
+
+ while ( organisationUnitParent != null )
+ {
+ organisationUnits.add( organisationUnitParent );
+ organisationUnitParent = organisationUnitParent.getParent();
+ }
+ }
+ else
+ {
+ organisationUnits = Lists.newArrayList();
+ }
+
+ WebMetaData metaData = new WebMetaData();
+ metaData.setOrganisationUnits( organisationUnits );
+ WebOptions options = new WebOptions(parameters);
+
+ model.addAttribute( "model", metaData );
+ model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
+
+ return organisationUnits;
+ }
+
+
}