@Override
public DataRecord getLatestDataRecordForChannel(ObjectType objectType, String channelUri)
{
// Create invalid data record.
DataRecord dataRecord = new DataRecord();
// We need a working REST client.
if (!isClientReady())
return dataRecord;
try
{
// Call the REST Webservice method GET on the resource "<objectType>/<objectUri>".
//
// The request message body is empty, the response message body should contain a data record encoded in
// JSON as follows:
//
// {
// "value" : <value as float>,
// "timestamp" : <timestamp as epoch in ms>,
// "quality" : "<quality>"
// }
//
// The quality quantifier must be one of the enums Quality's enumerators string representations.
//
// A status of 200 is considered as success, all other values are considered as error or the fact that
// there is no data record.
//
Response response = client.target(baseUrl).path(objectType.toString()).path(channelUri).request()
.accept(MediaType.APPLICATION_JSON_TYPE).get();
// Status needs to be 200.
if (!isStatusEqualTo(response, 200))
return dataRecord;
// Content type needs to be application/json.
if (!isContentTypeEqualTo(response, "application/json"))
return dataRecord;
// Read the data record object and if it did not worked, create a defaul data record to return.
dataRecord = response.readEntity(DataRecord.class);
if (dataRecord == null)
dataRecord = new DataRecord();
// Finally return the data record.
return dataRecord;
}
catch (Exception e)