Search in sources :

Example 1 with TsData

use of org.thingsboard.server.service.telemetry.TsData in project thingsboard by thingsboard.

the class TelemetryController method getTsKvListCallback.

private FutureCallback<List<TsKvEntry>> getTsKvListCallback(final DeferredResult<ResponseEntity> response, Boolean useStrictDataTypes) {
    return new FutureCallback<>() {

        @Override
        public void onSuccess(List<TsKvEntry> data) {
            Map<String, List<TsData>> result = new LinkedHashMap<>();
            for (TsKvEntry entry : data) {
                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));
        }

        @Override
        public void onFailure(Throwable e) {
            log.error("Failed to fetch historical data", e);
            AccessValidator.handleError(e, response, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    };
}
Also used : TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) BaseDeleteTsKvQuery(org.thingsboard.server.common.data.kv.BaseDeleteTsKvQuery) TsData(org.thingsboard.server.service.telemetry.TsData) ENTITY_TYPE_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_TYPE_PARAM_DESCRIPTION) SORT_ORDER_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_ALLOWABLE_VALUES) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) STRICT_DATA_TYPES_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.STRICT_DATA_TYPES_DESCRIPTION) TenantId(org.thingsboard.server.common.data.id.TenantId) Map(java.util.Map) SAVE_ENTITY_TIMESERIES_STATUS_UNAUTHORIZED(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_TIMESERIES_STATUS_UNAUTHORIZED) SAVE_ATTIRIBUTES_STATUS_OK(org.thingsboard.server.controller.ControllerConstants.SAVE_ATTIRIBUTES_STATUS_OK) JsonConverter(org.thingsboard.server.common.transport.adaptor.JsonConverter) INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION) JsonNode(com.fasterxml.jackson.databind.JsonNode) ATTRIBUTES_KEYS_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ATTRIBUTES_KEYS_DESCRIPTION) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) Set(java.util.Set) RestController(org.springframework.web.bind.annotation.RestController) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) Executors(java.util.concurrent.Executors) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Slf4j(lombok.extern.slf4j.Slf4j) Operation(org.thingsboard.server.service.security.permission.Operation) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) DeferredResult(org.springframework.web.context.request.async.DeferredResult) TELEMETRY_KEYS_BASE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.TELEMETRY_KEYS_BASE_DESCRIPTION) JsonParser(com.google.gson.JsonParser) DEVICE_ID(org.thingsboard.server.controller.ControllerConstants.DEVICE_ID) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) LinkedHashMap(java.util.LinkedHashMap) EntityIdFactory(org.thingsboard.server.common.data.id.EntityIdFactory) DEVICE_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.DEVICE_ID_PARAM_DESCRIPTION) DataType(org.thingsboard.server.common.data.kv.DataType) SAVE_ATTRIBUTES_REQUEST_PAYLOAD(org.thingsboard.server.controller.ControllerConstants.SAVE_ATTRIBUTES_REQUEST_PAYLOAD) Nullable(javax.annotation.Nullable) DataConstants(org.thingsboard.server.common.data.DataConstants) ATTRIBUTES_JSON_REQUEST_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ATTRIBUTES_JSON_REQUEST_DESCRIPTION) ConstraintValidator(org.thingsboard.server.dao.service.ConstraintValidator) ATTRIBUTES_SCOPE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ATTRIBUTES_SCOPE_DESCRIPTION) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) FutureCallback(com.google.common.util.concurrent.FutureCallback) HttpStatus(org.springframework.http.HttpStatus) Futures(com.google.common.util.concurrent.Futures) SAVE_ENTITY_ATTRIBUTES_STATUS_UNAUTHORIZED(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_ATTRIBUTES_STATUS_UNAUTHORIZED) ApiResponse(io.swagger.annotations.ApiResponse) MARKDOWN_CODE_BLOCK_START(org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_START) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) ENTITY_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_ID_PARAM_DESCRIPTION) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) PathVariable(org.springframework.web.bind.annotation.PathVariable) SAVE_ENTITY_ATTRIBUTES_STATUS_INTERNAL_SERVER_ERROR(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_ATTRIBUTES_STATUS_INTERNAL_SERVER_ERROR) SAVE_ENTITY_TIMESERIES_STATUS_INTERNAL_SERVER_ERROR(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_TIMESERIES_STATUS_INTERNAL_SERVER_ERROR) DefaultTenantProfileConfiguration(org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) ApiOperation(io.swagger.annotations.ApiOperation) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) PreDestroy(javax.annotation.PreDestroy) INVALID_STRUCTURE_OF_THE_REQUEST(org.thingsboard.server.controller.ControllerConstants.INVALID_STRUCTURE_OF_THE_REQUEST) EntityType(org.thingsboard.server.common.data.EntityType) TS_STRICT_DATA_EXAMPLE(org.thingsboard.server.controller.ControllerConstants.TS_STRICT_DATA_EXAMPLE) DeviceAttributesEventNotificationMsg(org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Function(com.google.common.base.Function) MARKDOWN_CODE_BLOCK_END(org.thingsboard.server.controller.ControllerConstants.MARKDOWN_CODE_BLOCK_END) AttributeData(org.thingsboard.server.service.telemetry.AttributeData) MediaType(org.springframework.http.MediaType) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TimeseriesService(org.thingsboard.server.dao.timeseries.TimeseriesService) ThingsBoardThreadFactory(org.thingsboard.common.util.ThingsBoardThreadFactory) UncheckedApiException(org.thingsboard.server.service.telemetry.exception.UncheckedApiException) LATEST_TS_NON_STRICT_DATA_EXAMPLE(org.thingsboard.server.controller.ControllerConstants.LATEST_TS_NON_STRICT_DATA_EXAMPLE) Collectors(java.util.stream.Collectors) TELEMETRY_KEYS_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.TELEMETRY_KEYS_DESCRIPTION) TELEMETRY_JSON_REQUEST_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.TELEMETRY_JSON_REQUEST_DESCRIPTION) List(java.util.List) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) PostConstruct(javax.annotation.PostConstruct) TELEMETRY_SCOPE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.TELEMETRY_SCOPE_DESCRIPTION) SAVE_ATTIRIBUTES_STATUS_BAD_REQUEST(org.thingsboard.server.controller.ControllerConstants.SAVE_ATTIRIBUTES_STATUS_BAD_REQUEST) SORT_ORDER_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_DESCRIPTION) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) JsonParseException(com.google.gson.JsonParseException) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ATTRIBUTE_DATA_EXAMPLE(org.thingsboard.server.controller.ControllerConstants.ATTRIBUTE_DATA_EXAMPLE) SAVE_TIMESERIES_REQUEST_PAYLOAD(org.thingsboard.server.controller.ControllerConstants.SAVE_TIMESERIES_REQUEST_PAYLOAD) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SAVE_ENTITY_ATTRIBUTES_STATUS_OK(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_ATTRIBUTES_STATUS_OK) JacksonUtil(org.thingsboard.common.util.JacksonUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiResponses(io.swagger.annotations.ApiResponses) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) TenantProfile(org.thingsboard.server.common.data.TenantProfile) ActionType(org.thingsboard.server.common.data.audit.ActionType) TbCoreComponent(org.thingsboard.server.queue.util.TbCoreComponent) EntityId(org.thingsboard.server.common.data.id.EntityId) UUIDBased(org.thingsboard.server.common.data.id.UUIDBased) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) ExecutorService(java.util.concurrent.ExecutorService) AttributeKey(org.thingsboard.server.common.data.kv.AttributeKey) ATTRIBUTES_SCOPE_ALLOWED_VALUES(org.thingsboard.server.controller.ControllerConstants.ATTRIBUTES_SCOPE_ALLOWED_VALUES) AccessValidator(org.thingsboard.server.service.security.AccessValidator) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) LATEST_TS_STRICT_DATA_EXAMPLE(org.thingsboard.server.controller.ControllerConstants.LATEST_TS_STRICT_DATA_EXAMPLE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) SAVE_ENTITY_TIMESERIES_STATUS_OK(org.thingsboard.server.controller.ControllerConstants.SAVE_ENTITY_TIMESERIES_STATUS_OK) InvalidParametersException(org.thingsboard.server.service.telemetry.exception.InvalidParametersException) TimeUnit(java.util.concurrent.TimeUnit) JsonDataEntry(org.thingsboard.server.common.data.kv.JsonDataEntry) ResponseEntity(org.springframework.http.ResponseEntity) ENTITY_ATTRIBUTE_SCOPES(org.thingsboard.server.controller.ControllerConstants.ENTITY_ATTRIBUTE_SCOPES) StringUtils(org.springframework.util.StringUtils) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsData(org.thingsboard.server.service.telemetry.TsData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FutureCallback(com.google.common.util.concurrent.FutureCallback) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Function (com.google.common.base.Function)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 JsonParser (com.google.gson.JsonParser)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1