From eb20d1fc1c1a3a607bc24aef1f2fd767c97fc473 Mon Sep 17 00:00:00 2001 From: susinda Date: Thu, 13 Oct 2016 12:02:00 +0530 Subject: [PATCH] Device delete implemented (only in api level) for iot --- .../service/api/DeviceManagementService.java | 66 +++++++++++++++++++ .../impl/DeviceManagementServiceImpl.java | 14 ++++ 2 files changed, 80 insertions(+) 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 5c7b7e710d6..de032b83c7a 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 @@ -230,6 +230,72 @@ public interface DeviceManagementService { @HeaderParam("If-Modified-Since") String ifModifiedSince); + //device delete request would looks like follows + //DELETE devices/type/virtual_firealarm/id/us06ww93auzp + @DELETE + @Path("/type/{device-type}/id/{device-id}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "DELETE", + value = "Delete the device speccified by device id", + notes = "Returns the status of the deleted device operation.", + tags = "Device Management") + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched information of the device.", + response = Device.class, + 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 = 304, + message = "Not Modified. 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.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n No device is found under the provided type and id.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving information requested device.", + response = ErrorResponse.class) + }) + //TODO need to introduce delete permission + @Permission(name = "View Devices", permission = "/device-mgt/devices/owning-device/view") + Response deleteDevice( + @ApiParam( + name = "device-type", + value = "The device type, such as ios, android or windows.", + required = true) + @PathParam("device-type") + @Size(max = 45) + String deviceType, + @ApiParam( + name = "device-id", + value = "The device identifier of the device.", + required = true) + @PathParam("device-id") + @Size(max = 45) + String deviceId); + + @GET @Path("/{type}/{id}/features") @ApiOperation( 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 fa4e20d85ff..ccea8d9bd4d 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 @@ -216,6 +216,20 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } } + @DELETE + @Override + @Path("/type/{device-type}/id/{device-id}") + public Response deleteDevice(@PathParam("device-type") String deviceType, @PathParam("device-id") String deviceId) { + + log.info("Deleting " + deviceType + " " + deviceId + "is not supported"); + try { + return Response.status(Response.Status.BAD_REQUEST).entity("{Deleting device(s) is not supported}").build(); + } catch (Exception e) { + String msg = "Error occurred while deleting device(s)"; + log.error(msg, e); + return Response.serverError().entity(new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } @GET @Path("/{type}/{id}")