Change try catch positions and add error messages to required positions

merge-requests/418/head
Yohan Avishke 5 years ago
parent 4a70d8e17d
commit 4378feedde

@ -3606,9 +3606,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
throws DeviceManagementException {
List<String> deviceIdentifiers;
try {
if (deviceType == null || deviceTypeName == null || deviceTypeName.isEmpty()) {
String msg = "Error, device type cannot be null or empty";
if (deviceType == null || StringUtils.isBlank(deviceTypeName)) {
String msg = "Error, device type cannot be null or empty or a blank space";
log.error(msg);
return false;
}
@ -3623,20 +3622,29 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
// delete devices
deviceIdentifiers = devices.stream()
.map(Device::getDeviceIdentifier).collect(Collectors.toList());
deleteDevices(deviceIdentifiers);
try {
if(!deleteDevices(deviceIdentifiers)){
log.error("Failed to delete devices of device type: " + deviceTypeName);
return false;
}
} catch (InvalidDeviceException e) {
String msg = "Error occurred while deleting devices of type: " + deviceTypeName;
log.error(msg);
throw new DeviceManagementException(msg, e);
}
}
// remove device type versions
if (!deleteDeviceTypeVersions(deviceType)){
if (!deleteDeviceTypeVersions(deviceType)) {
log.error("Failed to delete device type vesions for device type: " + deviceTypeName);
return false;
}
try {
// delete device type
DeviceManagementDAOFactory.beginTransaction();
deviceTypeDAO.deleteDeviceType(getTenantId(), deviceType.getId());
DeviceManagementDAOFactory.commitTransaction();
} catch (InvalidDeviceException e) {
String msg = "Error occurred while deleting devices of type: " + deviceTypeName;
log.error(msg);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while deleting device type of: " + deviceTypeName;

Loading…
Cancel
Save