1
package org.hisp.dhis.web.webservice.resources;
3
import java.util.ArrayList;
4
import java.util.Collection;
7
import javax.ws.rs.GET;
8
import javax.ws.rs.Path;
9
import javax.ws.rs.PathParam;
10
import javax.ws.rs.Produces;
12
import org.hisp.dhis.organisationunit.OrganisationUnit;
13
import org.hisp.dhis.web.webservice.model.OrgUnitIdentifier;
14
import org.hisp.dhis.web.webservice.service.DataService;
15
import org.springframework.beans.factory.annotation.Autowired;
17
* Resource for providing the Organisation units (Name, Id) to a mobile client.
18
* @author Kristian Haga Karstensen <kristhk@ifi.uio.no>
22
public class MobileOrgUnitResource {
29
* Returns a mobile-friendly list of the root org units (OrgUnitIdentifiers)
31
@Produces("text/html")
33
public String getMobileOrgUnitRoot() {
34
Collection<OrganisationUnit> orgUnits = ds.getRootOrgUnits();
35
List<OrgUnitIdentifier> mobileOrgUnits = new ArrayList<OrgUnitIdentifier>();
36
for (OrganisationUnit ou : orgUnits) {
37
mobileOrgUnits.add(new OrgUnitIdentifier(ou.getId(), ou.getName()));
40
/* Return the org units as some sort of list */
42
for (OrgUnitIdentifier ouId : mobileOrgUnits) {
43
result +=ouId.getId()+", "+ouId.getName()+" \n";
48
@Produces("text/html")
51
public String getMobileOrgUnitChildren(@PathParam("id") String id) {
52
Collection<OrganisationUnit> orgUnits = ds.getChildrenFromOrgUnit(Integer.parseInt(id));
53
List<OrgUnitIdentifier> mobileOrgUnits = new ArrayList<OrgUnitIdentifier>();
55
for(OrganisationUnit ou : orgUnits) {
56
mobileOrgUnits.add(new OrgUnitIdentifier(ou.getId(),ou.getName()));
60
for (OrgUnitIdentifier ouId : mobileOrgUnits) {
61
result += ouId.getId()+", "+ouId.getName()+" \n";