@ -1,12 +1,12 @@
/ * *
/ * *
* Copyright © 2016 - 2021 The Thingsboard Authors
* Copyright © 2016 - 2021 The Thingsboard Authors
*
* < p >
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
* You may obtain a copy of the License at
*
* < p >
* http : //www.apache.org/licenses/LICENSE-2.0
* http : //www.apache.org/licenses/LICENSE-2.0
*
* < p >
* Unless required by applicable law or agreed to in writing , software
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
@ -26,6 +26,8 @@ import com.google.common.util.concurrent.MoreExecutors;
import com.google.gson.JsonElement ;
import com.google.gson.JsonElement ;
import com.google.gson.JsonParseException ;
import com.google.gson.JsonParseException ;
import com.google.gson.JsonParser ;
import com.google.gson.JsonParser ;
import io.swagger.annotations.ApiOperation ;
import io.swagger.annotations.ApiParam ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
@ -133,83 +135,101 @@ public class TelemetryController extends BaseController {
}
}
}
}
@ApiOperation ( value = "Get all existed attributes of entity by it`s type" ,
notes = "Returns key`s name of the attribute" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getAttributeKeys (
public DeferredResult < ResponseEntity > getAttributeKeys (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity type. For example, 'ASSET'" ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = "A string value representing the entity id of the required entity type. For example, '87b2fe90-2050-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr , this : : getAttributeKeysCallback ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr , this : : getAttributeKeysCallback ) ;
}
}
@ApiOperation ( value = "Get all existed attributes of entity by type and scope" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes/{scope}" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes/{scope}" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getAttributeKeysByScope (
public DeferredResult < ResponseEntity > getAttributeKeysByScope (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
, @PathVariable ( "scope" ) String scope ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the scope. For example, 'SERVER_SCOPE'. In the result will be return all server attributes" ) @PathVariable ( "scope" ) String scope ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeKeysCallback ( result , tenantId , entityId , scope ) ) ;
( result , tenantId , entityId ) - > getAttributeKeysCallback ( result , tenantId , entityId , scope ) ) ;
}
}
@ApiOperation ( value = "Get all existed attributes of entity by it`s type" ,
notes = "Returns key and value of the attribute" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getAttributes (
public DeferredResult < ResponseEntity > getAttributes (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity keys. They are optional and listed with comma with no space between keys. For example, 'active,inactivityAlarmTime'" ) @RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
SecurityUser user = getCurrentUser ( ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , null , keysStr ) ) ;
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , null , keysStr ) ) ;
}
}
@ApiOperation ( value = "Get all existed attributes of entity by it`s type and scope" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes/{scope}" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes/{scope}" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getAttributesByScope (
public DeferredResult < ResponseEntity > getAttributesByScope (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity type. For example, 'SERVER_SCOPE'" ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the entity keys. They are optional and listed with comma with no space between keys. For example, 'active,inactivityAlarmTime'" ) @RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
SecurityUser user = getCurrentUser ( ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , scope , keysStr ) ) ;
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , scope , keysStr ) ) ;
}
}
@ApiOperation ( value = "Get all timeseries keys of entity" ,
notes = "Return all keys of timeseries of entity id and type" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/timeseries" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/timeseries" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getTimeseriesKeys (
public DeferredResult < ResponseEntity > getTimeseriesKeys (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
( result , tenantId , entityId ) - > Futures . addCallback ( tsService . findAllLatest ( tenantId , entityId ) , getTsKeysToResponseCallback ( result ) , MoreExecutors . directExecutor ( ) ) ) ;
( result , tenantId , entityId ) - > Futures . addCallback ( tsService . findAllLatest ( tenantId , entityId ) , getTsKeysToResponseCallback ( result ) , MoreExecutors . directExecutor ( ) ) ) ;
}
}
@ApiOperation ( value = "Get all last timeseries of entity" ,
notes = "Return all last timeserie(last time updated or created) of entity id and type" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getLatestTimeseries (
public DeferredResult < ResponseEntity > getLatestTimeseries (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestParam ( name = "keys" , required = false ) String keysStr ,
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity keys. They are optional and listed with comma with no space between keys. For example, 'active,inactivityAlarmTime'" ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@ApiParam ( value = "A boolean value representing if value of timeseries is representing as a string (by default) or as original type" ) @RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
SecurityUser user = getCurrentUser ( ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getLatestTimeseriesValuesCallback ( result , user , entityId , keysStr , useStrictDataTypes ) ) ;
( result , tenantId , entityId ) - > getLatestTimeseriesValuesCallback ( result , user , entityId , keysStr , useStrictDataTypes ) ) ;
}
}
@ApiOperation ( value = "Get all last timeseries of entity" ,
notes = "Return all timeseries of entity in selected period of time. Based on this information can be built " +
"widget on the dashboard to see updated telemetry in real-time" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET , params = { "keys" , "startTs" , "endTs" } )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET , params = { "keys" , "startTs" , "endTs" } )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > getTimeseries (
public DeferredResult < ResponseEntity > getTimeseries (
@PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @ PathVariable ( "entityType" ) String entityType ,
@PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity id. For example, '16cdaaf0-229d-11ec-b9f0-231c4d2593da'" ) @ PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" ) String keys ,
@ApiParam ( value = "A string value representing the entity keys. They are optional and listed with comma with no space between keys. For example, 'active,inactivityAlarmTime'" ) @ RequestParam ( name = "keys" ) String keys ,
@RequestParam ( name = "startTs" ) Long startTs ,
@ApiParam ( value = "A string value representing the start point of time" ) @ RequestParam ( name = "startTs" ) Long startTs ,
@RequestParam ( name = "endTs" ) Long endTs ,
@ApiParam ( value = "A string value representing the end point of time" ) @ RequestParam ( name = "endTs" ) Long endTs ,
@RequestParam ( name = "interval" , defaultValue = "0" ) Long interval ,
@ApiParam ( value = "A long value representing the period of time" ) @ RequestParam ( name = "interval" , defaultValue = "0" ) Long interval ,
@RequestParam ( name = "limit" , defaultValue = "100" ) Integer limit ,
@RequestParam ( name = "limit" , defaultValue = "100" ) Integer limit ,
@RequestParam ( name = "agg" , defaultValue = "NONE" ) String aggStr ,
@ApiParam ( value = "A string value representing the function. For example, 'AVG'" ) @ RequestParam ( name = "agg" , defaultValue = "NONE" ) String aggStr ,
@RequestParam ( name = "orderBy" , defaultValue = "DESC" ) String orderBy ,
@ApiParam ( value = "A string value representing a sorting type" ) @ RequestParam ( name = "orderBy" , defaultValue = "DESC" ) String orderBy ,
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
( result , tenantId , entityId ) - > {
( result , tenantId , entityId ) - > {
@ -222,25 +242,33 @@ public class TelemetryController extends BaseController {
} ) ;
} ) ;
}
}
@ApiOperation ( value = "Create and save attribute of device" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{deviceId}/{scope}" , method = RequestMethod . POST )
@RequestMapping ( value = "/{deviceId}/{scope}" , method = RequestMethod . POST )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > saveDeviceAttributes ( @PathVariable ( "deviceId" ) String deviceIdStr , @PathVariable ( "scope" ) String scope ,
public DeferredResult < ResponseEntity > saveDeviceAttributes (
@RequestBody JsonNode request ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the device id. For example, 'e0034860-2065-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "deviceId" ) String deviceIdStr ,
@ApiParam ( value = "A string value representing the entity type. For example, 'SERVER_SCOPE'" ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the json object. Should contains key and value of the attribute. For example, '{\"key\":\"value\"}'" ) @RequestBody JsonNode request ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndUuid ( EntityType . DEVICE , deviceIdStr ) ;
EntityId entityId = EntityIdFactory . getByTypeAndUuid ( EntityType . DEVICE , deviceIdStr ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
}
@ApiOperation ( value = "Create and save attribute of entity" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/{scope}" , method = RequestMethod . POST )
@RequestMapping ( value = "/{entityType}/{entityId}/{scope}" , method = RequestMethod . POST )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityAttributesV1 ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
public DeferredResult < ResponseEntity > saveEntityAttributesV1 (
@PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the entity type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestBody JsonNode request ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the entity id. For example, 'e0034860-2065-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the entity type. For example, 'SHARED_SCOPE'" ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the json object. Should contains key and value of the attribute. For example, '{\"key\":\"value\"}'" ) @RequestBody JsonNode request ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
}
@ApiOperation ( value = "Create and save attribute of entity" ,
notes = "The same as saveEntityAttributesV1" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/attributes/{scope}" , method = RequestMethod . POST )
@RequestMapping ( value = "/{entityType}/{entityId}/attributes/{scope}" , method = RequestMethod . POST )
@ResponseBody
@ResponseBody
@ -251,35 +279,47 @@ public class TelemetryController extends BaseController {
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
}
@ApiOperation ( value = "Save telemetry of entity type and scope" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}" , method = RequestMethod . POST )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}" , method = RequestMethod . POST )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityTelemetry ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
public DeferredResult < ResponseEntity > saveEntityTelemetry (
@PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the device type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestBody String requestBody ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the device id. For example, 'e0034860-2065-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the scope. For example, 'SERVER_SCOPE'" ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A string value representing the json object. Should contains key and value of the attribute. For example, '{\"key\":\"value\"}'" ) @RequestBody String requestBody ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , 0L ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , 0L ) ;
}
}
@ApiOperation ( value = "Save telemetry of entity type and scope" ,
notes = "The TTL parameter is used to extract the number of days to store the data." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}/{ttl}" , method = RequestMethod . POST )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}/{ttl}" , method = RequestMethod . POST )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityTelemetryWithTTL ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
public DeferredResult < ResponseEntity > saveEntityTelemetryWithTTL (
@PathVariable ( "scope" ) String scope , @PathVariable ( "ttl" ) Long ttl ,
@ApiParam ( value = "A string value representing the device type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestBody String requestBody ) throws ThingsboardException {
@ApiParam ( value = "A string value representing the device id. For example, 'e0034860-2065-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = "A string value representing the scope. For example, 'SERVER_SCOPE'" ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A long value representing the amount of days." ) @PathVariable ( "ttl" ) Long ttl ,
@ApiParam ( value = "A string value representing the json object. Should contains key and value of the attribute. For example, '{\"key\":\"value\"}'" ) @RequestBody String requestBody ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , ttl ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , ttl ) ;
}
}
@ApiOperation ( value = "Delete entity timeseries" ,
notes = "Delete all timeseries of entity in the required period of time" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/delete" , method = RequestMethod . DELETE )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/delete" , method = RequestMethod . DELETE )
@ResponseBody
@ResponseBody
public DeferredResult < ResponseEntity > deleteEntityTimeseries ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
public DeferredResult < ResponseEntity > deleteEntityTimeseries (
@RequestParam ( name = "keys" ) String keysStr ,
@ApiParam ( value = "A string value representing the device type. For example, 'DEVICE'" ) @PathVariable ( "entityType" ) String entityType ,
@RequestParam ( name = "deleteAllDataForKeys" , defaultValue = "false" ) boolean deleteAllDataForKeys ,
@ApiParam ( value = "A string value representing the device id. For example, 'e0034860-2065-11ec-8a0a-15ac1b4580c2'" ) @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "startTs" , required = false ) Long startTs ,
@ApiParam ( value = "A string value representing the entity keys. They are optional and listed with comma with no space between keys. For example, 'active,inactivityAlarmTime'" ) @RequestParam ( name = "keys" ) String keysStr ,
@RequestParam ( name = "endTs" , required = false ) Long endTs ,
@ApiParam ( value = "A boolean value representing if should be deleted all data of required key or only the latest" ) @RequestParam ( name = "deleteAllDataForKeys" , defaultValue = "false" ) boolean deleteAllDataForKeys ,
@RequestParam ( name = "rewriteLatestIfDeleted" , defaultValue = "false" ) boolean rewriteLatestIfDeleted ) throws ThingsboardException {
@ApiParam ( value = "A long value representing the start point of time" ) @RequestParam ( name = "startTs" , required = false ) Long startTs ,
@ApiParam ( value = "A long value representing the end point of time" ) @RequestParam ( name = "endTs" , required = false ) Long endTs ,
@RequestParam ( name = "rewriteLatestIfDeleted" , defaultValue = "false" ) boolean rewriteLatestIfDeleted ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return deleteTimeseries ( entityId , keysStr , deleteAllDataForKeys , startTs , endTs , rewriteLatestIfDeleted ) ;
return deleteTimeseries ( entityId , keysStr , deleteAllDataForKeys , startTs , endTs , rewriteLatestIfDeleted ) ;
}
}
@ -311,7 +351,6 @@ public class TelemetryController extends BaseController {
for ( String key : keys ) {
for ( String key : keys ) {
deleteTsKvQueries . add ( new BaseDeleteTsKvQuery ( key , deleteFromTs , deleteToTs , rewriteLatestIfDeleted ) ) ;
deleteTsKvQueries . add ( new BaseDeleteTsKvQuery ( key , deleteFromTs , deleteToTs , rewriteLatestIfDeleted ) ) ;
}
}
ListenableFuture < List < Void > > future = tsService . remove ( user . getTenantId ( ) , entityId , deleteTsKvQueries ) ;
ListenableFuture < List < Void > > future = tsService . remove ( user . getTenantId ( ) , entityId , deleteTsKvQueries ) ;
Futures . addCallback ( future , new FutureCallback < List < Void > > ( ) {
Futures . addCallback ( future , new FutureCallback < List < Void > > ( ) {
@Override
@Override