Change try catch positions and add error messages to required positions

feature/appm-store/pbac
Yohan Avishke 5 years ago
parent 4a70d8e17d
commit 4378feedde

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

Loading…
Cancel
Save