Commit e207545ce072e6dbf67c2d5f8c2b74982f6bdcf3
Committed by
Andrew Shvayka
1 parent
f2aefb55
Improvement TelemetryController, change TsData value to Object
Showing
2 changed files
with
15 additions
and
14 deletions
... | ... | @@ -182,11 +182,12 @@ public class TelemetryController extends BaseController { |
182 | 182 | @ResponseBody |
183 | 183 | public DeferredResult<ResponseEntity> getLatestTimeseries( |
184 | 184 | @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr, |
185 | - @RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException { | |
185 | + @RequestParam(name = "keys", required = false) String keysStr, | |
186 | + @RequestParam(name = "useStrictType", required = false, defaultValue = "false") Boolean useStrictType) throws ThingsboardException { | |
186 | 187 | SecurityUser user = getCurrentUser(); |
187 | 188 | |
188 | 189 | return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr, |
189 | - (result, tenantId, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr)); | |
190 | + (result, tenantId, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr, useStrictType)); | |
190 | 191 | } |
191 | 192 | |
192 | 193 | |
... | ... | @@ -200,8 +201,8 @@ public class TelemetryController extends BaseController { |
200 | 201 | @RequestParam(name = "endTs") Long endTs, |
201 | 202 | @RequestParam(name = "interval", defaultValue = "0") Long interval, |
202 | 203 | @RequestParam(name = "limit", defaultValue = "100") Integer limit, |
203 | - @RequestParam(name = "agg", defaultValue = "NONE") String aggStr | |
204 | - ) throws ThingsboardException { | |
204 | + @RequestParam(name = "agg", defaultValue = "NONE") String aggStr, | |
205 | + @RequestParam(name = "useStrictType", required = false, defaultValue = "false") Boolean useStrictType) throws ThingsboardException { | |
205 | 206 | return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr, |
206 | 207 | (result, tenantId, entityId) -> { |
207 | 208 | // 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 { |
209 | 210 | List<ReadTsKvQuery> queries = toKeysList(keys).stream().map(key -> new BaseReadTsKvQuery(key, startTs, endTs, interval, limit, agg)) |
210 | 211 | .collect(Collectors.toList()); |
211 | 212 | |
212 | - Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result)); | |
213 | + Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result, useStrictType)); | |
213 | 214 | }); |
214 | 215 | } |
215 | 216 | |
... | ... | @@ -454,14 +455,14 @@ public class TelemetryController extends BaseController { |
454 | 455 | }); |
455 | 456 | } |
456 | 457 | |
457 | - private void getLatestTimeseriesValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String keys) { | |
458 | + private void getLatestTimeseriesValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String keys, Boolean useStrictType) { | |
458 | 459 | ListenableFuture<List<TsKvEntry>> future; |
459 | 460 | if (StringUtils.isEmpty(keys)) { |
460 | 461 | future = tsService.findAllLatest(user.getTenantId(), entityId); |
461 | 462 | } else { |
462 | 463 | future = tsService.findLatest(user.getTenantId(), entityId, toKeysList(keys)); |
463 | 464 | } |
464 | - Futures.addCallback(future, getTsKvListCallback(result)); | |
465 | + Futures.addCallback(future, getTsKvListCallback(result, useStrictType)); | |
465 | 466 | } |
466 | 467 | |
467 | 468 | private void getAttributeValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String scope, String keys) { |
... | ... | @@ -544,7 +545,7 @@ public class TelemetryController extends BaseController { |
544 | 545 | @Override |
545 | 546 | public void onSuccess(List<AttributeKvEntry> attributes) { |
546 | 547 | List<AttributeData> values = attributes.stream().map(attribute -> |
547 | - new AttributeData(attribute.getLastUpdateTs(), attribute.getKey(), getKvValue(attribute)) | |
548 | + new AttributeData(attribute.getLastUpdateTs(), attribute.getKey(), getKvValue(attribute)) | |
548 | 549 | ).collect(Collectors.toList()); |
549 | 550 | logAttributesRead(user, entityId, scope, keyList, null); |
550 | 551 | response.setResult(new ResponseEntity<>(values, HttpStatus.OK)); |
... | ... | @@ -559,14 +560,14 @@ public class TelemetryController extends BaseController { |
559 | 560 | }; |
560 | 561 | } |
561 | 562 | |
562 | - private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response) { | |
563 | + private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response, Boolean useStrictType) { | |
563 | 564 | return new FutureCallback<List<TsKvEntry>>() { |
564 | 565 | @Override |
565 | 566 | public void onSuccess(List<TsKvEntry> data) { |
566 | 567 | Map<String, List<TsData>> result = new LinkedHashMap<>(); |
567 | 568 | for (TsKvEntry entry : data) { |
568 | - result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()) | |
569 | - .add(new TsData(entry.getTs(), entry.getValueAsString())); | |
569 | + Object value = useStrictType ? getKvValue(entry) : entry.getValueAsString(); | |
570 | + result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(new TsData(entry.getTs(), value)); | |
570 | 571 | } |
571 | 572 | response.setResult(new ResponseEntity<>(result, HttpStatus.OK)); |
572 | 573 | } | ... | ... |
... | ... | @@ -18,9 +18,9 @@ package org.thingsboard.server.service.telemetry; |
18 | 18 | public class TsData implements Comparable<TsData>{ |
19 | 19 | |
20 | 20 | private final long ts; |
21 | - private final String value; | |
21 | + private final Object value; | |
22 | 22 | |
23 | - public TsData(long ts, String value) { | |
23 | + public TsData(long ts, Object value) { | |
24 | 24 | super(); |
25 | 25 | this.ts = ts; |
26 | 26 | this.value = value; |
... | ... | @@ -30,7 +30,7 @@ public class TsData implements Comparable<TsData>{ |
30 | 30 | return ts; |
31 | 31 | } |
32 | 32 | |
33 | - public String getValue() { | |
33 | + public Object getValue() { | |
34 | 34 | return value; |
35 | 35 | } |
36 | 36 | ... | ... |