Modify delete device API to have permanentDelete query parameter

merge-requests/118/head
Saad Sahibjan 6 years ago
parent c7232bba86
commit be1bee9b9a

@ -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")

@ -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();

Loading…
Cancel
Save