From 25e45dc9f1053c9d0ab2f350898ee33dc1200f58 Mon Sep 17 00:00:00 2001 From: dilanua Date: Wed, 1 Jun 2016 10:44:08 +0530 Subject: [PATCH] Fixing issues in GET /operations and /admin/devices APIs --- .../service/impl/DeviceManagementServiceImpl.java | 4 ++-- .../admin/DeviceManagementAdminServiceImpl.java | 14 +++++++++++--- .../src/main/webapp/META-INF/permissions.xml | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) 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 75e886cb92d..b9e181745a2 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 @@ -326,8 +326,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { dms = DeviceMgtAPIUtils.getDeviceManagementService(); operations = dms.getOperations(new DeviceIdentifier(id, type)); if (operations == null) { - Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " + - "the provided type and id"); + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " + + "the provided type and id").build(); } } catch (OperationManagementException e) { String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 54140ccada8..6400e598210 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -25,9 +25,11 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnauthorizedAccessException; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.*; @@ -67,11 +69,17 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe return Response.status(Response.Status.NOT_FOUND).entity("No device, which carries the name '" + name + "', is currently enrolled in the system").build(); } - return Response.status(Response.Status.OK).entity(devices).build(); + + DeviceList deviceList = new DeviceList(); + deviceList.setCount(devices.size()); + deviceList.setList(devices); + + return Response.status(Response.Status.OK).entity(deviceList).build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while fetching the devices that carry the name '" + name + "'"; + String msg = "Error occurred at server side while fetching device list."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); } finally { PrivilegedCarbonContext.endTenantFlow(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index 45293bc4a1a..5a9c3f5347d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -394,6 +394,20 @@ GET + + View device + /device-mgt/admin/devices/view + /devices/*/*/operations + GET + + + + View device + /device-mgt/user/devices/view + /devices/*/*/operations + GET + +