From fb3da8c94d0f890523dee9b7c0f702a2b4eda44a Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 8 Oct 2020 17:14:00 +0530 Subject: [PATCH] Fixes for device enrollment status change issues --- .../mgt/dao/impl/GenericOperationDAOImpl.java | 1 + .../DeviceManagementProviderService.java | 1 - .../DeviceManagementProviderServiceImpl.java | 22 +++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index fe26b7677b..37984c8709 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -674,6 +674,7 @@ public class GenericOperationDAOImpl implements OperationDAO { while (rs.next()) { if (enrolmentId == 0) { activity = new Activity(); + activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); 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 b63b109533..2fb5ce6f3e 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 @@ -73,7 +73,6 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.core.geo.GeoCluster; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; -import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import java.sql.SQLException; import java.util.Date; 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 b5333d9677..2afa4bbdb6 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 @@ -2747,14 +2747,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (EnrolmentInfo.Status.REMOVED == newStatus) { isDeviceUpdated = disenrollDevice(deviceIdentifier); } else { - enrolmentInfo = device.getEnrolmentInfo(); - if (enrolmentInfo.getStatus() != newStatus) { - enrolmentInfo.setStatus(newStatus); - isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId); - } else { - isDeviceUpdated = false; - } + enrolmentInfo.setStatus(newStatus); + isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId); } + this.removeDeviceFromCache(deviceIdentifier); return isDeviceUpdated; } @@ -2790,15 +2786,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } boolean isUpdatedEnrollment = false; try { - DeviceManagementDAOFactory.openConnection(); + DeviceManagementDAOFactory.beginTransaction(); int updatedRows = enrollmentDAO.updateEnrollment(enrolmentInfo, tenantId); + DeviceManagementDAOFactory.commitTransaction(); if (updatedRows > 0) { isUpdatedEnrollment = true; } - } catch (SQLException e) { - String msg = "Error occurred while opening a connection to the data source"; - log.error(msg, e); - throw new DeviceManagementException(msg, e); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while updating the enrollment information device for" + @@ -3321,6 +3314,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.beginTransaction(); success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, getTenantId(), deviceList); DeviceManagementDAOFactory.commitTransaction(); + if (success) { + for (String id : deviceList) { + this.removeDeviceFromCache(new DeviceIdentifier(id, deviceType)); + } + } } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + status;