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());
}
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;
}
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;
}
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;
}
Aggregations