@ -26,6 +26,8 @@ import com.google.common.util.concurrent.MoreExecutors;
import com.google.gson.JsonElement ;
import com.google.gson.JsonParseException ;
import com.google.gson.JsonParser ;
import io.swagger.annotations.ApiOperation ;
import io.swagger.annotations.ApiParam ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
@ -48,7 +50,6 @@ import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.TenantProfile ;
import org.thingsboard.server.common.data.audit.ActionType ;
import org.thingsboard.server.common.data.exception.ThingsboardException ;
import org.thingsboard.server.common.data.id.CustomerId ;
import org.thingsboard.server.common.data.id.DeviceId ;
import org.thingsboard.server.common.data.id.EntityId ;
import org.thingsboard.server.common.data.id.EntityIdFactory ;
@ -108,6 +109,17 @@ import java.util.stream.Collectors;
@Slf4j
public class TelemetryController extends BaseController {
private static final String ATTRIBUTES_SCOPE_DESCRIPTION = "A string value representing the attributes scope. For example, 'SERVER_SCOPE'." ;
private static final String ATTRIBUTES_KEYS_DESCRIPTION = "A string value representing the comma-separated list of attributes keys. For example, 'active,inactivityAlarmTime'." ;
private static final String ATTRIBUTES_SCOPE_ALLOWED_VALUES = "SERVER_SCOPE, CLIENT_SCOPE, SHARED_SCOPE" ;
private static final String ATTRIBUTES_JSON_REQUEST_DESCRIPTION = "A string value representing the json object. For example, '{\"key\":\"value\"}'" ;
private static final String TELEMETRY_KEYS_DESCRIPTION = "A string value representing the comma-separated list of timeseries keys. If keys are not selected, the result will return all latest timeseries. For example, 'temp,humidity'." ;
private static final String TELEMETRY_SCOPE_DESCRIPTION = "Value is not used in the API call implementation" ;
private static final String TELEMETRY_JSON_REQUEST_DESCRIPTION = "A string value representing the json object. For example, '{\"key\":\"value\"}' or '{\"ts\":1527863043000,\"values\":{\"key1\":\"value1\",\"key2\":\"value2\"}}'" ;
private static final String STRICT_DATA_TYPES_DESCRIPTION = "A boolean value to specify if values of selected timeseries keys will representing a string (by default) or use strict data type." ;
@Autowired
private TimeseriesService tsService ;
@ -133,62 +145,81 @@ public class TelemetryController extends BaseController {
}
}
@ApiOperation ( value = "Get all attribute keys (getAttributeKeys)" ,
notes = "Returns key names for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getAttributeKeys (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr , this : : getAttributeKeysCallback ) ;
}
@ApiOperation ( value = "Get all attributes by scope (getAttributeKeysByScope)" ,
notes = "Returns key names of specified scope for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/attributes/{scope}" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getAttributeKeysByScope (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr
, @PathVariable ( "scope" ) String scope ) throws ThingsboardException {
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeKeysCallback ( result , tenantId , entityId , scope ) ) ;
}
@ApiOperation ( value = "Get attributes (getAttributes)" ,
notes = "Returns JSON array of AttributeData objects for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getAttributes (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , null , keysStr ) ) ;
}
@ApiOperation ( value = "Get attributes by scope (getAttributesByScope)" ,
notes = "Returns JSON array of AttributeData objects for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/attributes/{scope}" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getAttributesByScope (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_ATTRIBUTES , entityType , entityIdStr ,
( result , tenantId , entityId ) - > getAttributeValuesCallback ( result , user , entityId , scope , keysStr ) ) ;
}
@ApiOperation ( value = "Get timeseries keys (getTimeseriesKeys)" ,
notes = "Returns latest timeseries keys for selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/keys/timeseries" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getTimeseriesKeys (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
( result , tenantId , entityId ) - > Futures . addCallback ( tsService . findAllLatest ( tenantId , entityId ) , getTsKeysToResponseCallback ( result ) , MoreExecutors . directExecutor ( ) ) ) ;
}
@ApiOperation ( value = "Get latest timeseries (getLatestTimeseries)" ,
notes = "Returns JSON object with mapping latest timeseries keys to JSON arrays of TsData objects for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET )
@ResponseBody
public DeferredResult < ResponseEntity > getLatestTimeseries (
@PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" , required = false ) String keysStr ,
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = TELEMETRY_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@ApiParam ( value = STRICT_DATA_TYPES_DESCRIPTION )
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
SecurityUser user = getCurrentUser ( ) ;
@ -196,20 +227,30 @@ public class TelemetryController extends BaseController {
( result , tenantId , entityId ) - > getLatestTimeseriesValuesCallback ( result , user , entityId , keysStr , useStrictDataTypes ) ) ;
}
@ApiOperation ( value = "Get timeseries (getTimeseries)" ,
notes = "Returns JSON object with mapping timeseries keys to JSON arrays of TsData objects based on specified filters for the selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/values/timeseries" , method = RequestMethod . GET , params = { "keys" , "startTs" , "endTs" } )
@ResponseBody
public DeferredResult < ResponseEntity > getTimeseries (
@PathVariable ( "entityType" ) String entityType ,
@PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" ) String keys ,
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = TELEMETRY_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" ) String keys ,
@ApiParam ( value = "A long value representing the start timestamp(milliseconds) of search time range." )
@RequestParam ( name = "startTs" ) Long startTs ,
@ApiParam ( value = "A long value representing the end timestamp(milliseconds) of search time range." )
@RequestParam ( name = "endTs" ) Long endTs ,
@ApiParam ( value = "A long value representing the aggregation interval(milliseconds) range." )
@RequestParam ( name = "interval" , defaultValue = "0" ) Long interval ,
@ApiParam ( value = "An integer value representing max number of selected data points." , defaultValue = "100" )
@RequestParam ( name = "limit" , defaultValue = "100" ) Integer limit ,
@ApiParam ( value = "A string value representing the aggregation function. " +
"If the interval is not specified, 'agg' parameter will be converted to 'NONE' value." ,
allowableValues = "MIN, MAX, AVG, SUM, COUNT, NONE" )
@RequestParam ( name = "agg" , defaultValue = "NONE" ) String aggStr ,
@ApiParam ( value = SORT_ORDER_DESCRIPTION , allowableValues = SORT_ORDER_ALLOWABLE_VALUES )
@RequestParam ( name = "orderBy" , defaultValue = "DESC" ) String orderBy ,
@ApiParam ( value = STRICT_DATA_TYPES_DESCRIPTION )
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ) throws ThingsboardException {
return accessValidator . validateEntityAndCallback ( getCurrentUser ( ) , Operation . READ_TELEMETRY , entityType , entityIdStr ,
( result , tenantId , entityId ) - > {
@ -222,64 +263,89 @@ public class TelemetryController extends BaseController {
} ) ;
}
@ApiOperation ( value = "Save or update device attributes (saveDeviceAttributes)" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{deviceId}/{scope}" , method = RequestMethod . POST )
@ResponseBody
public DeferredResult < ResponseEntity > saveDeviceAttributes ( @PathVariable ( "deviceId" ) String deviceIdStr , @PathVariable ( "scope" ) String scope ,
@RequestBody JsonNode request ) throws ThingsboardException {
public DeferredResult < ResponseEntity > saveDeviceAttributes (
@ApiParam ( value = DEVICE_ID_PARAM_DESCRIPTION ) @PathVariable ( "deviceId" ) String deviceIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION ) @RequestBody JsonNode request ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndUuid ( EntityType . DEVICE , deviceIdStr ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
@ApiOperation ( value = "Save or update attributes (saveEntityAttributesV1)" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/{scope}" , method = RequestMethod . POST )
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityAttributesV1 ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestBody JsonNode request ) throws ThingsboardException {
public DeferredResult < ResponseEntity > saveEntityAttributesV1 (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION ) @RequestBody JsonNode request ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
@ApiOperation ( value = "Save or update attributes (saveEntityAttributesV2)" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/attributes/{scope}" , method = RequestMethod . POST )
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityAttributesV2 ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestBody JsonNode request ) throws ThingsboardException {
public DeferredResult < ResponseEntity > saveEntityAttributesV2 (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION ) @RequestBody JsonNode request ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveAttributes ( getTenantId ( ) , entityId , scope , request ) ;
}
@ApiOperation ( value = "Save or update telemetry (saveEntityTelemetry)" )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}" , method = RequestMethod . POST )
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityTelemetry ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestBody String requestBody ) throws ThingsboardException {
public DeferredResult < ResponseEntity > saveEntityTelemetry (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = TELEMETRY_SCOPE_DESCRIPTION ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = TELEMETRY_JSON_REQUEST_DESCRIPTION ) @RequestBody String requestBody ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , 0L ) ;
}
@ApiOperation ( value = "Save or update telemetry with TTL (saveEntityTelemetryWithTTL)" ,
notes = "The TTL parameter is used to extract the number of days to store the data." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/{scope}/{ttl}" , method = RequestMethod . POST )
@ResponseBody
public DeferredResult < ResponseEntity > saveEntityTelemetryWithTTL ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope , @PathVariable ( "ttl" ) Long ttl ,
@RequestBody String requestBody ) throws ThingsboardException {
public DeferredResult < ResponseEntity > saveEntityTelemetryWithTTL (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = TELEMETRY_SCOPE_DESCRIPTION ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = "A long value representing TTL(Time to Live) parameter." ) @PathVariable ( "ttl" ) Long ttl ,
@ApiParam ( value = TELEMETRY_JSON_REQUEST_DESCRIPTION ) @RequestBody String requestBody ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return saveTelemetry ( getTenantId ( ) , entityId , requestBody , ttl ) ;
}
@ApiOperation ( value = "Delete entity timeseries (deleteEntityTimeseries)" ,
notes = "Delete timeseries in the specified time range for selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/timeseries/delete" , method = RequestMethod . DELETE )
@ResponseBody
public DeferredResult < ResponseEntity > deleteEntityTimeseries ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@RequestParam ( name = "keys" ) String keysStr ,
@RequestParam ( name = "deleteAllDataForKeys" , defaultValue = "false" ) boolean deleteAllDataForKeys ,
@RequestParam ( name = "startTs" , required = false ) Long startTs ,
@RequestParam ( name = "endTs" , required = false ) Long endTs ,
@RequestParam ( name = "rewriteLatestIfDeleted" , defaultValue = "false" ) boolean rewriteLatestIfDeleted ) throws ThingsboardException {
public DeferredResult < ResponseEntity > deleteEntityTimeseries (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = TELEMETRY_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" ) String keysStr ,
@ApiParam ( value = "A boolean value to specify if should be deleted all data for selected keys or only data that are in the selected time range." )
@RequestParam ( name = "deleteAllDataForKeys" , defaultValue = "false" ) boolean deleteAllDataForKeys ,
@ApiParam ( value = "A long value representing the start timestamp(milliseconds) of removal time range." )
@RequestParam ( name = "startTs" , required = false ) Long startTs ,
@ApiParam ( value = "A long value representing the end timestamp(milliseconds) of removal time range." )
@RequestParam ( name = "endTs" , required = false ) Long endTs ,
@ApiParam ( value = "If the parameter is set to true, the latest telemetry will be rewritten if the current latest value was removed, otherwise, the new latest value will not set." )
@RequestParam ( name = "rewriteLatestIfDeleted" , defaultValue = "false" ) boolean rewriteLatestIfDeleted ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return deleteTimeseries ( entityId , keysStr , deleteAllDataForKeys , startTs , endTs , rewriteLatestIfDeleted ) ;
}
@ -311,7 +377,6 @@ public class TelemetryController extends BaseController {
for ( String key : keys ) {
deleteTsKvQueries . add ( new BaseDeleteTsKvQuery ( key , deleteFromTs , deleteToTs , rewriteLatestIfDeleted ) ) ;
}
ListenableFuture < List < Void > > future = tsService . remove ( user . getTenantId ( ) , entityId , deleteTsKvQueries ) ;
Futures . addCallback ( future , new FutureCallback < List < Void > > ( ) {
@Override
@ -329,22 +394,29 @@ public class TelemetryController extends BaseController {
} ) ;
}
@ApiOperation ( value = "Delete device attributes (deleteEntityAttributes)" ,
notes = "Delete attributes of specified scope for selected device." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{deviceId}/{scope}" , method = RequestMethod . DELETE )
@ResponseBody
public DeferredResult < ResponseEntity > deleteEntityAttributes ( @PathVariable ( "deviceId" ) String deviceIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestParam ( name = "keys" ) String keysStr ) throws ThingsboardException {
public DeferredResult < ResponseEntity > deleteEntityAttributes (
@ApiParam ( value = DEVICE_ID_PARAM_DESCRIPTION ) @PathVariable ( "deviceId" ) String deviceIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" ) String keysStr ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndUuid ( EntityType . DEVICE , deviceIdStr ) ;
return deleteAttributes ( entityId , scope , keysStr ) ;
}
@ApiOperation ( value = "Delete entity attributes (deleteEntityAttributes)" ,
notes = "Delete attributes of specified scope for selected entity." )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@RequestMapping ( value = "/{entityType}/{entityId}/{scope}" , method = RequestMethod . DELETE )
@ResponseBody
public DeferredResult < ResponseEntity > deleteEntityAttributes ( @PathVariable ( "entityType" ) String entityType , @PathVariable ( "entityId" ) String entityIdStr ,
@PathVariable ( "scope" ) String scope ,
@RequestParam ( name = "keys" ) String keysStr ) throws ThingsboardException {
public DeferredResult < ResponseEntity > deleteEntityAttributes (
@ApiParam ( value = ENTITY_TYPE_PARAM_DESCRIPTION ) @PathVariable ( "entityType" ) String entityType ,
@ApiParam ( value = ENTITY_ID_PARAM_DESCRIPTION ) @PathVariable ( "entityId" ) String entityIdStr ,
@ApiParam ( value = ATTRIBUTES_SCOPE_DESCRIPTION , allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES ) @PathVariable ( "scope" ) String scope ,
@ApiParam ( value = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" ) String keysStr ) throws ThingsboardException {
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
return deleteAttributes ( entityId , scope , keysStr ) ;
}