Updated the last-known api to be able to return a number of records.

revert-70aa11f8
lashanfaliq95 7 years ago
parent c0615fee83
commit 65cfca7024

@ -290,7 +290,11 @@ public interface DeviceEventManagementService {
Response getLastKnownData(@ApiParam(name = "deviceId", value = "id of the device ", required = false) Response getLastKnownData(@ApiParam(name = "deviceId", value = "id of the device ", required = false)
@PathParam("deviceId") String deviceId, @PathParam("deviceId") String deviceId,
@ApiParam(name = "type", value = "name of the device type", required = false) @ApiParam(name = "type", value = "name of the device type", required = false)
@PathParam("type") String deviceType); @PathParam("type") String deviceType,
@ApiParam(name = "limit", value = "limit of the records that needs to be picked up", required = false)
@QueryParam("limit") int limit);
@GET @GET
@Path("/{type}") @Path("/{type}")

@ -340,12 +340,12 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
} }
/** /**
* Returns the last know data point of the device type. * Returns the last know data point of the device type or last known data points upto the limit.
*/ */
@GET @GET
@Path("/last-known/{type}/{deviceId}") @Path("/last-known/{type}/{deviceId}")
@Override @Override
public Response getLastKnownData(@PathParam("deviceId") String deviceId, @PathParam("type") String deviceType) { public Response getLastKnownData(@PathParam("deviceId") String deviceId, @PathParam("type") String deviceType,@QueryParam("limit") int limit) {
String query = DEFAULT_META_DEVICE_ID_ATTRIBUTE + ":" + deviceId; String query = DEFAULT_META_DEVICE_ID_ATTRIBUTE + ":" + deviceId;
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String sensorTableName = getTableName(DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain)); String sensorTableName = getTableName(DeviceMgtAPIUtils.getStreamDefinition(deviceType, tenantDomain));
@ -363,8 +363,13 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
List<SortByField> sortByFields = new ArrayList<>(); List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC); SortByField sortByField = new SortByField(TIMESTAMP_FIELD_NAME, SortType.DESC);
sortByFields.add(sortByField); sortByFields.add(sortByField);
if(limit == 0){
EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1); EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, 1);
return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build(); return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();}
else{
EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, limit);
return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
}
} catch (AnalyticsException e) { } catch (AnalyticsException e) {
String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query; String errorMsg = "Error on retrieving stats on table " + sensorTableName + " with query " + query;
log.error(errorMsg); log.error(errorMsg);
@ -379,6 +384,7 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe
} }
} }
private void publishEventReceivers(String streamNameWithVersion, TransportType transportType private void publishEventReceivers(String streamNameWithVersion, TransportType transportType
, String requestedTenantDomain, String deviceType) , String requestedTenantDomain, String deviceType)
throws RemoteException, UserStoreException, JWTClientException { throws RemoteException, UserStoreException, JWTClientException {

Loading…
Cancel
Save