|
|
@ -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();}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
EventRecords eventRecords = getAllEventsForDevice(sensorTableName, query, sortByFields, 0, limit);
|
|
|
|
return Response.status(Response.Status.OK.getStatusCode()).entity(eventRecords).build();
|
|
|
|
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 {
|
|
|
|