From f85224f4ad620b9fb3a280273ebe1ffa40ea3ad7 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Thu, 8 Oct 2020 20:00:20 +0530 Subject: [PATCH] Update device cache if the device status has updated and the device info has updated --- .../task/impl/DeviceStatusMonitoringTask.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java index f2deae4810..71cc06a6d1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java @@ -25,13 +25,16 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskException; import org.wso2.carbon.ntask.core.Task; @@ -98,6 +101,19 @@ public class DeviceStatusMonitoringTask implements Task { enrolmentInfo.setId(mapping.getEnrolmentId()); enrolmentInfo.setStatus(newStatus); } else { + DeviceManagementProviderService dmps = DeviceManagementDataHolder.getInstance() + .getDeviceManagementProvider(); + try { + Device updatedDevice = dmps + .getDevice(device.getDeviceIdentifier(), device.getDeviceInfo().getUpdatedTime(), true); + if (updatedDevice != null) { + device = updatedDevice; + } + } catch (DeviceManagementException e) { + log.error( + "Error occurred while getting the updated device information which has device identifier: " + + device.getDeviceIdentifier()); + } enrolmentInfo = device.getEnrolmentInfo(); enrolmentInfo.setStatus(newStatus); device.setEnrolmentInfo(enrolmentInfo);