From 34354c032e46fbd1f7ab16a6e0f6fbe8f783f20e Mon Sep 17 00:00:00 2001 From: madhawap Date: Thu, 7 Jul 2016 19:46:22 +0530 Subject: [PATCH] Added end-point to get devices enrolled under a specific user --- .../impl/DeviceManagementServiceImpl.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 50f60c92b1..fc004bbc7a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; @@ -144,6 +145,32 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } + @GET + @Path("/user-devices") + public Response getDeviceByUser(@QueryParam("offset") int offset, + @QueryParam("limit") int limit) { + + PaginationRequest request = new PaginationRequest(offset, limit); + PaginationResult result; + DeviceList devices = new DeviceList(); + + String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); + request.setOwner(currentUser); + + try { + result = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(request); + devices.setList((List) result.getData()); + devices.setCount(result.getRecordsTotal()); + return Response.status(Response.Status.OK).entity(devices).build(); + } catch (DeviceManagementException e) { + String msg = "Error occurred while fetching all enrolled devices"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } + + @GET @Path("/{type}/{id}") @Override