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 360a41679f8..9533c43a42a 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 cdc5379ea7d..9246d2fc974 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 a823a76bfb3..b7190c03aa9 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);