|
|
@ -3606,37 +3606,45 @@ 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Device> devices = getAllDevices(deviceTypeName, false);
|
|
|
|
|
|
|
|
if (devices == null || devices.isEmpty()) {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("No devices found for the device type: " + deviceTypeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Device> devices = getAllDevices(deviceTypeName, false);
|
|
|
|
} else {
|
|
|
|
if (devices == null || devices.isEmpty()) {
|
|
|
|
// dis-enroll devices
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
disEnrollDevices(devices);
|
|
|
|
log.debug("No devices found for the device type: " + deviceTypeName);
|
|
|
|
// delete devices
|
|
|
|
|
|
|
|
deviceIdentifiers = devices.stream()
|
|
|
|
|
|
|
|
.map(Device::getDeviceIdentifier).collect(Collectors.toList());
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if(!deleteDevices(deviceIdentifiers)){
|
|
|
|
|
|
|
|
log.error("Failed to delete devices of device type: " + deviceTypeName);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
// dis-enroll devices
|
|
|
|
String msg = "Error occurred while deleting devices of type: " + deviceTypeName;
|
|
|
|
disEnrollDevices(devices);
|
|
|
|
log.error(msg);
|
|
|
|
// delete devices
|
|
|
|
throw new DeviceManagementException(msg, e);
|
|
|
|
deviceIdentifiers = devices.stream()
|
|
|
|
|
|
|
|
.map(Device::getDeviceIdentifier).collect(Collectors.toList());
|
|
|
|
|
|
|
|
deleteDevices(deviceIdentifiers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove device type versions
|
|
|
|
|
|
|
|
if (!deleteDeviceTypeVersions(deviceType)){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove device type versions
|
|
|
|
|
|
|
|
if (!deleteDeviceTypeVersions(deviceType)) {
|
|
|
|
|
|
|
|
log.error("Failed to delete device type vesions for device type: " + deviceTypeName);
|
|
|
|
|
|
|
|
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;
|
|
|
|