From 9871122c0a3cb1f0065903585963802f221aae5c Mon Sep 17 00:00:00 2001 From: Harshan Liyanage Date: Fri, 2 Jun 2017 15:36:56 +0530 Subject: [PATCH] Code refactoring of device-status-task which Resolves harshanl/product-iots#518 --- .../core/status/task/impl/DeviceStatusMonitoringTask.java | 6 +++--- .../task/impl/DeviceStatusTaskManagerServiceImpl.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) 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 1a35ea4ebc..6bc51da2ba 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 @@ -43,7 +43,7 @@ import java.util.Map; */ public class DeviceStatusMonitoringTask implements Task { - private static Log log = LogFactory.getLog(DeviceStatusMonitoringTask.class); + private static final Log log = LogFactory.getLog(DeviceStatusMonitoringTask.class); private String deviceType; private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private int deviceTypeId = -1; @@ -70,7 +70,7 @@ public class DeviceStatusMonitoringTask implements Task { EnrolmentInfo enrolmentInfo; try { operationEnrolmentMappings = this.getOperationEnrolmentMappings(); - if (operationEnrolmentMappings.size() > 0) { + if (operationEnrolmentMappings != null && operationEnrolmentMappings.size() > 0) { lastActivities = this.getLastDeviceActivities(); } } catch (DeviceStatusTaskException e) { @@ -78,7 +78,7 @@ public class DeviceStatusMonitoringTask implements Task { } for (OperationEnrolmentMapping mapping:operationEnrolmentMappings) { long lastActivity = -1; - if (lastActivities.containsKey(mapping.getEnrolmentId())) { + if (lastActivities != null && lastActivities.containsKey(mapping.getEnrolmentId())) { lastActivity = lastActivities.get(mapping.getEnrolmentId()); } EnrolmentInfo.Status newStatus = this.determineDeviceStatus(mapping, lastActivity); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusTaskManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusTaskManagerServiceImpl.java index 682f59317d..988be3f4d0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusTaskManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusTaskManagerServiceImpl.java @@ -39,13 +39,13 @@ import java.util.Map; */ public class DeviceStatusTaskManagerServiceImpl implements DeviceStatusTaskManagerService { - private static Log log = LogFactory.getLog(DeviceStatusTaskManagerServiceImpl.class); + private static final Log log = LogFactory.getLog(DeviceStatusTaskManagerServiceImpl.class); public static final String DEVICE_STATUS_MONITORING_TASK_TYPE = "DEVICE_STATUS_MONITORING"; static final String DEVICE_TYPE = "DEVICE_TYPE"; static final String DEVICE_TYPE_ID = "DEVICE_TYPE_ID"; static final String DEVICE_STATUS_TASK_CONFIG = "DEVICE_STATUS_TASK_CONFIG"; - private static String TASK_CLASS = DeviceStatusMonitoringTask.class.getName(); + private static final String TASK_CLASS = DeviceStatusMonitoringTask.class.getName(); @Override public void startTask(DeviceType deviceType, DeviceStatusTaskPluginConfig deviceStatusTaskConfig)