|
|
@ -3589,25 +3589,20 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteDeviceType(String deviceTypeName) throws DeviceManagementException {
|
|
|
|
public boolean deleteDeviceType(String deviceTypeName, DeviceType deviceType)
|
|
|
|
int tenantId = getTenantId();
|
|
|
|
throws DeviceManagementException {
|
|
|
|
List<String> deviceIdentifiers;
|
|
|
|
List<String> deviceIdentifiers;
|
|
|
|
List<DeviceTypeVersion> deviceTypeVersions;
|
|
|
|
List<DeviceTypeVersion> deviceTypeVersions;
|
|
|
|
boolean result;
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
int tenantId = getTenantId();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (deviceTypeName.isEmpty()) {
|
|
|
|
if (deviceTypeName.isEmpty() || deviceType == null) {
|
|
|
|
String msg = "Error, device type cannot be null or empty";
|
|
|
|
String msg = "Error, device type cannot be null or empty";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
DeviceType deviceTypeObj = deviceTypeDAO.getDeviceType(deviceTypeName, tenantId);
|
|
|
|
|
|
|
|
if (deviceTypeObj == null) {
|
|
|
|
|
|
|
|
String msg = "Error, device of type: " + deviceTypeName + " does not exist";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Device> devices = deviceDAO.getDevices(deviceTypeName, this.getTenantId());
|
|
|
|
List<Device> devices = deviceDAO.getDevices(deviceTypeName, this.getTenantId());
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -3637,14 +3632,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// remove device type versions
|
|
|
|
// remove device type versions
|
|
|
|
deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions(deviceTypeObj.getId(), deviceTypeName);
|
|
|
|
deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions(deviceType.getId(), deviceTypeName);
|
|
|
|
if (deviceTypeVersions.isEmpty()) {
|
|
|
|
if (deviceTypeVersions.isEmpty()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Device of type: " + deviceTypeName + "doesn't have any type versions");
|
|
|
|
log.debug("Device of type: " + deviceTypeName + "doesn't have any type versions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (DeviceTypeVersion deviceTypeVersion : deviceTypeVersions) {
|
|
|
|
for (DeviceTypeVersion deviceTypeVersion : deviceTypeVersions) {
|
|
|
|
result = deviceTypeDAO.isDeviceTypeVersionModifiable(deviceTypeObj.getId()
|
|
|
|
result = deviceTypeDAO.isDeviceTypeVersionModifiable(deviceType.getId()
|
|
|
|
, deviceTypeVersion.getVersionName(), tenantId);
|
|
|
|
, deviceTypeVersion.getVersionName(), tenantId);
|
|
|
|
if (!result) {
|
|
|
|
if (!result) {
|
|
|
|
String msg = "Device type of: " + deviceTypeName + "is unauthorized to modify " +
|
|
|
|
String msg = "Device type of: " + deviceTypeName + "is unauthorized to modify " +
|
|
|
@ -3662,7 +3657,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete device type
|
|
|
|
// delete device type
|
|
|
|
deviceTypeDAO.deleteDeviceType(tenantId, deviceTypeObj.getId());
|
|
|
|
deviceTypeDAO.deleteDeviceType(tenantId, deviceType.getId());
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
String msg = "Error occurred while deleting devices of type: " + deviceTypeName;
|
|
|
|
String msg = "Error occurred while deleting devices of type: " + deviceTypeName;
|
|
|
|