|
|
|
@ -182,11 +182,12 @@ public class TelemetryController extends BaseController { |
|
|
|
@ResponseBody |
|
|
|
public DeferredResult<ResponseEntity> getLatestTimeseries( |
|
|
|
@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { |
|
|
|
@RequestParam(name = "keys", required = false) String keysStr, |
|
|
|
@RequestParam(name = "useStrictType", required = false, defaultValue = "false") Boolean useStrictType) throws ThingsboardException { |
|
|
|
SecurityUser user = getCurrentUser(); |
|
|
|
|
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr, |
|
|
|
(result, tenantId, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr)); |
|
|
|
(result, tenantId, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr, useStrictType)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -200,8 +201,8 @@ public class TelemetryController extends BaseController { |
|
|
|
@RequestParam(name = "endTs") Long endTs, |
|
|
|
@RequestParam(name = "interval", defaultValue = "0") Long interval, |
|
|
|
@RequestParam(name = "limit", defaultValue = "100") Integer limit, |
|
|
|
@RequestParam(name = "agg", defaultValue = "NONE") String aggStr |
|
|
|
) throws ThingsboardException { |
|
|
|
@RequestParam(name = "agg", defaultValue = "NONE") String aggStr, |
|
|
|
@RequestParam(name = "useStrictType", required = false, defaultValue = "false") Boolean useStrictType) throws ThingsboardException { |
|
|
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr, |
|
|
|
(result, tenantId, entityId) -> { |
|
|
|
// If interval is 0, convert this to a NONE aggregation, which is probably what the user really wanted
|
|
|
|
@ -209,7 +210,7 @@ public class TelemetryController extends BaseController { |
|
|
|
List<ReadTsKvQuery> queries = toKeysList(keys).stream().map(key -> new BaseReadTsKvQuery(key, startTs, endTs, interval, limit, agg)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result)); |
|
|
|
Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result, useStrictType)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -454,14 +455,14 @@ public class TelemetryController extends BaseController { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void getLatestTimeseriesValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String keys) { |
|
|
|
private void getLatestTimeseriesValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String keys, Boolean useStrictType) { |
|
|
|
ListenableFuture<List<TsKvEntry>> future; |
|
|
|
if (StringUtils.isEmpty(keys)) { |
|
|
|
future = tsService.findAllLatest(user.getTenantId(), entityId); |
|
|
|
} else { |
|
|
|
future = tsService.findLatest(user.getTenantId(), entityId, toKeysList(keys)); |
|
|
|
} |
|
|
|
Futures.addCallback(future, getTsKvListCallback(result)); |
|
|
|
Futures.addCallback(future, getTsKvListCallback(result, useStrictType)); |
|
|
|
} |
|
|
|
|
|
|
|
private void getAttributeValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String scope, String keys) { |
|
|
|
@ -544,7 +545,7 @@ public class TelemetryController extends BaseController { |
|
|
|
@Override |
|
|
|
public void onSuccess(List<AttributeKvEntry> attributes) { |
|
|
|
List<AttributeData> values = attributes.stream().map(attribute -> |
|
|
|
new AttributeData(attribute.getLastUpdateTs(), attribute.getKey(), getKvValue(attribute)) |
|
|
|
new AttributeData(attribute.getLastUpdateTs(), attribute.getKey(), getKvValue(attribute)) |
|
|
|
).collect(Collectors.toList()); |
|
|
|
logAttributesRead(user, entityId, scope, keyList, null); |
|
|
|
response.setResult(new ResponseEntity<>(values, HttpStatus.OK)); |
|
|
|
@ -559,14 +560,14 @@ public class TelemetryController extends BaseController { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response) { |
|
|
|
private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response, Boolean useStrictType) { |
|
|
|
return new FutureCallback<List<TsKvEntry>>() { |
|
|
|
@Override |
|
|
|
public void onSuccess(List<TsKvEntry> data) { |
|
|
|
Map<String, List<TsData>> result = new LinkedHashMap<>(); |
|
|
|
for (TsKvEntry entry : data) { |
|
|
|
result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()) |
|
|
|
.add(new TsData(entry.getTs(), entry.getValueAsString())); |
|
|
|
Object value = useStrictType ? getKvValue(entry) : entry.getValueAsString(); |
|
|
|
result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(new TsData(entry.getTs(), value)); |
|
|
|
} |
|
|
|
response.setResult(new ResponseEntity<>(result, HttpStatus.OK)); |
|
|
|
} |
|
|
|
|