Modify delete device API to have permanentDelete query parameter

revert-70aa11f8
Saad Sahibjan 6 years ago
parent c7232bba86
commit be1bee9b9a

@ -899,7 +899,12 @@ public interface DeviceManagementService {
required = true) required = true)
@PathParam("device-id") @PathParam("device-id")
@Size(max = 45) @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 @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")

@ -323,7 +323,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@DELETE @DELETE
@Override @Override
@Path("/type/{device-type}/id/{device-id}") @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 = DeviceManagementProviderService deviceManagementProviderService =
DeviceMgtAPIUtils.getDeviceManagementService(); DeviceMgtAPIUtils.getDeviceManagementService();
try { try {
@ -333,13 +335,19 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.NOT_FOUND).build(); 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(); return Response.status(Response.Status.OK).entity(response).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error encountered while deleting device of type : " + deviceType + " and " + String msg = "Error encountered while deleting device of type : " + deviceType + " and " +
"ID : " + deviceId; "ID : " + deviceId;
log.error(msg); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity( return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build() new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()
).build(); ).build();

Loading…
Cancel
Save