From e002ffb54ab08e6c4b0ff9081e5288c41ffa6783 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 2 Jun 2016 00:20:14 +0530 Subject: [PATCH] Re-enabling retrieval of device info --- .../service/api/DeviceManagementService.java | 125 +++++++++--------- .../impl/DeviceManagementServiceImpl.java | 45 ++++--- 2 files changed, 85 insertions(+), 85 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 2fad649ab45..9c88e11cd8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -201,69 +201,68 @@ public interface DeviceManagementService { required = false) @HeaderParam("If-Modified-Since") String ifModifiedSince); -// @POST -// @ApiOperation( -// consumes = MediaType.APPLICATION_JSON, -// produces = MediaType.APPLICATION_JSON, -// httpMethod = "POST", -// value = "Retrieve devices information from the supplied device identifies.", -// notes = "This will return device information such as CPU usage, memory usage etc for supplied device " + -// "identifiers.", -// response = DeviceInfo.class, -// responseContainer = "List", -// tags = "Device Management") -// @ApiResponses( -// value = { -// @ApiResponse( -// code = 200, -// message = "OK. \n Information of the submitted list of devices is returned", -// response = DeviceInfo.class, -// responseContainer = "List", -// responseHeaders = { -// @ResponseHeader( -// name = "Content-Type", -// description = "The content type of the body"), -// @ResponseHeader( -// name = "ETag", -// description = "Entity Tag of the response resource.\n" + -// "Used by caches, or in conditional requests."), -// @ResponseHeader( -// name = "Last-Modified", -// description = "Date and time the resource has been modified the last time.\n" + -// "Used by caches, or in conditional requests.")}), -// @ApiResponse( -// code = 303, -// message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", -// responseHeaders = { -// @ResponseHeader( -// name = "Content-Location", -// description = "The Source URL of the document.")}), -// @ApiResponse( -// code = 304, -// message = "Not Modified. \n " + -// "Empty body because the client already has the latest version of the requested resource."), -// @ApiResponse( -// code = 400, -// message = "Bad Request. \n Invalid request or validation error."), -// @ApiResponse( -// code = 406, -// message = "Not Acceptable. \n The requested media type is not supported."), -// @ApiResponse( -// code = 500, -// message = "Internal Server ErrorResponse. \n " + -// "Server error occurred while retrieving information of the list of the devices submitted.") -// }) -// @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) -// Response getDevicesInfo( -// @ApiParam( -// name = "deviceIds", -// value = "List of device identifiers", -// required = true) List deviceIds, -// @ApiParam( -// name = "If-Modified-Since", -// value = "Timestamp of the last modified date", -// required = false) -// @HeaderParam("If-Modified-Since") String timestamp); + @POST + @Path("/get-info") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Retrieve devices information from the supplied device identifies.", + notes = "This will return device information such as CPU usage, memory usage etc for supplied device " + + "identifiers.", + tags = "Device Management") + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Information of the submitted list of devices is returned", + response = DeviceInfo.class, + responseContainer = "List", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 304, + message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 406, + message = "Not Acceptable. \n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server ErrorResponse. \n " + + "Server error occurred while retrieving information of the list of the devices submitted.") + }) + @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) + Response getDevicesInfo( + @ApiParam( + name = "If-Modified-Since", + value = "Timestamp of the last modified date", + required = false) + @HeaderParam("If-Modified-Since") String timestamp, + @ApiParam( + name = "deviceIds", + value = "List of device identifiers", + required = true) List deviceIds); @GET 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 d7065e0878f..04eb20326c4 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 @@ -131,28 +131,29 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } return Response.status(Response.Status.OK).entity(deviceInfo).build(); } -// -// @POST -// @Override -// public Response getDevicesInfo( -// List deviceIds, -// @HeaderParam("If-Modified-Since") String timestamp) { -// DeviceInformationManager informationManager; -// List deviceInfo; -// try { -// informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); -// deviceInfo = informationManager.getDevicesInfo(deviceIds); -// if (deviceInfo == null) { -// return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " + -// "device list submitted").build(); -// } -// } catch (DeviceDetailsMgtException e) { -// String msg = "Error occurred while getting the device information."; -// log.error(msg, e); -// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); -// } -// return Response.status(Response.Status.OK).entity(deviceInfo).build(); -// } + + @POST + @Path("/get-info") + @Override + public Response getDevicesInfo( + @HeaderParam("If-Modified-Since") String timestamp, + List deviceIds) { + DeviceInformationManager informationManager; + List deviceInfo; + try { + informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); + deviceInfo = informationManager.getDevicesInfo(deviceIds); + if (deviceInfo == null) { + return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " + + "device list submitted").build(); + } + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while getting the device information."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + return Response.status(Response.Status.OK).entity(deviceInfo).build(); + } @GET @Path("/{type}/{id}")