Search in sources :

Example 1 with OrgUnits

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

the class OrgUnitsTest method testSerialization.

@Test
public void testSerialization() throws IOException {
    MobileOrgUnitLinks unit = createOrgUnit();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    OrgUnits units = new OrgUnits();
    units.setOrgUnits(Arrays.asList(new MobileOrgUnitLinks[] { unit }));
    units.serializeVersion2_10(dos);
    dos.flush();
    OrgUnits units2 = new OrgUnits();
    units2.deSerialize(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
    List<MobileOrgUnitLinks> unitList = units2.getOrgUnits();
    assertEquals(1, unitList.size());
    MobileOrgUnitLinks unit2 = unitList.get(0);
    assertEquals(unit.getName(), unit2.getName());
    assertEquals(unit.getId(), unit2.getId());
}
Also used : MobileOrgUnitLinks(org.hisp.dhis.api.mobile.model.MobileOrgUnitLinks) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OrgUnits(org.hisp.dhis.api.mobile.model.OrgUnits) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 2 with OrgUnits

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

the class MobileClientController method getOrgUnitsForUser2_8.

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public OrgUnits getOrgUnitsForUser2_8(HttpServletRequest request) 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(DataStreamSerializable.TWO_POINT_EIGHT);
    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)

Example 3 with OrgUnits

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

the class MobileClientController method getOrgUnitsForUserLWUIT.

@RequestMapping(method = RequestMethod.GET, value = "/{version}/LWUIT")
@ResponseBody
public org.hisp.dhis.api.mobile.model.LWUITmodel.OrgUnits getOrgUnitsForUserLWUIT(HttpServletRequest request, @PathVariable String version) throws NotAllowedException {
    User user = currentUserService.getCurrentUser();
    if (user == null) {
        throw NotAllowedException.NO_USER;
    }
    Collection<OrganisationUnit> units = user.getOrganisationUnits();
    List<org.hisp.dhis.api.mobile.model.LWUITmodel.MobileOrgUnitLinks> unitList = new ArrayList<>();
    for (OrganisationUnit unit : units) {
        unitList.add(getTrackerOrgUnit(unit, request));
    }
    org.hisp.dhis.api.mobile.model.LWUITmodel.OrgUnits orgUnits = new org.hisp.dhis.api.mobile.model.LWUITmodel.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)

Example 4 with OrgUnits

use of org.hisp.dhis.api.mobile.model.OrgUnits 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)4 OrgUnits (org.hisp.dhis.api.mobile.model.OrgUnits)4 ArrayList (java.util.ArrayList)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 User (org.hisp.dhis.user.User)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Test (org.junit.Test)1