Search in sources :

Example 6 with MobileOrgUnitLinks

use of org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks in project dhis2-core by dhis2.

the class MobileClientController method getOrgUnitsForUser.

@RequestMapping(method = RequestMethod.GET, value = "/{version:.+}")
@ResponseBody
public OrgUnits getOrgUnitsForUser(HttpServletRequest request, @PathVariable String version) throws NotAllowedException {
    User user = currentUserService.getCurrentUser();
    if (user == null) {
        throw NotAllowedException.NO_USER;
    }
    Collection<OrganisationUnit> units = user.getOrganisationUnits();
    List<MobileOrgUnitLinks> unitList = new ArrayList<>();
    for (OrganisationUnit unit : units) {
        unitList.add(getOrgUnit(unit, request));
    }
    OrgUnits orgUnits = new OrgUnits(unitList);
    orgUnits.setClientVersion(version);
    return orgUnits;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MobileOrgUnitLinks(org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) OrgUnits(org.hisp.dhis.api.mobile.model.OrgUnits) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MobileOrgUnitLinks (org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks)6 OrgUnits (org.hisp.dhis.api.mobile.model.OrgUnits)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 ArrayList (java.util.ArrayList)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2