Update delete device api

APiTesting
Akeela Azhar 2 years ago
parent 724057f841
commit db56b8216d

@ -133,6 +133,32 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
private static final String SPREADSHEET_ID = "1OZCS5NRwwSum9ai3ra4lABtU0UGW-9yLYgZk-aQfxpw";
private static final String RANGE = "Sheet1!A:B";
/**
* Validate group Id and group Id greater than 0 and exist.
*
* @param groupId Group ID of the group
* @param from time to start getting DeviceLocationHistorySnapshotWrapper in milliseconds
* @param to time to end getting DeviceLocationHistorySnapshotWrapper in milliseconds
*/
private static void validateGroupId(int groupId, long from, long to) throws GroupManagementException, BadRequestException {
if (from == 0 || to == 0) {
String msg = "Invalid values for from/to";
log.error(msg);
throw new BadRequestException(msg);
}
if (groupId <= 0) {
String msg = "Invalid group ID '" + groupId + "'";
log.error(msg);
throw new BadRequestException(msg);
}
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
if (service.getGroup(groupId, false) == null) {
String msg = "Invalid group ID '" + groupId + "'";
log.error(msg);
throw new BadRequestException(msg);
}
}
@GET
@Path("/{type}/{id}/status")
@Override
@ -356,32 +382,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
}
/**
* Validate group Id and group Id greater than 0 and exist.
*
* @param groupId Group ID of the group
* @param from time to start getting DeviceLocationHistorySnapshotWrapper in milliseconds
* @param to time to end getting DeviceLocationHistorySnapshotWrapper in milliseconds
*/
private static void validateGroupId(int groupId, long from, long to) throws GroupManagementException, BadRequestException {
if (from == 0 || to == 0) {
String msg = "Invalid values for from/to";
log.error(msg);
throw new BadRequestException(msg);
}
if (groupId <= 0) {
String msg = "Invalid group ID '" + groupId + "'";
log.error(msg);
throw new BadRequestException(msg);
}
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
if (service.getGroup(groupId, false) == null) {
String msg = "Invalid group ID '" + groupId + "'";
log.error(msg);
throw new BadRequestException(msg);
}
}
@GET
@Override
@Path("/{groupId}/location-history")
@ -480,6 +480,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
saveResponseTimeToGoogleSheet(responseTime); // Save response time to Google Sheet
if (response) {
String successMessage = "Device of type '" + deviceType + "' with ID '" + deviceId + "' has been deleted.";
System.out.println(successMessage); // Print success message
}
return Response.status(Response.Status.OK).entity(response).build();
} catch (DeviceManagementException e) {
String msg = "Error encountered while deleting requested device of type : " + deviceType;

Loading…
Cancel
Save