Commit 4783d7dd62c990ab9fb7b68babec1e308688f7cd

Authored by Andrii Shvaika
2 parents 90f7ff57 b032b5ac

Merge with main branch

... ... @@ -217,7 +217,7 @@ public class AlarmController extends BaseController {
217 217 @RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
218 218 @ResponseBody
219 219 public PageData<AlarmInfo> getAlarms(
220   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION)
  220 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION)
221 221 @PathVariable(ENTITY_TYPE) String strEntityType,
222 222 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION)
223 223 @PathVariable(ENTITY_ID) String strEntityId,
... ... @@ -318,7 +318,7 @@ public class AlarmController extends BaseController {
318 318 @RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET)
319 319 @ResponseBody
320 320 public AlarmSeverity getHighestAlarmSeverity(
321   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
  321 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
322 322 @PathVariable(ENTITY_TYPE) String strEntityType,
323 323 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
324 324 @PathVariable(ENTITY_ID) String strEntityId,
... ...
... ... @@ -172,7 +172,7 @@ public abstract class BaseController {
172 172 public static final String ASSET_ID_PARAM_DESCRIPTION = "A string value representing the asset id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
173 173 public static final String ALARM_ID_PARAM_DESCRIPTION = "A string value representing the alarm id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
174 174 public static final String ENTITY_ID_PARAM_DESCRIPTION = "A string value representing the entity id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
175   - public static final String ENTITY_TYPE_DESCRIPTION = "A string value representing the entity type. For example, 'DEVICE'";
  175 + public static final String ENTITY_TYPE_PARAM_DESCRIPTION = "A string value representing the entity type. For example, 'DEVICE'";
176 176
177 177 protected final String PAGE_SIZE_DESCRIPTION = "Maximum amount of entities in a one page";
178 178 protected final String PAGE_NUMBER_DESCRIPTION = "Sequence number of page starting from 0";
... ...
... ... @@ -105,11 +105,11 @@ public class EntityRelationController extends BaseController {
105 105 @RequestMapping(value = "/relation", method = RequestMethod.DELETE, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE})
106 106 @ResponseStatus(value = HttpStatus.OK)
107 107 public void deleteRelation(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_ID) String strFromId,
108   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
  108 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
109 109 @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(RELATION_TYPE) String strRelationType,
110 110 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION) @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
111 111 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(TO_ID) String strToId,
112   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
  112 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
113 113 checkParameter(FROM_ID, strFromId);
114 114 checkParameter(FROM_TYPE, strFromType);
115 115 checkParameter(RELATION_TYPE, strRelationType);
... ... @@ -148,7 +148,7 @@ public class EntityRelationController extends BaseController {
148 148 @RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = {"entityId", "entityType"})
149 149 @ResponseStatus(value = HttpStatus.OK)
150 150 public void deleteRelations(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam("entityId") String strId,
151   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam("entityType") String strType) throws ThingsboardException {
  151 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam("entityType") String strType) throws ThingsboardException {
152 152 checkParameter("entityId", strId);
153 153 checkParameter("entityType", strType);
154 154 EntityId entityId = EntityIdFactory.getByTypeAndId(strType, strId);
... ... @@ -169,11 +169,11 @@ public class EntityRelationController extends BaseController {
169 169 @RequestMapping(value = "/relation", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE})
170 170 @ResponseBody
171 171 public EntityRelation getRelation(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_ID) String strFromId,
172   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
  172 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
173 173 @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(RELATION_TYPE) String strRelationType,
174 174 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION) @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
175 175 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(TO_ID) String strToId,
176   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
  176 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
177 177 try {
178 178 checkParameter(FROM_ID, strFromId);
179 179 checkParameter(FROM_TYPE, strFromType);
... ... @@ -199,7 +199,7 @@ public class EntityRelationController extends BaseController {
199 199 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE})
200 200 @ResponseBody
201 201 public List<EntityRelation> findByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_ID) String strFromId,
202   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
  202 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
203 203 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
204 204 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
205 205 checkParameter(FROM_ID, strFromId);
... ... @@ -222,7 +222,7 @@ public class EntityRelationController extends BaseController {
222 222 @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE})
223 223 @ResponseBody
224 224 public List<EntityRelationInfo> findInfoByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_ID) String strFromId,
225   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
  225 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
226 226 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
227 227 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
228 228 checkParameter(FROM_ID, strFromId);
... ... @@ -245,7 +245,7 @@ public class EntityRelationController extends BaseController {
245 245 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE})
246 246 @ResponseBody
247 247 public List<EntityRelation> findByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_ID) String strFromId,
248   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
  248 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(FROM_TYPE) String strFromType,
249 249 @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(RELATION_TYPE) String strRelationType,
250 250 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
251 251 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
... ... @@ -270,7 +270,7 @@ public class EntityRelationController extends BaseController {
270 270 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE})
271 271 @ResponseBody
272 272 public List<EntityRelation> findByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(TO_ID) String strToId,
273   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
  273 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
274 274 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
275 275 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
276 276 checkParameter(TO_ID, strToId);
... ... @@ -293,7 +293,7 @@ public class EntityRelationController extends BaseController {
293 293 @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {TO_ID, TO_TYPE})
294 294 @ResponseBody
295 295 public List<EntityRelationInfo> findInfoByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(TO_ID) String strToId,
296   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
  296 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
297 297 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
298 298 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
299 299 checkParameter(TO_ID, strToId);
... ... @@ -316,7 +316,7 @@ public class EntityRelationController extends BaseController {
316 316 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE, RELATION_TYPE})
317 317 @ResponseBody
318 318 public List<EntityRelation> findByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) @RequestParam(TO_ID) String strToId,
319   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
  319 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(TO_TYPE) String strToType,
320 320 @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION, required = true) @RequestParam(RELATION_TYPE) String strRelationType,
321 321 @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
322 322 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
... ...
... ... @@ -55,7 +55,7 @@ public class EventController extends BaseController {
55 55 @RequestMapping(value = "/events/{entityType}/{entityId}/{eventType}", method = RequestMethod.GET)
56 56 @ResponseBody
57 57 public PageData<Event> getEvents(
58   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
  58 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
59 59 @PathVariable(ENTITY_TYPE) String strEntityType,
60 60 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
61 61 @PathVariable(ENTITY_ID) String strEntityId,
... ... @@ -98,7 +98,7 @@ public class EventController extends BaseController {
98 98 @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.GET)
99 99 @ResponseBody
100 100 public PageData<Event> getEvents(
101   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
  101 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
102 102 @PathVariable(ENTITY_TYPE) String strEntityType,
103 103 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
104 104 @PathVariable(ENTITY_ID) String strEntityId,
... ... @@ -141,7 +141,7 @@ public class EventController extends BaseController {
141 141 @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.POST)
142 142 @ResponseBody
143 143 public PageData<Event> getEvents(
144   - @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
  144 + @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
145 145 @PathVariable(ENTITY_TYPE) String strEntityType,
146 146 @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
147 147 @PathVariable(ENTITY_ID) String strEntityId,
... ...
... ... @@ -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 }
... ...