Commit 041582b9c7bf9fd851047df8c6f66a799c82c2e1

Authored by Dima Landiak
1 parent 8cb0622d

entity relation controller description

... ... @@ -169,6 +169,8 @@ public abstract class BaseController {
169 169 public static final String CUSTOMER_ID_PARAM_DESCRIPTION = "A string value representing the customer id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
170 170 public static final String ASSET_ID_PARAM_DESCRIPTION = "A string value representing the asset id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
171 171
  172 + protected static final String ENTITY_ID_PARAM_DESCRIPTION = "A string value representing the entity id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'";
  173 + protected static final String ENTITY_TYPE_DESCRIPTION = "A string value representing the entity type. For example, 'DEVICE'";
172 174
173 175 protected final String PAGE_SIZE_DESCRIPTION = "Maximum amount of entities in a one page";
174 176 protected final String PAGE_NUMBER_DESCRIPTION = "Sequence number of page starting from 0";
... ... @@ -188,11 +190,15 @@ public abstract class BaseController {
188 190 protected final String SORT_ORDER_ALLOWABLE_VALUES = "ASC, DESC";
189 191 protected final String DEVICE_INFO_DESCRIPTION = "Device Info is an extension of the default Device object that contains information about the assigned customer name and device profile name. ";
190 192 protected final String ASSET_INFO_DESCRIPTION = "Asset Info is an extension of the default Asset object that contains information about the assigned customer name. ";
  193 + protected final String RELATION_INFO_DESCRIPTION = "Relation Info is an extension of the default Relation object that contains information about the 'from' and 'to' entity names. ";
191 194
192 195
193 196 protected final String DEVICE_NAME_DESCRIPTION = "A string value representing the Device name.";
194 197 protected final String ASSET_NAME_DESCRIPTION = "A string value representing the Asset name.";
195 198
  199 + protected static final String RELATION_TYPE_PARAM_DESCRIPTION = "A string value representing relation type between entities. For example, 'Contains', 'Manages'. It can be any string value.";
  200 + protected static final String RELATION_TYPE_GROUP_PARAM_DESCRIPTION = "A string value representing relation type group. For example, 'COMMON'";
  201 +
196 202 public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
197 203 protected static final String DEFAULT_DASHBOARD = "defaultDashboardId";
198 204 protected static final String HOME_DASHBOARD = "homeDashboardId";
... ...
... ... @@ -15,7 +15,10 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
  18 +import io.swagger.annotations.ApiOperation;
  19 +import io.swagger.annotations.ApiParam;
18 20 import org.springframework.http.HttpStatus;
  21 +import org.springframework.http.MediaType;
19 22 import org.springframework.security.access.prepost.PreAuthorize;
20 23 import org.springframework.web.bind.annotation.RequestBody;
21 24 import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -52,10 +55,16 @@ public class EntityRelationController extends BaseController {
52 55 public static final String RELATION_TYPE = "relationType";
53 56 public static final String TO_ID = "toId";
54 57
  58 + @ApiOperation(value = "Create Relation (saveRelation)",
  59 + notes = "Creates a relation between two entities in the platform. " +
  60 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  61 + "If the user has the authority of 'Tenant Administrator', the server checks that 'from' and 'to' entities are owned by the same tenant. " +
  62 + "If the user has the authority of 'Customer User', the server checks that the 'from' and 'to' entities are assigned to the same customer.")
55 63 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
56 64 @RequestMapping(value = "/relation", method = RequestMethod.POST)
57 65 @ResponseStatus(value = HttpStatus.OK)
58   - public void saveRelation(@RequestBody EntityRelation relation) throws ThingsboardException {
  66 + public void saveRelation(@ApiParam(value = "A JSON value representing the relation.")
  67 + @RequestBody EntityRelation relation) throws ThingsboardException {
59 68 try {
60 69 checkNotNull(relation);
61 70 checkEntityId(relation.getFrom(), Operation.WRITE);
... ... @@ -80,14 +89,20 @@ public class EntityRelationController extends BaseController {
80 89 }
81 90 }
82 91
  92 + @ApiOperation(value = "Delete Relation (deleteRelation)",
  93 + notes = "Deletes a relation between two entities in the platform. " +
  94 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  95 + "If the user has the authority of 'Tenant Administrator', the server checks that 'from' and 'to' entities are owned by the same tenant. " +
  96 + "If the user has the authority of 'Customer User', the server checks that the 'from' and 'to' entities are assigned to the same customer.")
83 97 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
84 98 @RequestMapping(value = "/relation", method = RequestMethod.DELETE, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE})
85 99 @ResponseStatus(value = HttpStatus.OK)
86   - public void deleteRelation(@RequestParam(FROM_ID) String strFromId,
87   - @RequestParam(FROM_TYPE) String strFromType,
88   - @RequestParam(RELATION_TYPE) String strRelationType,
89   - @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
90   - @RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
  100 + public void deleteRelation(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(FROM_ID) String strFromId,
  101 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(FROM_TYPE) String strFromType,
  102 + @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION) @RequestParam(RELATION_TYPE) String strRelationType,
  103 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION) @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
  104 + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(TO_ID) String strToId,
  105 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
91 106 checkParameter(FROM_ID, strFromId);
92 107 checkParameter(FROM_TYPE, strFromType);
93 108 checkParameter(RELATION_TYPE, strRelationType);
... ... @@ -119,11 +134,16 @@ public class EntityRelationController extends BaseController {
119 134 }
120 135 }
121 136
  137 + @ApiOperation(value = "Delete Relations (deleteRelations)",
  138 + notes = "Deletes all the relation (both 'from' and 'to' direction) for the specified entity. " +
  139 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  140 + "If the user has the authority of 'Tenant Administrator', the server checks that entity is owned by the same tenant. " +
  141 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.")
122 142 @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')")
123   - @RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = {"id", "type"})
  143 + @RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = {"entityId", "entityType"})
124 144 @ResponseStatus(value = HttpStatus.OK)
125   - public void deleteRelations(@RequestParam("entityId") String strId,
126   - @RequestParam("entityType") String strType) throws ThingsboardException {
  145 + public void deleteRelations(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam("entityId") String strId,
  146 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam("entityType") String strType) throws ThingsboardException {
127 147 checkParameter("entityId", strId);
128 148 checkParameter("entityType", strType);
129 149 EntityId entityId = EntityIdFactory.getByTypeAndId(strType, strId);
... ... @@ -137,14 +157,21 @@ public class EntityRelationController extends BaseController {
137 157 }
138 158 }
139 159
  160 + @ApiOperation(value = "Get Relation (getRelation)",
  161 + notes = "Returns relation object between two specified entities if present. Otherwise throws exception." +
  162 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  163 + "If the user has the authority of 'Tenant Administrator', the server checks that 'from' and 'to' entities are owned by the same tenant. " +
  164 + "If the user has the authority of 'Customer User', the server checks that the 'from' and 'to' entities are assigned to the same customer.",
  165 + produces = MediaType.APPLICATION_JSON_VALUE)
140 166 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
141 167 @RequestMapping(value = "/relation", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE})
142 168 @ResponseBody
143   - public EntityRelation getRelation(@RequestParam(FROM_ID) String strFromId,
144   - @RequestParam(FROM_TYPE) String strFromType,
145   - @RequestParam(RELATION_TYPE) String strRelationType,
146   - @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
147   - @RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
  169 + public EntityRelation getRelation(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(FROM_ID) String strFromId,
  170 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(FROM_TYPE) String strFromType,
  171 + @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION) @RequestParam(RELATION_TYPE) String strRelationType,
  172 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION) @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup,
  173 + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(TO_ID) String strToId,
  174 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
148 175 try {
149 176 checkParameter(FROM_ID, strFromId);
150 177 checkParameter(FROM_TYPE, strFromType);
... ... @@ -162,11 +189,18 @@ public class EntityRelationController extends BaseController {
162 189 }
163 190 }
164 191
  192 + @ApiOperation(value = "Get List of Relations (findByFrom)",
  193 + notes = "Returns list of relation objects for the specified entity by the 'from' direction. " +
  194 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  195 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  196 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.",
  197 + produces = MediaType.APPLICATION_JSON_VALUE)
165 198 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
166 199 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE})
167 200 @ResponseBody
168   - public List<EntityRelation> findByFrom(@RequestParam(FROM_ID) String strFromId,
169   - @RequestParam(FROM_TYPE) String strFromType,
  201 + public List<EntityRelation> findByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(FROM_ID) String strFromId,
  202 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(FROM_TYPE) String strFromType,
  203 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
170 204 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
171 205 checkParameter(FROM_ID, strFromId);
172 206 checkParameter(FROM_TYPE, strFromType);
... ... @@ -180,11 +214,18 @@ public class EntityRelationController extends BaseController {
180 214 }
181 215 }
182 216
  217 + @ApiOperation(value = "Get List of Relation Infos (findInfoByFrom)",
  218 + notes = "Returns list of relation info objects for the specified entity by the 'from' direction. " +
  219 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  220 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  221 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer. " + RELATION_INFO_DESCRIPTION,
  222 + produces = MediaType.APPLICATION_JSON_VALUE)
183 223 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
184 224 @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE})
185 225 @ResponseBody
186   - public List<EntityRelationInfo> findInfoByFrom(@RequestParam(FROM_ID) String strFromId,
187   - @RequestParam(FROM_TYPE) String strFromType,
  226 + public List<EntityRelationInfo> findInfoByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(FROM_ID) String strFromId,
  227 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(FROM_TYPE) String strFromType,
  228 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
188 229 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
189 230 checkParameter(FROM_ID, strFromId);
190 231 checkParameter(FROM_TYPE, strFromType);
... ... @@ -198,12 +239,19 @@ public class EntityRelationController extends BaseController {
198 239 }
199 240 }
200 241
  242 + @ApiOperation(value = "Get List of Relations (findByFrom)",
  243 + notes = "Returns list of relation objects for the specified entity by the 'from' direction and relation type. " +
  244 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  245 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  246 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.",
  247 + produces = MediaType.APPLICATION_JSON_VALUE)
201 248 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
202 249 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {FROM_ID, FROM_TYPE, RELATION_TYPE})
203 250 @ResponseBody
204   - public List<EntityRelation> findByFrom(@RequestParam(FROM_ID) String strFromId,
205   - @RequestParam(FROM_TYPE) String strFromType,
206   - @RequestParam(RELATION_TYPE) String strRelationType,
  251 + public List<EntityRelation> findByFrom(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(FROM_ID) String strFromId,
  252 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(FROM_TYPE) String strFromType,
  253 + @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION) @RequestParam(RELATION_TYPE) String strRelationType,
  254 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
207 255 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
208 256 checkParameter(FROM_ID, strFromId);
209 257 checkParameter(FROM_TYPE, strFromType);
... ... @@ -218,11 +266,18 @@ public class EntityRelationController extends BaseController {
218 266 }
219 267 }
220 268
  269 + @ApiOperation(value = "Get List of Relations (findByTo)",
  270 + notes = "Returns list of relation objects for the specified entity by the 'to' direction. " +
  271 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  272 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  273 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.",
  274 + produces = MediaType.APPLICATION_JSON_VALUE)
221 275 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
222 276 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE})
223 277 @ResponseBody
224   - public List<EntityRelation> findByTo(@RequestParam(TO_ID) String strToId,
225   - @RequestParam(TO_TYPE) String strToType,
  278 + public List<EntityRelation> findByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(TO_ID) String strToId,
  279 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(TO_TYPE) String strToType,
  280 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
226 281 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
227 282 checkParameter(TO_ID, strToId);
228 283 checkParameter(TO_TYPE, strToType);
... ... @@ -236,11 +291,18 @@ public class EntityRelationController extends BaseController {
236 291 }
237 292 }
238 293
  294 + @ApiOperation(value = "Get List of Relation Infos (findInfoByTo)",
  295 + notes = "Returns list of relation info objects for the specified entity by the 'to' direction. " +
  296 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  297 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  298 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer. " + RELATION_INFO_DESCRIPTION,
  299 + produces = MediaType.APPLICATION_JSON_VALUE)
239 300 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
240 301 @RequestMapping(value = "/relations/info", method = RequestMethod.GET, params = {TO_ID, TO_TYPE})
241 302 @ResponseBody
242   - public List<EntityRelationInfo> findInfoByTo(@RequestParam(TO_ID) String strToId,
243   - @RequestParam(TO_TYPE) String strToType,
  303 + public List<EntityRelationInfo> findInfoByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(TO_ID) String strToId,
  304 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(TO_TYPE) String strToType,
  305 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
244 306 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
245 307 checkParameter(TO_ID, strToId);
246 308 checkParameter(TO_TYPE, strToType);
... ... @@ -254,12 +316,19 @@ public class EntityRelationController extends BaseController {
254 316 }
255 317 }
256 318
  319 + @ApiOperation(value = "Get List of Relations (findByTo)",
  320 + notes = "Returns list of relation objects for the specified entity by the 'to' direction and relation type. " +
  321 + "If the user has the authority of 'System Administrator', the server checks that 'from' and 'to' entities are owned by the sysadmin. " +
  322 + "If the user has the authority of 'Tenant Administrator', the server checks that the entity is owned by the same tenant. " +
  323 + "If the user has the authority of 'Customer User', the server checks that the entity is assigned to the same customer.",
  324 + produces = MediaType.APPLICATION_JSON_VALUE)
257 325 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
258 326 @RequestMapping(value = "/relations", method = RequestMethod.GET, params = {TO_ID, TO_TYPE, RELATION_TYPE})
259 327 @ResponseBody
260   - public List<EntityRelation> findByTo(@RequestParam(TO_ID) String strToId,
261   - @RequestParam(TO_TYPE) String strToType,
262   - @RequestParam(RELATION_TYPE) String strRelationType,
  328 + public List<EntityRelation> findByTo(@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) @RequestParam(TO_ID) String strToId,
  329 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION) @RequestParam(TO_TYPE) String strToType,
  330 + @ApiParam(value = RELATION_TYPE_PARAM_DESCRIPTION) @RequestParam(RELATION_TYPE) String strRelationType,
  331 + @ApiParam(value = RELATION_TYPE_GROUP_PARAM_DESCRIPTION)
263 332 @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup) throws ThingsboardException {
264 333 checkParameter(TO_ID, strToId);
265 334 checkParameter(TO_TYPE, strToType);
... ... @@ -274,10 +343,15 @@ public class EntityRelationController extends BaseController {
274 343 }
275 344 }
276 345
  346 + @ApiOperation(value = "Find related entities (findByQuery)",
  347 + notes = "Returns all entities that are related to the specific entity. " +
  348 + "The entity id, relation type, entity types, depth of the search, and other query parameters defined using complex 'EntityRelationsQuery' object. " +
  349 + "See 'Model' tab of the Parameters for more info.", produces = MediaType.APPLICATION_JSON_VALUE)
277 350 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
278 351 @RequestMapping(value = "/relations", method = RequestMethod.POST)
279 352 @ResponseBody
280   - public List<EntityRelation> findByQuery(@RequestBody EntityRelationsQuery query) throws ThingsboardException {
  353 + public List<EntityRelation> findByQuery(@ApiParam(value = "A JSON value representing the entity relations query object.")
  354 + @RequestBody EntityRelationsQuery query) throws ThingsboardException {
281 355 checkNotNull(query);
282 356 checkNotNull(query.getParameters());
283 357 checkNotNull(query.getFilters());
... ... @@ -289,10 +363,15 @@ public class EntityRelationController extends BaseController {
289 363 }
290 364 }
291 365
  366 + @ApiOperation(value = "Find related entity infos (findInfoByQuery)",
  367 + notes = "Returns all entity infos that are related to the specific entity. " +
  368 + "The entity id, relation type, entity types, depth of the search, and other query parameters defined using complex 'EntityRelationsQuery' object. " +
  369 + "See 'Model' tab of the Parameters for more info. " + RELATION_INFO_DESCRIPTION, produces = MediaType.APPLICATION_JSON_VALUE)
292 370 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
293 371 @RequestMapping(value = "/relations/info", method = RequestMethod.POST)
294 372 @ResponseBody
295   - public List<EntityRelationInfo> findInfoByQuery(@RequestBody EntityRelationsQuery query) throws ThingsboardException {
  373 + public List<EntityRelationInfo> findInfoByQuery(@ApiParam(value = "A JSON value representing the entity relations query object.")
  374 + @RequestBody EntityRelationsQuery query) throws ThingsboardException {
296 375 checkNotNull(query);
297 376 checkNotNull(query.getParameters());
298 377 checkNotNull(query.getFilters());
... ...
... ... @@ -18,6 +18,8 @@ package org.thingsboard.server.common.data.id;
18 18 import com.fasterxml.jackson.annotation.JsonIgnore;
19 19 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20 20 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  21 +import io.swagger.annotations.ApiModel;
  22 +import io.swagger.annotations.ApiModelProperty;
21 23 import org.thingsboard.server.common.data.EntityType;
22 24
23 25 import java.io.Serializable;
... ... @@ -29,12 +31,15 @@ import java.util.UUID;
29 31
30 32 @JsonDeserialize(using = EntityIdDeserializer.class)
31 33 @JsonSerialize(using = EntityIdSerializer.class)
  34 +@ApiModel
32 35 public interface EntityId extends HasUUID, Serializable { //NOSONAR, the constant is closely related to EntityId
33 36
34 37 UUID NULL_UUID = UUID.fromString("13814000-1dd2-11b2-8080-808080808080");
35 38
  39 + @ApiModelProperty(position = 1, required = true, value = "string", example = "784f394c-42b6-435a-983c-b7beff2784f9")
36 40 UUID getId();
37 41
  42 + @ApiModelProperty(position = 2, required = true, value = "string", example = "DEVICE")
38 43 EntityType getEntityType();
39 44
40 45 @JsonIgnore
... ...
... ... @@ -16,18 +16,17 @@
16 16 package org.thingsboard.server.common.data.relation;
17 17
18 18 import com.fasterxml.jackson.annotation.JsonIgnore;
19   -import com.fasterxml.jackson.core.JsonProcessingException;
20 19 import com.fasterxml.jackson.databind.JsonNode;
21   -import com.fasterxml.jackson.databind.ObjectMapper;
  20 +import io.swagger.annotations.ApiModel;
  21 +import io.swagger.annotations.ApiModelProperty;
22 22 import lombok.extern.slf4j.Slf4j;
23 23 import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo;
24 24 import org.thingsboard.server.common.data.id.EntityId;
25 25
26   -import java.io.ByteArrayInputStream;
27   -import java.io.IOException;
28 26 import java.io.Serializable;
29 27
30 28 @Slf4j
  29 +@ApiModel
31 30 public class EntityRelation implements Serializable {
32 31
33 32 private static final long serialVersionUID = 2807343040519543363L;
... ... @@ -72,6 +71,7 @@ public class EntityRelation implements Serializable {
72 71 this.additionalInfo = entityRelation.getAdditionalInfo();
73 72 }
74 73
  74 + @ApiModelProperty(position = 1, value = "JSON object with [from] Entity Id.", readOnly = true)
75 75 public EntityId getFrom() {
76 76 return from;
77 77 }
... ... @@ -80,6 +80,7 @@ public class EntityRelation implements Serializable {
80 80 this.from = from;
81 81 }
82 82
  83 + @ApiModelProperty(position = 2, value = "JSON object with [to] Entity Id.", readOnly = true)
83 84 public EntityId getTo() {
84 85 return to;
85 86 }
... ... @@ -88,6 +89,7 @@ public class EntityRelation implements Serializable {
88 89 this.to = to;
89 90 }
90 91
  92 + @ApiModelProperty(position = 3, value = "String value of relation type.", example = "Contains")
91 93 public String getType() {
92 94 return type;
93 95 }
... ... @@ -96,6 +98,7 @@ public class EntityRelation implements Serializable {
96 98 this.type = type;
97 99 }
98 100
  101 + @ApiModelProperty(position = 4, value = "Represents the type group of the relation.", example = "COMMON")
99 102 public RelationTypeGroup getTypeGroup() {
100 103 return typeGroup;
101 104 }
... ... @@ -104,6 +107,7 @@ public class EntityRelation implements Serializable {
104 107 this.typeGroup = typeGroup;
105 108 }
106 109
  110 + @ApiModelProperty(position = 5, value = "Additional parameters of the relation", dataType = "com.fasterxml.jackson.databind.JsonNode")
107 111 public JsonNode getAdditionalInfo() {
108 112 return SearchTextBasedWithAdditionalInfo.getJson(() -> additionalInfo, () -> additionalInfoBytes);
109 113 }
... ...
... ... @@ -15,6 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.common.data.relation;
17 17
  18 +import io.swagger.annotations.ApiModelProperty;
  19 +
18 20 public class EntityRelationInfo extends EntityRelation {
19 21
20 22 private static final long serialVersionUID = 2807343097519543363L;
... ... @@ -30,6 +32,7 @@ public class EntityRelationInfo extends EntityRelation {
30 32 super(entityRelation);
31 33 }
32 34
  35 + @ApiModelProperty(position = 6, value = "Name of the entity for [from] direction.", readOnly = true, example = "A4B72CCDFF33")
33 36 public String getFromName() {
34 37 return fromName;
35 38 }
... ... @@ -38,6 +41,7 @@ public class EntityRelationInfo extends EntityRelation {
38 41 this.fromName = fromName;
39 42 }
40 43
  44 + @ApiModelProperty(position = 7, value = "Name of the entity for [to] direction.", readOnly = true, example = "A4B72CCDFF35")
41 45 public String getToName() {
42 46 return toName;
43 47 }
... ...
... ... @@ -15,6 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.common.data.relation;
17 17
  18 +import io.swagger.annotations.ApiModel;
  19 +import io.swagger.annotations.ApiModelProperty;
18 20 import lombok.Data;
19 21
20 22 import java.util.List;
... ... @@ -23,9 +25,12 @@ import java.util.List;
23 25 * Created by ashvayka on 02.05.17.
24 26 */
25 27 @Data
  28 +@ApiModel
26 29 public class EntityRelationsQuery {
27 30
  31 + @ApiModelProperty(position = 2, value = "Main search parameters.")
28 32 private RelationsSearchParameters parameters;
  33 + @ApiModelProperty(position = 1, value = "Main filters.")
29 34 private List<RelationEntityTypeFilter> filters;
30 35
31 36 }
... ...
... ... @@ -15,6 +15,8 @@
15 15 */
16 16 package org.thingsboard.server.common.data.relation;
17 17
  18 +import io.swagger.annotations.ApiModel;
  19 +import io.swagger.annotations.ApiModelProperty;
18 20 import lombok.AllArgsConstructor;
19 21 import lombok.Data;
20 22 import org.thingsboard.server.common.data.EntityType;
... ... @@ -26,9 +28,12 @@ import java.util.List;
26 28 */
27 29 @Data
28 30 @AllArgsConstructor
  31 +@ApiModel
29 32 public class RelationEntityTypeFilter {
30 33
  34 + @ApiModelProperty(position = 1, value = "Type of the relation between root entity and other entity (e.g. 'Contains' or 'Manages').", example = "Contains")
31 35 private String relationType;
32 36
  37 + @ApiModelProperty(position = 2, value = "Array of entity types to filter the related entities (e.g. 'DEVICE', 'ASSET').")
33 38 private List<EntityType> entityTypes;
34 39 }
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.common.data.relation;
17 17
  18 +import com.fasterxml.jackson.annotation.JsonIgnore;
18 19 import io.swagger.annotations.ApiModel;
19 20 import io.swagger.annotations.ApiModelProperty;
20 21 import lombok.AllArgsConstructor;
... ... @@ -33,7 +34,7 @@ import java.util.UUID;
33 34 @AllArgsConstructor
34 35 public class RelationsSearchParameters {
35 36
36   - @ApiModelProperty(position = 1, value = "Root entity id to start search from.")
  37 + @ApiModelProperty(position = 1, value = "Root entity id to start search from.", example = "784f394c-42b6-435a-983c-b7beff2784f9")
37 38 private UUID rootId;
38 39 @ApiModelProperty(position = 2, value = "Type of the root entity.")
39 40 private EntityType rootType;
... ... @@ -59,6 +60,7 @@ public class RelationsSearchParameters {
59 60 this.fetchLastLevelOnly = fetchLastLevelOnly;
60 61 }
61 62
  63 + @JsonIgnore
62 64 public EntityId getEntityId() {
63 65 return EntityIdFactory.getByTypeAndUuid(rootType, rootId);
64 66 }
... ...