From 3f9dba93568fcf03f5f1aff3036da60b34f0c531 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Wed, 18 Dec 2019 14:24:14 +0530 Subject: [PATCH] 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 --- .../impl/admin/DeviceManagementAdminServiceImpl.java | 2 +- .../service/DeviceManagementProviderService.java | 6 +++--- .../service/DeviceManagementProviderServiceImpl.java | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 360a41679f..9533c43a42 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -169,7 +169,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService(); try { - if (!deviceManagementProviderService.deleteDevices(deviceIdentifiers, false)) { + if (!deviceManagementProviderService.deleteDevices(deviceIdentifiers)) { String msg = "Found un-deployed device type."; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index cdc5379ea7..9246d2fc97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -611,7 +611,7 @@ public interface DeviceManagementProviderService { boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - boolean deleteDevices(List deviceIdentifiers, boolean transactionAlreadyExists) throws DeviceManagementException, InvalidDeviceException; + boolean deleteDevices(List deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException; boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; @@ -773,11 +773,11 @@ public interface DeviceManagementProviderService { DeviceManagementException; /** - * Permanently delete a device type + * Permanently delete a device type with all it's devices * * @param deviceTypeName device type name * @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; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a823a76bfb..b7190c03aa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -3630,22 +3630,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } deviceIdentifiers.add(device.getDeviceIdentifier()); } + DeviceManagementDAOFactory.commitTransaction(); + DeviceManagementDAOFactory.closeConnection(); // delete devices - deleteDevices(deviceIdentifiers, true); + deleteDevices(deviceIdentifiers); + DeviceManagementDAOFactory.beginTransaction(); } // remove device type versions - deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions( - deviceTypeObj.getId(), deviceTypeName); + deviceTypeVersions = deviceTypeDAO.getDeviceTypeVersions(deviceTypeObj.getId(), deviceTypeName); if (deviceTypeVersions.isEmpty()) { 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 { for (DeviceTypeVersion deviceTypeVersion : deviceTypeVersions) { result = deviceTypeDAO.isDeviceTypeVersionModifiable(deviceTypeObj.getId() , deviceTypeVersion.getVersionName(), tenantId); if (!result) { - DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Device type of: " + deviceTypeName + "is unauthorized to modify " + "version"; log.error(msg); @@ -3653,7 +3654,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } result = deviceTypeDAO.updateDeviceTypeVersion(deviceTypeVersion); if (!result) { - DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Could not delete the version of device type: " + deviceTypeName; log.error(msg);