From be1bee9b9ada8b00d5c95389a935c69fc24c7544 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Thu, 30 May 2019 18:21:28 +0530 Subject: [PATCH] Modify delete device API to have permanentDelete query parameter --- .../jaxrs/service/api/DeviceManagementService.java | 7 ++++++- .../service/impl/DeviceManagementServiceImpl.java | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 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 db0902ee36..96991ed2ce 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 @@ -899,7 +899,12 @@ public interface DeviceManagementService { required = true) @PathParam("device-id") @Size(max = 45) - String deviceId); + String deviceId, + @ApiParam( + name = "permanentDelete", + value = "Boolean flag indicating whether to permanently delete the device.", + required = false) + @QueryParam("permanentDelete") boolean permanentDelete); @GET @Path("/{type}/{id}/features") 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 b679323f97..9175580ce9 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 @@ -323,7 +323,9 @@ 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) { + public Response deleteDevice(@PathParam("device-type") String deviceType, + @PathParam("device-id") String deviceId, + @QueryParam("permanentDelete") boolean permanentDelete) { DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); try { @@ -333,13 +335,19 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.NOT_FOUND).build(); } - boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier); + boolean response; + + if (permanentDelete) { + response = deviceManagementProviderService.deleteDevice(deviceIdentifier); + } else { + response = deviceManagementProviderService.disenrollDevice(deviceIdentifier); + } return Response.status(Response.Status.OK).entity(response).build(); } catch (DeviceManagementException e) { String msg = "Error encountered while deleting device of type : " + deviceType + " and " + "ID : " + deviceId; - log.error(msg); + log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build() ).build();