Commit d1974e9b04b9cfeb46a7b0d3c975fead32094a51

Authored by Dima Landiak
1 parent 8cb0622d

swagger description for event controller

... ... @@ -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";
... ... @@ -179,11 +181,13 @@ public abstract class BaseController {
179 181 protected final String DASHBOARD_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the dashboard title.";
180 182 protected final String DEVICE_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the device name.";
181 183 protected final String CUSTOMER_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the customer title.";
  184 + protected final String EVENT_TEXT_SEARCH_DESCRIPTION = "The value is not used in searching.";
182 185 protected final String SORT_PROPERTY_DESCRIPTION = "Property of entity to sort by";
183 186 protected final String DASHBOARD_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, title";
184 187 protected final String CUSTOMER_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, title, email, country, city";
185 188 protected final String DEVICE_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, deviceProfileName, label, customerTitle";
186 189 protected final String ASSET_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, type, label, customerTitle";
  190 + protected final String EVENT_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, id";
187 191 protected final String SORT_ORDER_DESCRIPTION = "Sort order. ASC (ASCENDING) or DESC (DESCENDING)";
188 192 protected final String SORT_ORDER_ALLOWABLE_VALUES = "ASC, DESC";
189 193 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. ";
... ... @@ -193,6 +197,9 @@ public abstract class BaseController {
193 197 protected final String DEVICE_NAME_DESCRIPTION = "A string value representing the Device name.";
194 198 protected final String ASSET_NAME_DESCRIPTION = "A string value representing the Asset name.";
195 199
  200 + protected final String EVENT_START_TIME_DESCRIPTION = "Timestamp. Events with creation time before it won't be queried.";
  201 + protected final String EVENT_END_TIME_DESCRIPTION = "Timestamp. Events with creation time after it won't be queried.";
  202 +
196 203 public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
197 204 protected static final String DEFAULT_DASHBOARD = "defaultDashboardId";
198 205 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.beans.factory.annotation.Autowired;
  21 +import org.springframework.http.MediaType;
19 22 import org.springframework.security.access.prepost.PreAuthorize;
20 23 import org.springframework.web.bind.annotation.PathVariable;
21 24 import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -45,20 +48,34 @@ public class EventController extends BaseController {
45 48 @Autowired
46 49 private EventService eventService;
47 50
  51 + @ApiOperation(value = "Get Events (getEvents)",
  52 + notes = "Returns a page of events for specified entity by specifying event type." +
  53 + PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
48 54 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
49 55 @RequestMapping(value = "/events/{entityType}/{entityId}/{eventType}", method = RequestMethod.GET)
50 56 @ResponseBody
51 57 public PageData<Event> getEvents(
  58 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
52 59 @PathVariable("entityType") String strEntityType,
  60 + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
53 61 @PathVariable("entityId") String strEntityId,
  62 + @ApiParam(value = "A string value representing event type", example = "STATS", required = true)
54 63 @PathVariable("eventType") String eventType,
  64 + @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true)
55 65 @RequestParam("tenantId") String strTenantId,
  66 + @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
56 67 @RequestParam int pageSize,
  68 + @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
57 69 @RequestParam int page,
  70 + @ApiParam(value = EVENT_TEXT_SEARCH_DESCRIPTION)
58 71 @RequestParam(required = false) String textSearch,
  72 + @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = EVENT_SORT_PROPERTY_ALLOWABLE_VALUES)
59 73 @RequestParam(required = false) String sortProperty,
  74 + @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
60 75 @RequestParam(required = false) String sortOrder,
  76 + @ApiParam(value = EVENT_START_TIME_DESCRIPTION)
61 77 @RequestParam(required = false) Long startTime,
  78 + @ApiParam(value = EVENT_END_TIME_DESCRIPTION)
62 79 @RequestParam(required = false) Long endTime) throws ThingsboardException {
63 80 checkParameter("EntityId", strEntityId);
64 81 checkParameter("EntityType", strEntityType);
... ... @@ -74,19 +91,32 @@ public class EventController extends BaseController {
74 91 }
75 92 }
76 93
  94 + @ApiOperation(value = "Get Events (getEvents)",
  95 + notes = "Returns a page of events for specified entity." +
  96 + PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
77 97 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
78 98 @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.GET)
79 99 @ResponseBody
80 100 public PageData<Event> getEvents(
  101 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
81 102 @PathVariable("entityType") String strEntityType,
  103 + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
82 104 @PathVariable("entityId") String strEntityId,
  105 + @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true)
83 106 @RequestParam("tenantId") String strTenantId,
  107 + @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
84 108 @RequestParam int pageSize,
  109 + @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
85 110 @RequestParam int page,
  111 + @ApiParam(value = EVENT_TEXT_SEARCH_DESCRIPTION)
86 112 @RequestParam(required = false) String textSearch,
  113 + @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = EVENT_SORT_PROPERTY_ALLOWABLE_VALUES)
87 114 @RequestParam(required = false) String sortProperty,
  115 + @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
88 116 @RequestParam(required = false) String sortOrder,
  117 + @ApiParam(value = EVENT_START_TIME_DESCRIPTION)
89 118 @RequestParam(required = false) Long startTime,
  119 + @ApiParam(value = EVENT_END_TIME_DESCRIPTION)
90 120 @RequestParam(required = false) Long endTime) throws ThingsboardException {
91 121 checkParameter("EntityId", strEntityId);
92 122 checkParameter("EntityType", strEntityType);
... ... @@ -104,20 +134,34 @@ public class EventController extends BaseController {
104 134 }
105 135 }
106 136
  137 + @ApiOperation(value = "Get Events (getEvents)",
  138 + notes = "Returns a page of events for specified entity by specifying event filter." +
  139 + PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
107 140 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
108 141 @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.POST)
109 142 @ResponseBody
110 143 public PageData<Event> getEvents(
  144 + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true)
111 145 @PathVariable("entityType") String strEntityType,
  146 + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
112 147 @PathVariable("entityId") String strEntityId,
  148 + @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true)
113 149 @RequestParam("tenantId") String strTenantId,
  150 + @ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
114 151 @RequestParam int pageSize,
  152 + @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
115 153 @RequestParam int page,
  154 + @ApiParam(value = "A JSON value representing the event filter.", required = true)
116 155 @RequestBody EventFilter eventFilter,
  156 + @ApiParam(value = EVENT_TEXT_SEARCH_DESCRIPTION)
117 157 @RequestParam(required = false) String textSearch,
  158 + @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = EVENT_SORT_PROPERTY_ALLOWABLE_VALUES)
118 159 @RequestParam(required = false) String sortProperty,
  160 + @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
119 161 @RequestParam(required = false) String sortOrder,
  162 + @ApiParam(value = EVENT_START_TIME_DESCRIPTION)
120 163 @RequestParam(required = false) Long startTime,
  164 + @ApiParam(value = EVENT_END_TIME_DESCRIPTION)
121 165 @RequestParam(required = false) Long endTime) throws ThingsboardException {
122 166 checkParameter("EntityId", strEntityId);
123 167 checkParameter("EntityType", strEntityType);
... ... @@ -127,7 +171,7 @@ public class EventController extends BaseController {
127 171 EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
128 172 checkEntityId(entityId, Operation.READ);
129 173
130   - if(sortProperty != null && sortProperty.equals("createdTime") && eventFilter.hasFilterForJsonBody()) {
  174 + if (sortProperty != null && sortProperty.equals("createdTime") && eventFilter.hasFilterForJsonBody()) {
131 175 sortProperty = ModelConstants.CREATED_TIME_PROPERTY;
132 176 }
133 177
... ...
... ... @@ -16,6 +16,8 @@
16 16 package org.thingsboard.server.common.data;
17 17
18 18 import com.fasterxml.jackson.databind.JsonNode;
  19 +import io.swagger.annotations.ApiModel;
  20 +import io.swagger.annotations.ApiModelProperty;
19 21 import lombok.Data;
20 22 import org.thingsboard.server.common.data.id.EntityId;
21 23 import org.thingsboard.server.common.data.id.EventId;
... ... @@ -25,12 +27,18 @@ import org.thingsboard.server.common.data.id.TenantId;
25 27 * @author Andrew Shvayka
26 28 */
27 29 @Data
  30 +@ApiModel
28 31 public class Event extends BaseData<EventId> {
29 32
  33 + @ApiModelProperty(position = 1, value = "JSON object with Tenant Id.", readOnly = true)
30 34 private TenantId tenantId;
  35 + @ApiModelProperty(position = 2, value = "Event type", example = "STATS")
31 36 private String type;
  37 + @ApiModelProperty(position = 3, value = "string", example = "784f394c-42b6-435a-983c-b7beff2784f9")
32 38 private String uid;
  39 + @ApiModelProperty(position = 4, value = "JSON object with Entity Id for which event is created.", readOnly = true)
33 40 private EntityId entityId;
  41 + @ApiModelProperty(position = 5, value = "Event body.", dataType = "com.fasterxml.jackson.databind.JsonNode")
34 42 private transient JsonNode body;
35 43
36 44 public Event() {
... ... @@ -45,4 +53,9 @@ public class Event extends BaseData<EventId> {
45 53 super(event);
46 54 }
47 55
  56 + @ApiModelProperty(position = 6, value = "Timestamp of the event creation, in milliseconds", example = "1609459200000", readOnly = true)
  57 + @Override
  58 + public long getCreatedTime() {
  59 + return super.getCreatedTime();
  60 + }
48 61 }
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
18 19 import lombok.Data;
19 20 import org.thingsboard.server.common.data.StringUtils;
20 21
21 22 @Data
  23 +@ApiModel
22 24 public abstract class DebugEvent implements EventFilter {
23 25
24 26 private String msgDirectionType;
... ...
... ... @@ -15,6 +15,9 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
  19 +
  20 +@ApiModel
18 21 public class DebugRuleChainEventFilter extends DebugEvent {
19 22 @Override
20 23 public EventType getEventType() {
... ...
... ... @@ -15,6 +15,9 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
  19 +
  20 +@ApiModel
18 21 public class DebugRuleNodeEventFilter extends DebugEvent {
19 22 @Override
20 23 public EventType getEventType() {
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
18 19 import lombok.Data;
19 20 import org.thingsboard.server.common.data.StringUtils;
20 21
21 22 @Data
  23 +@ApiModel
22 24 public class ErrorEventFilter implements EventFilter {
23 25 private String server;
24 26 private String method;
... ...
... ... @@ -16,10 +16,11 @@
16 16 package org.thingsboard.server.common.data.event;
17 17
18 18 import com.fasterxml.jackson.annotation.JsonIgnore;
19   -import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20 19 import com.fasterxml.jackson.annotation.JsonSubTypes;
21 20 import com.fasterxml.jackson.annotation.JsonTypeInfo;
  21 +import io.swagger.annotations.ApiModel;
22 22
  23 +@ApiModel
23 24 @JsonTypeInfo(
24 25 use = JsonTypeInfo.Id.NAME,
25 26 include = JsonTypeInfo.As.PROPERTY,
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
18 19 import lombok.Data;
19 20 import org.thingsboard.server.common.data.StringUtils;
20 21
21 22 @Data
  23 +@ApiModel
22 24 public class LifeCycleEventFilter implements EventFilter {
23 25 private String server;
24 26 private String event;
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.common.data.event;
17 17
  18 +import io.swagger.annotations.ApiModel;
18 19 import lombok.Data;
19 20 import org.thingsboard.server.common.data.StringUtils;
20 21
21 22 @Data
  23 +@ApiModel
22 24 public class StatisticsEventFilter implements EventFilter {
23 25 private String server;
24 26 private Integer messagesProcessed;
... ...