Code refactoring of device-status-task which Resolves harshanl/product-iots#518

4.x.x
Harshan Liyanage 8 years ago
parent 52bbdfcd78
commit 9871122c0a

@ -43,7 +43,7 @@ import java.util.Map;
*/ */
public class DeviceStatusMonitoringTask implements Task { 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 String deviceType;
private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
private int deviceTypeId = -1; private int deviceTypeId = -1;
@ -70,7 +70,7 @@ public class DeviceStatusMonitoringTask implements Task {
EnrolmentInfo enrolmentInfo; EnrolmentInfo enrolmentInfo;
try { try {
operationEnrolmentMappings = this.getOperationEnrolmentMappings(); operationEnrolmentMappings = this.getOperationEnrolmentMappings();
if (operationEnrolmentMappings.size() > 0) { if (operationEnrolmentMappings != null && operationEnrolmentMappings.size() > 0) {
lastActivities = this.getLastDeviceActivities(); lastActivities = this.getLastDeviceActivities();
} }
} catch (DeviceStatusTaskException e) { } catch (DeviceStatusTaskException e) {
@ -78,7 +78,7 @@ public class DeviceStatusMonitoringTask implements Task {
} }
for (OperationEnrolmentMapping mapping:operationEnrolmentMappings) { for (OperationEnrolmentMapping mapping:operationEnrolmentMappings) {
long lastActivity = -1; long lastActivity = -1;
if (lastActivities.containsKey(mapping.getEnrolmentId())) { if (lastActivities != null && lastActivities.containsKey(mapping.getEnrolmentId())) {
lastActivity = lastActivities.get(mapping.getEnrolmentId()); lastActivity = lastActivities.get(mapping.getEnrolmentId());
} }
EnrolmentInfo.Status newStatus = this.determineDeviceStatus(mapping, lastActivity); EnrolmentInfo.Status newStatus = this.determineDeviceStatus(mapping, lastActivity);

@ -39,13 +39,13 @@ import java.util.Map;
*/ */
public class DeviceStatusTaskManagerServiceImpl implements DeviceStatusTaskManagerService { 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"; public static final String DEVICE_STATUS_MONITORING_TASK_TYPE = "DEVICE_STATUS_MONITORING";
static final String DEVICE_TYPE = "DEVICE_TYPE"; static final String DEVICE_TYPE = "DEVICE_TYPE";
static final String DEVICE_TYPE_ID = "DEVICE_TYPE_ID"; static final String DEVICE_TYPE_ID = "DEVICE_TYPE_ID";
static final String DEVICE_STATUS_TASK_CONFIG = "DEVICE_STATUS_TASK_CONFIG"; 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 @Override
public void startTask(DeviceType deviceType, DeviceStatusTaskPluginConfig deviceStatusTaskConfig) public void startTask(DeviceType deviceType, DeviceStatusTaskPluginConfig deviceStatusTaskConfig)

Loading…
Cancel
Save