From 3a7136abf90c2f066b86f97d62aa40f7059eeb42 Mon Sep 17 00:00:00 2001 From: lashanfaliq95 Date: Sun, 15 Jul 2018 10:58:09 +0530 Subject: [PATCH] complete the event filter --- .../impl/DeviceEventManagementServiceImpl.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index ed85576713..7a627ba9cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -444,12 +444,8 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe String query; if (min != 0 & max != 0) { query = parameter + " : [" + min + " TO " + max + "]"; - } else if (min != 0 & max == 0) { - query = parameter + " : [ " + min + " TO *]"; - } else if (max != 0 & min == 0) { - query = parameter + " : [* TO " + max + "]"; - } else { - String errorMessage = "One of the range values need to be given"; + } else { + String errorMessage = "The of range values need to be given"; log.error(errorMessage); return Response.status(Response.Status.BAD_REQUEST).build(); } @@ -467,17 +463,14 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe List sortByFields = new ArrayList<>(); SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC); sortByFields.add(sortByField); - EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 100); - List filterdEvents = eventRecords.getRecord(); List uniqueFilterdEvents = new ArrayList(); Set devices = new HashSet<>(); for (int i = 0; i < filterdEvents.size(); i++) { - String deviceid = (String) filterdEvents.get(i).getValue("meta_deviceId"); - long timestamp=(long).filterdEvents.get(i).getTimestamp(); + long timestamp=(long)filterdEvents.get(i).getTimestamp(); Calendar c = java.util.Calendar.getInstance(); long currentTimestamp = c.getTimeInMillis(); if (!devices.contains(deviceid) && (currentTimestamp-timestamp<=300*1000)) {