...
|
...
|
@@ -26,6 +26,8 @@ import com.google.common.util.concurrent.MoreExecutors; |
26
|
26
|
import com.google.gson.JsonElement;
|
27
|
27
|
import com.google.gson.JsonParseException;
|
28
|
28
|
import com.google.gson.JsonParser;
|
|
29
|
+import io.swagger.annotations.ApiOperation;
|
|
30
|
+import io.swagger.annotations.ApiParam;
|
29
|
31
|
import lombok.extern.slf4j.Slf4j;
|
30
|
32
|
import org.springframework.beans.factory.annotation.Autowired;
|
31
|
33
|
import org.springframework.beans.factory.annotation.Value;
|
...
|
...
|
@@ -48,7 +50,6 @@ import org.thingsboard.server.common.data.EntityType; |
48
|
50
|
import org.thingsboard.server.common.data.TenantProfile;
|
49
|
51
|
import org.thingsboard.server.common.data.audit.ActionType;
|
50
|
52
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
51
|
|
-import org.thingsboard.server.common.data.id.CustomerId;
|
52
|
53
|
import org.thingsboard.server.common.data.id.DeviceId;
|
53
|
54
|
import org.thingsboard.server.common.data.id.EntityId;
|
54
|
55
|
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
...
|
...
|
@@ -108,6 +109,17 @@ import java.util.stream.Collectors; |
108
|
109
|
@Slf4j
|
109
|
110
|
public class TelemetryController extends BaseController {
|
110
|
111
|
|
|
112
|
+ private static final String ATTRIBUTES_SCOPE_DESCRIPTION = "A string value representing the attributes scope. For example, 'SERVER_SCOPE'.";
|
|
113
|
+ private static final String ATTRIBUTES_KEYS_DESCRIPTION = "A string value representing the comma-separated list of attributes keys. For example, 'active,inactivityAlarmTime'.";
|
|
114
|
+ private static final String ATTRIBUTES_SCOPE_ALLOWED_VALUES = "SERVER_SCOPE, CLIENT_SCOPE, SHARED_SCOPE";
|
|
115
|
+ private static final String ATTRIBUTES_JSON_REQUEST_DESCRIPTION = "A string value representing the json object. For example, '{\"key\":\"value\"}'";
|
|
116
|
+
|
|
117
|
+ 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'.";
|
|
118
|
+ private static final String TELEMETRY_SCOPE_DESCRIPTION = "Value is not used in the API call implementation";
|
|
119
|
+ 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\"}}'";
|
|
120
|
+
|
|
121
|
+ 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.";
|
|
122
|
+
|
111
|
123
|
@Autowired
|
112
|
124
|
private TimeseriesService tsService;
|
113
|
125
|
|
...
|
...
|
@@ -133,62 +145,81 @@ public class TelemetryController extends BaseController { |
133
|
145
|
}
|
134
|
146
|
}
|
135
|
147
|
|
|
148
|
+ @ApiOperation(value = "Get all attribute keys (getAttributeKeys)",
|
|
149
|
+ notes = "Returns key names for the selected entity.")
|
136
|
150
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
137
|
151
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/attributes", method = RequestMethod.GET)
|
138
|
152
|
@ResponseBody
|
139
|
153
|
public DeferredResult<ResponseEntity> getAttributeKeys(
|
140
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr) throws ThingsboardException {
|
|
154
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
155
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr) throws ThingsboardException {
|
141
|
156
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_ATTRIBUTES, entityType, entityIdStr, this::getAttributeKeysCallback);
|
142
|
157
|
}
|
143
|
158
|
|
|
159
|
+ @ApiOperation(value = "Get all attributes by scope (getAttributeKeysByScope)",
|
|
160
|
+ notes = "Returns key names of specified scope for the selected entity.")
|
144
|
161
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
145
|
162
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/attributes/{scope}", method = RequestMethod.GET)
|
146
|
163
|
@ResponseBody
|
147
|
164
|
public DeferredResult<ResponseEntity> getAttributeKeysByScope(
|
148
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr
|
149
|
|
- , @PathVariable("scope") String scope) throws ThingsboardException {
|
|
165
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
166
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
167
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope) throws ThingsboardException {
|
150
|
168
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_ATTRIBUTES, entityType, entityIdStr,
|
151
|
169
|
(result, tenantId, entityId) -> getAttributeKeysCallback(result, tenantId, entityId, scope));
|
152
|
170
|
}
|
153
|
171
|
|
|
172
|
+ @ApiOperation(value = "Get attributes (getAttributes)",
|
|
173
|
+ notes = "Returns JSON array of AttributeData objects for the selected entity.")
|
154
|
174
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
155
|
175
|
@RequestMapping(value = "/{entityType}/{entityId}/values/attributes", method = RequestMethod.GET)
|
156
|
176
|
@ResponseBody
|
157
|
177
|
public DeferredResult<ResponseEntity> getAttributes(
|
158
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
159
|
|
- @RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException {
|
|
178
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
179
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
180
|
+ @ApiParam(value = ATTRIBUTES_KEYS_DESCRIPTION) @RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException {
|
160
|
181
|
SecurityUser user = getCurrentUser();
|
161
|
182
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_ATTRIBUTES, entityType, entityIdStr,
|
162
|
183
|
(result, tenantId, entityId) -> getAttributeValuesCallback(result, user, entityId, null, keysStr));
|
163
|
184
|
}
|
164
|
185
|
|
|
186
|
+ @ApiOperation(value = "Get attributes by scope (getAttributesByScope)",
|
|
187
|
+ notes = "Returns JSON array of AttributeData objects for the selected entity.")
|
165
|
188
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
166
|
189
|
@RequestMapping(value = "/{entityType}/{entityId}/values/attributes/{scope}", method = RequestMethod.GET)
|
167
|
190
|
@ResponseBody
|
168
|
191
|
public DeferredResult<ResponseEntity> getAttributesByScope(
|
169
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
170
|
|
- @PathVariable("scope") String scope,
|
171
|
|
- @RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException {
|
|
192
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
193
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
194
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
195
|
+ @ApiParam(value = ATTRIBUTES_KEYS_DESCRIPTION) @RequestParam(name = "keys", required = false) String keysStr) throws ThingsboardException {
|
172
|
196
|
SecurityUser user = getCurrentUser();
|
173
|
197
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_ATTRIBUTES, entityType, entityIdStr,
|
174
|
198
|
(result, tenantId, entityId) -> getAttributeValuesCallback(result, user, entityId, scope, keysStr));
|
175
|
199
|
}
|
176
|
200
|
|
|
201
|
+ @ApiOperation(value = "Get timeseries keys (getTimeseriesKeys)",
|
|
202
|
+ notes = "Returns latest timeseries keys for selected entity.")
|
177
|
203
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
178
|
204
|
@RequestMapping(value = "/{entityType}/{entityId}/keys/timeseries", method = RequestMethod.GET)
|
179
|
205
|
@ResponseBody
|
180
|
206
|
public DeferredResult<ResponseEntity> getTimeseriesKeys(
|
181
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr) throws ThingsboardException {
|
|
207
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
208
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr) throws ThingsboardException {
|
182
|
209
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr,
|
183
|
210
|
(result, tenantId, entityId) -> Futures.addCallback(tsService.findAllLatest(tenantId, entityId), getTsKeysToResponseCallback(result), MoreExecutors.directExecutor()));
|
184
|
211
|
}
|
185
|
212
|
|
|
213
|
+ @ApiOperation(value = "Get latest timeseries (getLatestTimeseries)",
|
|
214
|
+ notes = "Returns JSON object with mapping latest timeseries keys to JSON arrays of TsData objects for the selected entity.")
|
186
|
215
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
187
|
216
|
@RequestMapping(value = "/{entityType}/{entityId}/values/timeseries", method = RequestMethod.GET)
|
188
|
217
|
@ResponseBody
|
189
|
218
|
public DeferredResult<ResponseEntity> getLatestTimeseries(
|
190
|
|
- @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
191
|
|
- @RequestParam(name = "keys", required = false) String keysStr,
|
|
219
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
220
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
221
|
+ @ApiParam(value = TELEMETRY_KEYS_DESCRIPTION) @RequestParam(name = "keys", required = false) String keysStr,
|
|
222
|
+ @ApiParam(value = STRICT_DATA_TYPES_DESCRIPTION)
|
192
|
223
|
@RequestParam(name = "useStrictDataTypes", required = false, defaultValue = "false") Boolean useStrictDataTypes) throws ThingsboardException {
|
193
|
224
|
SecurityUser user = getCurrentUser();
|
194
|
225
|
|
...
|
...
|
@@ -196,20 +227,30 @@ public class TelemetryController extends BaseController { |
196
|
227
|
(result, tenantId, entityId) -> getLatestTimeseriesValuesCallback(result, user, entityId, keysStr, useStrictDataTypes));
|
197
|
228
|
}
|
198
|
229
|
|
199
|
|
-
|
|
230
|
+ @ApiOperation(value = "Get timeseries (getTimeseries)",
|
|
231
|
+ notes = "Returns JSON object with mapping timeseries keys to JSON arrays of TsData objects based on specified filters for the selected entity.")
|
200
|
232
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
201
|
233
|
@RequestMapping(value = "/{entityType}/{entityId}/values/timeseries", method = RequestMethod.GET, params = {"keys", "startTs", "endTs"})
|
202
|
234
|
@ResponseBody
|
203
|
235
|
public DeferredResult<ResponseEntity> getTimeseries(
|
204
|
|
- @PathVariable("entityType") String entityType,
|
205
|
|
- @PathVariable("entityId") String entityIdStr,
|
206
|
|
- @RequestParam(name = "keys") String keys,
|
|
236
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
237
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
238
|
+ @ApiParam(value = TELEMETRY_KEYS_DESCRIPTION) @RequestParam(name = "keys") String keys,
|
|
239
|
+ @ApiParam(value = "A long value representing the start timestamp(milliseconds) of search time range.")
|
207
|
240
|
@RequestParam(name = "startTs") Long startTs,
|
|
241
|
+ @ApiParam(value = "A long value representing the end timestamp(milliseconds) of search time range.")
|
208
|
242
|
@RequestParam(name = "endTs") Long endTs,
|
|
243
|
+ @ApiParam(value = "A long value representing the aggregation interval(milliseconds) range.")
|
209
|
244
|
@RequestParam(name = "interval", defaultValue = "0") Long interval,
|
|
245
|
+ @ApiParam(value = "An integer value representing max number of selected data points.", defaultValue = "100")
|
210
|
246
|
@RequestParam(name = "limit", defaultValue = "100") Integer limit,
|
|
247
|
+ @ApiParam(value = "A string value representing the aggregation function. " +
|
|
248
|
+ "If the interval is not specified, 'agg' parameter will be converted to 'NONE' value.",
|
|
249
|
+ allowableValues = "MIN, MAX, AVG, SUM, COUNT, NONE")
|
211
|
250
|
@RequestParam(name = "agg", defaultValue = "NONE") String aggStr,
|
|
251
|
+ @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
212
|
252
|
@RequestParam(name = "orderBy", defaultValue = "DESC") String orderBy,
|
|
253
|
+ @ApiParam(value = STRICT_DATA_TYPES_DESCRIPTION)
|
213
|
254
|
@RequestParam(name = "useStrictDataTypes", required = false, defaultValue = "false") Boolean useStrictDataTypes) throws ThingsboardException {
|
214
|
255
|
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr,
|
215
|
256
|
(result, tenantId, entityId) -> {
|
...
|
...
|
@@ -222,64 +263,89 @@ public class TelemetryController extends BaseController { |
222
|
263
|
});
|
223
|
264
|
}
|
224
|
265
|
|
|
266
|
+ @ApiOperation(value = "Save or update device attributes (saveDeviceAttributes)")
|
225
|
267
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
226
|
268
|
@RequestMapping(value = "/{deviceId}/{scope}", method = RequestMethod.POST)
|
227
|
269
|
@ResponseBody
|
228
|
|
- public DeferredResult<ResponseEntity> saveDeviceAttributes(@PathVariable("deviceId") String deviceIdStr, @PathVariable("scope") String scope,
|
229
|
|
- @RequestBody JsonNode request) throws ThingsboardException {
|
|
270
|
+ public DeferredResult<ResponseEntity> saveDeviceAttributes(
|
|
271
|
+ @ApiParam(value = DEVICE_ID_PARAM_DESCRIPTION) @PathVariable("deviceId") String deviceIdStr,
|
|
272
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
273
|
+ @ApiParam(value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION) @RequestBody JsonNode request) throws ThingsboardException {
|
230
|
274
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(EntityType.DEVICE, deviceIdStr);
|
231
|
275
|
return saveAttributes(getTenantId(), entityId, scope, request);
|
232
|
276
|
}
|
233
|
277
|
|
|
278
|
+ @ApiOperation(value = "Save or update attributes (saveEntityAttributesV1)")
|
234
|
279
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
235
|
280
|
@RequestMapping(value = "/{entityType}/{entityId}/{scope}", method = RequestMethod.POST)
|
236
|
281
|
@ResponseBody
|
237
|
|
- public DeferredResult<ResponseEntity> saveEntityAttributesV1(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
238
|
|
- @PathVariable("scope") String scope,
|
239
|
|
- @RequestBody JsonNode request) throws ThingsboardException {
|
|
282
|
+ public DeferredResult<ResponseEntity> saveEntityAttributesV1(
|
|
283
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
284
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
285
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
286
|
+ @ApiParam(value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION) @RequestBody JsonNode request) throws ThingsboardException {
|
240
|
287
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
241
|
288
|
return saveAttributes(getTenantId(), entityId, scope, request);
|
242
|
289
|
}
|
243
|
290
|
|
|
291
|
+ @ApiOperation(value = "Save or update attributes (saveEntityAttributesV2)")
|
244
|
292
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
245
|
293
|
@RequestMapping(value = "/{entityType}/{entityId}/attributes/{scope}", method = RequestMethod.POST)
|
246
|
294
|
@ResponseBody
|
247
|
|
- public DeferredResult<ResponseEntity> saveEntityAttributesV2(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
248
|
|
- @PathVariable("scope") String scope,
|
249
|
|
- @RequestBody JsonNode request) throws ThingsboardException {
|
|
295
|
+ public DeferredResult<ResponseEntity> saveEntityAttributesV2(
|
|
296
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
297
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
298
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
299
|
+ @ApiParam(value = ATTRIBUTES_JSON_REQUEST_DESCRIPTION) @RequestBody JsonNode request) throws ThingsboardException {
|
250
|
300
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
251
|
301
|
return saveAttributes(getTenantId(), entityId, scope, request);
|
252
|
302
|
}
|
253
|
303
|
|
|
304
|
+ @ApiOperation(value = "Save or update telemetry (saveEntityTelemetry)")
|
254
|
305
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
255
|
306
|
@RequestMapping(value = "/{entityType}/{entityId}/timeseries/{scope}", method = RequestMethod.POST)
|
256
|
307
|
@ResponseBody
|
257
|
|
- public DeferredResult<ResponseEntity> saveEntityTelemetry(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
258
|
|
- @PathVariable("scope") String scope,
|
259
|
|
- @RequestBody String requestBody) throws ThingsboardException {
|
|
308
|
+ public DeferredResult<ResponseEntity> saveEntityTelemetry(
|
|
309
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
310
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
311
|
+ @ApiParam(value = TELEMETRY_SCOPE_DESCRIPTION) @PathVariable("scope") String scope,
|
|
312
|
+ @ApiParam(value = TELEMETRY_JSON_REQUEST_DESCRIPTION) @RequestBody String requestBody) throws ThingsboardException {
|
260
|
313
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
261
|
314
|
return saveTelemetry(getTenantId(), entityId, requestBody, 0L);
|
262
|
315
|
}
|
263
|
316
|
|
|
317
|
+ @ApiOperation(value = "Save or update telemetry with TTL (saveEntityTelemetryWithTTL)",
|
|
318
|
+ notes = "The TTL parameter is used to extract the number of days to store the data.")
|
264
|
319
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
265
|
320
|
@RequestMapping(value = "/{entityType}/{entityId}/timeseries/{scope}/{ttl}", method = RequestMethod.POST)
|
266
|
321
|
@ResponseBody
|
267
|
|
- public DeferredResult<ResponseEntity> saveEntityTelemetryWithTTL(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
268
|
|
- @PathVariable("scope") String scope, @PathVariable("ttl") Long ttl,
|
269
|
|
- @RequestBody String requestBody) throws ThingsboardException {
|
|
322
|
+ public DeferredResult<ResponseEntity> saveEntityTelemetryWithTTL(
|
|
323
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
324
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
325
|
+ @ApiParam(value = TELEMETRY_SCOPE_DESCRIPTION) @PathVariable("scope") String scope,
|
|
326
|
+ @ApiParam(value = "A long value representing TTL(Time to Live) parameter.") @PathVariable("ttl") Long ttl,
|
|
327
|
+ @ApiParam(value = TELEMETRY_JSON_REQUEST_DESCRIPTION) @RequestBody String requestBody) throws ThingsboardException {
|
270
|
328
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
271
|
329
|
return saveTelemetry(getTenantId(), entityId, requestBody, ttl);
|
272
|
330
|
}
|
273
|
331
|
|
|
332
|
+ @ApiOperation(value = "Delete entity timeseries (deleteEntityTimeseries)",
|
|
333
|
+ notes = "Delete timeseries in the specified time range for selected entity.")
|
274
|
334
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
275
|
335
|
@RequestMapping(value = "/{entityType}/{entityId}/timeseries/delete", method = RequestMethod.DELETE)
|
276
|
336
|
@ResponseBody
|
277
|
|
- public DeferredResult<ResponseEntity> deleteEntityTimeseries(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
278
|
|
- @RequestParam(name = "keys") String keysStr,
|
279
|
|
- @RequestParam(name = "deleteAllDataForKeys", defaultValue = "false") boolean deleteAllDataForKeys,
|
280
|
|
- @RequestParam(name = "startTs", required = false) Long startTs,
|
281
|
|
- @RequestParam(name = "endTs", required = false) Long endTs,
|
282
|
|
- @RequestParam(name = "rewriteLatestIfDeleted", defaultValue = "false") boolean rewriteLatestIfDeleted) throws ThingsboardException {
|
|
337
|
+ public DeferredResult<ResponseEntity> deleteEntityTimeseries(
|
|
338
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
339
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
340
|
+ @ApiParam(value = TELEMETRY_KEYS_DESCRIPTION) @RequestParam(name = "keys") String keysStr,
|
|
341
|
+ @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.")
|
|
342
|
+ @RequestParam(name = "deleteAllDataForKeys", defaultValue = "false") boolean deleteAllDataForKeys,
|
|
343
|
+ @ApiParam(value = "A long value representing the start timestamp(milliseconds) of removal time range.")
|
|
344
|
+ @RequestParam(name = "startTs", required = false) Long startTs,
|
|
345
|
+ @ApiParam(value = "A long value representing the end timestamp(milliseconds) of removal time range.")
|
|
346
|
+ @RequestParam(name = "endTs", required = false) Long endTs,
|
|
347
|
+ @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.")
|
|
348
|
+ @RequestParam(name = "rewriteLatestIfDeleted", defaultValue = "false") boolean rewriteLatestIfDeleted) throws ThingsboardException {
|
283
|
349
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
284
|
350
|
return deleteTimeseries(entityId, keysStr, deleteAllDataForKeys, startTs, endTs, rewriteLatestIfDeleted);
|
285
|
351
|
}
|
...
|
...
|
@@ -311,7 +377,6 @@ public class TelemetryController extends BaseController { |
311
|
377
|
for (String key : keys) {
|
312
|
378
|
deleteTsKvQueries.add(new BaseDeleteTsKvQuery(key, deleteFromTs, deleteToTs, rewriteLatestIfDeleted));
|
313
|
379
|
}
|
314
|
|
-
|
315
|
380
|
ListenableFuture<List<Void>> future = tsService.remove(user.getTenantId(), entityId, deleteTsKvQueries);
|
316
|
381
|
Futures.addCallback(future, new FutureCallback<List<Void>>() {
|
317
|
382
|
@Override
|
...
|
...
|
@@ -329,22 +394,29 @@ public class TelemetryController extends BaseController { |
329
|
394
|
});
|
330
|
395
|
}
|
331
|
396
|
|
|
397
|
+ @ApiOperation(value = "Delete device attributes (deleteEntityAttributes)",
|
|
398
|
+ notes = "Delete attributes of specified scope for selected device.")
|
332
|
399
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
333
|
400
|
@RequestMapping(value = "/{deviceId}/{scope}", method = RequestMethod.DELETE)
|
334
|
401
|
@ResponseBody
|
335
|
|
- public DeferredResult<ResponseEntity> deleteEntityAttributes(@PathVariable("deviceId") String deviceIdStr,
|
336
|
|
- @PathVariable("scope") String scope,
|
337
|
|
- @RequestParam(name = "keys") String keysStr) throws ThingsboardException {
|
|
402
|
+ public DeferredResult<ResponseEntity> deleteEntityAttributes(
|
|
403
|
+ @ApiParam(value = DEVICE_ID_PARAM_DESCRIPTION) @PathVariable("deviceId") String deviceIdStr,
|
|
404
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
405
|
+ @ApiParam(value = ATTRIBUTES_KEYS_DESCRIPTION) @RequestParam(name = "keys") String keysStr) throws ThingsboardException {
|
338
|
406
|
EntityId entityId = EntityIdFactory.getByTypeAndUuid(EntityType.DEVICE, deviceIdStr);
|
339
|
407
|
return deleteAttributes(entityId, scope, keysStr);
|
340
|
408
|
}
|
341
|
409
|
|
|
410
|
+ @ApiOperation(value = "Delete entity attributes (deleteEntityAttributes)",
|
|
411
|
+ notes = "Delete attributes of specified scope for selected entity.")
|
342
|
412
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
343
|
413
|
@RequestMapping(value = "/{entityType}/{entityId}/{scope}", method = RequestMethod.DELETE)
|
344
|
414
|
@ResponseBody
|
345
|
|
- public DeferredResult<ResponseEntity> deleteEntityAttributes(@PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr,
|
346
|
|
- @PathVariable("scope") String scope,
|
347
|
|
- @RequestParam(name = "keys") String keysStr) throws ThingsboardException {
|
|
415
|
+ public DeferredResult<ResponseEntity> deleteEntityAttributes(
|
|
416
|
+ @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION) @PathVariable("entityType") String entityType,
|
|
417
|
+ @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @PathVariable("entityId") String entityIdStr,
|
|
418
|
+ @ApiParam(value = ATTRIBUTES_SCOPE_DESCRIPTION, allowableValues = ATTRIBUTES_SCOPE_ALLOWED_VALUES) @PathVariable("scope") String scope,
|
|
419
|
+ @ApiParam(value = ATTRIBUTES_KEYS_DESCRIPTION) @RequestParam(name = "keys") String keysStr) throws ThingsboardException {
|
348
|
420
|
EntityId entityId = EntityIdFactory.getByTypeAndId(entityType, entityIdStr);
|
349
|
421
|
return deleteAttributes(entityId, scope, keysStr);
|
350
|
422
|
}
|
...
|
...
|
|