@ -26,6 +26,8 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonParser ;
import io.swagger.v3.oas.annotations.Hidden ;
import io.swagger.v3.oas.annotations.Parameter ;
import io.swagger.v3.oas.annotations.Parameters ;
import io.swagger.v3.oas.annotations.enums.ParameterIn ;
import io.swagger.v3.oas.annotations.media.ArraySchema ;
import io.swagger.v3.oas.annotations.media.Content ;
import io.swagger.v3.oas.annotations.media.Schema ;
@ -39,7 +41,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus ;
import org.springframework.http.ResponseEntity ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.util.MultiValueMap ;
import org.springframework.web.bind.annotation.DeleteMapping ;
import org.springframework.web.bind.annotation.GetMapping ;
@ -205,12 +206,16 @@ public class TelemetryController extends BaseController {
+ MARKDOWN_CODE_BLOCK_END
+ "\n\n " + INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH ,
responses = @ApiResponse ( responseCode = "200" , description = "OK" , content = @Content ( array = @ArraySchema ( schema = @Schema ( implementation = AttributeData . class ) ) ) ) )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/{entityType}/{entityId}/values/attributes" )
public DeferredResult < ResponseEntity > getAttributes (
@Parameter ( description = ENTITY_TYPE_PARAM_DESCRIPTION , required = true , schema = @Schema ( defaultValue = "DEVICE" ) ) @PathVariable ( "entityType" ) String entityType ,
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( "entityId" ) String entityIdStr ,
@Parameter ( description = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
SecurityUser user = getCurrentUser ( ) ;
@ -229,6 +234,9 @@ public class TelemetryController extends BaseController {
+ MARKDOWN_CODE_BLOCK_END
+ "\n\n " + INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH ,
responses = @ApiResponse ( content = @Content ( mediaType = "application/json" , array = @ArraySchema ( schema = @Schema ( implementation = AttributeData . class ) ) ) ) )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/{entityType}/{entityId}/values/attributes/{scope}" )
public DeferredResult < ResponseEntity > getAttributesByScope (
@ -236,6 +244,7 @@ public class TelemetryController extends BaseController {
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( "entityId" ) String entityIdStr ,
@Parameter ( description = ATTRIBUTES_SCOPE_DESCRIPTION , schema = @Schema ( allowableValues = { "SERVER_SCOPE" , "SHARED_SCOPE" , "CLIENT_SCOPE" } , requiredMode = Schema . RequiredMode . REQUIRED ) ) @PathVariable ( "scope" ) AttributeScope scope ,
@Parameter ( description = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
SecurityUser user = getCurrentUser ( ) ;
@ -269,6 +278,9 @@ public class TelemetryController extends BaseController {
+ MARKDOWN_CODE_BLOCK_END
+ "\n\n " + INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH ,
responses = @ApiResponse ( responseCode = "200" , description = "OK" , content = @Content ( schema = @Schema ( type = "object" , additionalPropertiesSchema = TsData [ ] . class ) ) ) )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/{entityType}/{entityId}/values/timeseries" )
public DeferredResult < ResponseEntity > getLatestTimeseries (
@ -277,6 +289,7 @@ public class TelemetryController extends BaseController {
@Parameter ( description = TELEMETRY_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@Parameter ( description = STRICT_DATA_TYPES_DESCRIPTION )
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
SecurityUser user = getCurrentUser ( ) ;
@ -319,6 +332,9 @@ public class TelemetryController extends BaseController {
+ MARKDOWN_CODE_BLOCK_END
+ "\n\n" + INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH ,
responses = @ApiResponse ( responseCode = "200" , description = "OK" , content = @Content ( schema = @Schema ( type = "object" , additionalPropertiesSchema = TsData [ ] . class ) ) ) )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@PreAuthorize ( "hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')" )
@GetMapping ( value = "/{entityType}/{entityId}/values/timeseries/history" )
public DeferredResult < ResponseEntity > getTimeseriesHistory (
@ -346,6 +362,7 @@ public class TelemetryController extends BaseController {
@RequestParam ( name = "orderBy" , defaultValue = "DESC" ) String orderBy ,
@Parameter ( description = STRICT_DATA_TYPES_DESCRIPTION )
@RequestParam ( name = "useStrictDataTypes" , required = false , defaultValue = "false" ) Boolean useStrictDataTypes ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
DeferredResult < ResponseEntity > response = new DeferredResult < > ( ) ;
@ -485,6 +502,9 @@ public class TelemetryController extends BaseController {
" Use 'rewriteLatestIfDeleted' to rewrite latest value (stored in separate table for performance) if the value's timestamp matches the time-range and 'deleteLatest' param is true." +
" The replacement value will be fetched from the 'time series' table, and its timestamp will be the most recent one before the defined time-range. " +
TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@ApiResponses ( value = {
@ApiResponse ( responseCode = "200" , description = "Time series for the selected keys in the request was removed. " +
"Platform creates an audit log event about entity time series removal with action type 'TIMESERIES_DELETED'." ) ,
@ -509,6 +529,7 @@ public class TelemetryController extends BaseController {
@RequestParam ( name = "deleteLatest" , required = false , defaultValue = "true" ) boolean deleteLatest ,
@Parameter ( description = "If the parameter is set to true, the latest telemetry will be rewritten in case that current latest value was removed, otherwise, in case that parameter is set to false the new latest value will not set." )
@RequestParam ( name = "rewriteLatestIfDeleted" , defaultValue = "false" ) boolean rewriteLatestIfDeleted ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;
@ -566,6 +587,9 @@ public class TelemetryController extends BaseController {
@ApiOperation ( value = "Delete device attributes (deleteDeviceAttributes)" ,
notes = "Delete device attributes using provided Device Id, scope and a list of keys. " +
"Referencing a non-existing Device Id will cause an error" + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@ApiResponses ( value = {
@ApiResponse ( responseCode = "200" , description = "Device attributes was removed for the selected keys in the request. " +
"Platform creates an audit log event about device attributes removal with action type 'ATTRIBUTES_DELETED'." ) ,
@ -580,6 +604,7 @@ public class TelemetryController extends BaseController {
@Parameter ( description = DEVICE_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( DEVICE_ID ) String deviceIdStr ,
@Parameter ( description = ATTRIBUTES_SCOPE_DESCRIPTION , schema = @Schema ( allowableValues = { "SERVER_SCOPE" , "SHARED_SCOPE" , "CLIENT_SCOPE" } , requiredMode = Schema . RequiredMode . REQUIRED ) ) @PathVariable ( "scope" ) AttributeScope scope ,
@Parameter ( description = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
EntityId entityId = EntityIdFactory . getByTypeAndUuid ( EntityType . DEVICE , deviceIdStr ) ;
@ -589,6 +614,9 @@ public class TelemetryController extends BaseController {
@ApiOperation ( value = "Delete entity attributes (deleteEntityAttributes)" ,
notes = "Delete entity attributes using provided Entity Id, scope and a list of keys. " +
INVALID_ENTITY_ID_OR_ENTITY_TYPE_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH )
@Parameters ( {
@Parameter ( name = "key" , description = "Repeatable key query parameter (alternative to comma-separated 'keys')" , in = ParameterIn . QUERY , required = false , array = @ArraySchema ( schema = @Schema ( type = "string" ) ) )
} )
@ApiResponses ( value = {
@ApiResponse ( responseCode = "200" , description = "Entity attributes was removed for the selected keys in the request. " +
"Platform creates an audit log event about entity attributes removal with action type 'ATTRIBUTES_DELETED'." ) ,
@ -604,6 +632,7 @@ public class TelemetryController extends BaseController {
@Parameter ( description = ENTITY_ID_PARAM_DESCRIPTION , required = true ) @PathVariable ( "entityId" ) String entityIdStr ,
@Parameter ( description = ATTRIBUTES_SCOPE_DESCRIPTION , required = true , schema = @Schema ( allowableValues = { "SERVER_SCOPE" , "SHARED_SCOPE" , "CLIENT_SCOPE" } ) ) @PathVariable ( "scope" ) AttributeScope scope ,
@Parameter ( description = ATTRIBUTES_KEYS_DESCRIPTION ) @RequestParam ( name = "keys" , required = false ) String keysStr ,
@Parameter ( hidden = true )
@RequestParam MultiValueMap < String , String > params ) throws ThingsboardException {
List < String > keys = getKeys ( keysStr , params ) ;
EntityId entityId = EntityIdFactory . getByTypeAndId ( entityType , entityIdStr ) ;