Merge branch 'master' of github.com:thingsboard/thingsboard into develop/3.0
This commit is contained in:
		
						commit
						c4fd267f9e
					
				@ -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 = "useStrictDataTypes", required = false, defaultValue = "false") Boolean useStrictDataTypes) 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, useStrictDataTypes));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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 = "useStrictDataTypes", required = false, defaultValue = "false") Boolean useStrictDataTypes) 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, useStrictDataTypes));
 | 
			
		||||
                });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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 useStrictDataTypes) {
 | 
			
		||||
        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, useStrictDataTypes));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 useStrictDataTypes) {
 | 
			
		||||
        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 = useStrictDataTypes ? getKvValue(entry) : entry.getValueAsString();
 | 
			
		||||
                    result.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(new TsData(entry.getTs(), value));
 | 
			
		||||
                }
 | 
			
		||||
                response.setResult(new ResponseEntity<>(result, HttpStatus.OK));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -18,9 +18,9 @@ package org.thingsboard.server.service.telemetry;
 | 
			
		||||
public class TsData implements Comparable<TsData>{
 | 
			
		||||
 | 
			
		||||
    private final long ts;
 | 
			
		||||
    private final String value;
 | 
			
		||||
    private final Object value;
 | 
			
		||||
 | 
			
		||||
    public TsData(long ts, String value) {
 | 
			
		||||
    public TsData(long ts, Object value) {
 | 
			
		||||
        super();
 | 
			
		||||
        this.ts = ts;
 | 
			
		||||
        this.value = value;
 | 
			
		||||
@ -30,7 +30,7 @@ public class TsData implements Comparable<TsData>{
 | 
			
		||||
        return ts;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getValue() {
 | 
			
		||||
    public Object getValue() {
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -97,6 +97,7 @@ import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.concurrent.ExecutorService;
 | 
			
		||||
import java.util.concurrent.Executors;
 | 
			
		||||
import java.util.concurrent.Future;
 | 
			
		||||
@ -1611,31 +1612,40 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<TsKvEntry> getLatestTimeseries(EntityId entityId, List<String> keys) {
 | 
			
		||||
        return getLatestTimeseries(entityId, keys, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<TsKvEntry> getLatestTimeseries(EntityId entityId, List<String> keys, boolean useStrictDataTypes) {
 | 
			
		||||
        Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}",
 | 
			
		||||
                baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&useStrictDataTypes={useStrictDataTypes}",
 | 
			
		||||
                HttpMethod.GET,
 | 
			
		||||
                HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
 | 
			
		||||
                },
 | 
			
		||||
                entityId.getEntityType().name(),
 | 
			
		||||
                entityId.getId().toString(),
 | 
			
		||||
                listToString(keys)).getBody();
 | 
			
		||||
                listToString(keys),
 | 
			
		||||
                useStrictDataTypes).getBody();
 | 
			
		||||
 | 
			
		||||
        return RestJsonConverter.toTimeseries(timeseries);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public List<TsKvEntry> getTimeseries(EntityId entityId, List<String> keys, Long interval, Aggregation agg, TimePageLink pageLink) {
 | 
			
		||||
        return getTimeseries(entityId, keys, interval, agg, pageLink, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<TsKvEntry> getTimeseries(EntityId entityId, List<String> keys, Long interval, Aggregation agg, TimePageLink pageLink, boolean useStrictDataTypes) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        params.put("entityType", entityId.getEntityType().name());
 | 
			
		||||
        params.put("entityId", entityId.getId().toString());
 | 
			
		||||
        params.put("keys", listToString(keys));
 | 
			
		||||
        params.put("interval", interval == null ? "0" : interval.toString());
 | 
			
		||||
        params.put("agg", agg == null ? "NONE" : agg.name());
 | 
			
		||||
        params.put("useStrictDataTypes", Boolean.toString(useStrictDataTypes));
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
 | 
			
		||||
        Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&interval={interval}&agg={agg}&" + getUrlParams(pageLink),
 | 
			
		||||
                baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&interval={interval}&agg={agg}&useStrictDataTypes={useStrictDataTypes}&" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET,
 | 
			
		||||
                HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user