Complete implementation of device type permanent delete

This service will do following modifications to achieve it's functionality,
 1. Dis-enroll and delete all devices of a device type
 2. Remove platform configuration of a device type
 3. Delete the device type
feature/appm-store/pbac
Yohan Avishke 5 years ago
parent 2e62acfafc
commit 3f9dba9356

@ -169,7 +169,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementProviderService deviceManagementProviderService =
DeviceMgtAPIUtils.getDeviceManagementService(); DeviceMgtAPIUtils.getDeviceManagementService();
try { try {
if (!deviceManagementProviderService.deleteDevices(deviceIdentifiers, false)) { if (!deviceManagementProviderService.deleteDevices(deviceIdentifiers)) {
String msg = "Found un-deployed device type."; String msg = "Found un-deployed device type.";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(

@ -611,7 +611,7 @@ public interface DeviceManagementProviderService {
boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
boolean deleteDevices(List<String> deviceIdentifiers, boolean transactionAlreadyExists) throws DeviceManagementException, InvalidDeviceException; boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException;
boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
@ -773,11 +773,11 @@ public interface DeviceManagementProviderService {
DeviceManagementException; DeviceManagementException;
/** /**
* Permanently delete a device type * Permanently delete a device type with all it's devices
* *
* @param deviceTypeName device type name * @param deviceTypeName device type name
* @return True if device type successfully removed * @return True if device type successfully removed
* @throws DeviceManagementException * @throws DeviceManagementException Will be thrown if any service level or DAO level error occurs
*/ */
boolean deleteDeviceType(String deviceTypeName) throws DeviceManagementException; boolean deleteDeviceType(String deviceTypeName) throws DeviceManagementException;

@ -3630,22 +3630,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
deviceIdentifiers.add(device.getDeviceIdentifier()); deviceIdentifiers.add(device.getDeviceIdentifier());
} }
DeviceManagementDAOFactory.commitTransaction();
DeviceManagementDAOFactory.closeConnection();
// delete devices // delete devices
deleteDevices(deviceIdentifiers, true); deleteDevices(deviceIdentifiers);
DeviceManagementDAOFactory.beginTransaction();
} }
// remove device type versions // remove device type versions
deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions( deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions(deviceTypeObj.getId(), deviceTypeName);
deviceTypeObj.getId(), deviceTypeName);
if (deviceTypeVersions.isEmpty()) { if (deviceTypeVersions.isEmpty()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device 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(deviceTypeObj.getId()
, deviceTypeVersion.getVersionName(), tenantId); , deviceTypeVersion.getVersionName(), tenantId);
if (!result) { if (!result) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Device type of: " + deviceTypeName + "is unauthorized to modify " + String msg = "Device type of: " + deviceTypeName + "is unauthorized to modify " +
"version"; "version";
log.error(msg); log.error(msg);
@ -3653,7 +3654,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
result = deviceTypeDAO.updateDeviceTypeVersion(deviceTypeVersion); result = deviceTypeDAO.updateDeviceTypeVersion(deviceTypeVersion);
if (!result) { if (!result) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Could not delete the version of device type: " + String msg = "Could not delete the version of device type: " +
deviceTypeName; deviceTypeName;
log.error(msg); log.error(msg);

Loading…
Cancel
Save