From e1ffd6341de51a35dbb7ebd44de60e48289595de Mon Sep 17 00:00:00 2001 From: lashanfaliq95 Date: Fri, 13 Jul 2018 17:50:39 +0530 Subject: [PATCH] filter implementation which gets all records and based on the timestamp --- .../api/DeviceEventManagementService.java | 4 ++-- .../DeviceEventManagementServiceImpl.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java index 449df8e8f5..26904a9cdf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java @@ -352,9 +352,9 @@ public interface DeviceEventManagementService { @ApiParam(name = "type", value = "name of the parameter", required = true) @PathParam("type") String parameter, @ApiParam(name = "limit", value = "minimum value the parameter can have", required = false) - @QueryParam("min") int min, + @QueryParam("min") double min, @ApiParam(name = "max", value = "max value the parameter can have", required = false) - @QueryParam("max") int max + @QueryParam("max") double max ); 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 b166c7127b..ed85576713 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 @@ -55,10 +55,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * This is used for device type integration with DAS, to create streams and receiver dynamically and a common endpoint @@ -443,14 +440,14 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe @Path("filter/{type}/{parameter}") @Override public Response getFilteredDevices(@PathParam("type") String deviceType, @PathParam("parameter") String parameter, - @QueryParam("min") int min, @QueryParam("max") int max) { + @QueryParam("min") double min, @QueryParam("max") double max) { String query; if (min != 0 & max != 0) { query = parameter + " : [" + min + " TO " + max + "]"; } else if (min != 0 & max == 0) { - query = parameter + " : [" + min + " TO " + max + "]"; + query = parameter + " : [ " + min + " TO *]"; } else if (max != 0 & min == 0) { - query = parameter + " : [" + min + " TO " + max + "]"; + query = parameter + " : [* TO " + max + "]"; } else { String errorMessage = "One of the range values need to be given"; log.error(errorMessage); @@ -471,7 +468,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC); sortByFields.add(sortByField); - EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1); + EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 100); List filterdEvents = eventRecords.getRecord(); List uniqueFilterdEvents = new ArrayList(); @@ -480,13 +477,16 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe for (int i = 0; i < filterdEvents.size(); i++) { String deviceid = (String) filterdEvents.get(i).getValue("meta_deviceId"); - if (!devices.contains(deviceid)) { + 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)) { devices.add(deviceid); uniqueFilterdEvents.add(filterdEvents.get(i)); } } - EventRecords filterdRecords=new EventRecords(); + EventRecords filterdRecords = new EventRecords(); filterdRecords.setList(uniqueFilterdEvents); return Response.status(Response.Status.OK.getStatusCode()).entity(filterdRecords).build();