Showing
11 changed files
with
96 additions
and
18 deletions
... | ... | @@ -218,9 +218,9 @@ public class AlarmController extends BaseController { |
218 | 218 | @ResponseBody |
219 | 219 | public PageData<AlarmInfo> getAlarms( |
220 | 220 | @ApiParam(value = ENTITY_TYPE_DESCRIPTION) |
221 | - @PathVariable("entityType") String strEntityType, | |
222 | - @ApiParam(value = ENTITY_ID_DESCRIPTION) | |
223 | - @PathVariable("entityId") String strEntityId, | |
221 | + @PathVariable(ENTITY_TYPE) String strEntityType, | |
222 | + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION) | |
223 | + @PathVariable(ENTITY_ID) String strEntityId, | |
224 | 224 | @ApiParam(value = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES) |
225 | 225 | @RequestParam(required = false) String searchStatus, |
226 | 226 | @ApiParam(value = ALARM_QUERY_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_STATUS_ALLOWABLE_VALUES) |
... | ... | @@ -319,9 +319,9 @@ public class AlarmController extends BaseController { |
319 | 319 | @ResponseBody |
320 | 320 | public AlarmSeverity getHighestAlarmSeverity( |
321 | 321 | @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) |
322 | - @PathVariable("entityType") String strEntityType, | |
323 | - @ApiParam(value = ENTITY_ID_DESCRIPTION, required = true) | |
324 | - @PathVariable("entityId") String strEntityId, | |
322 | + @PathVariable(ENTITY_TYPE) String strEntityType, | |
323 | + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) | |
324 | + @PathVariable(ENTITY_ID) String strEntityId, | |
325 | 325 | @ApiParam(value = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES) |
326 | 326 | @RequestParam(required = false) String searchStatus, |
327 | 327 | @ApiParam(value = ALARM_QUERY_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_STATUS_ALLOWABLE_VALUES) | ... | ... |
... | ... | @@ -157,6 +157,8 @@ public abstract class BaseController { |
157 | 157 | |
158 | 158 | public static final String CUSTOMER_ID = "customerId"; |
159 | 159 | public static final String TENANT_ID = "tenantId"; |
160 | + public static final String ENTITY_ID = "entityId"; | |
161 | + public static final String ENTITY_TYPE = "entityType"; | |
160 | 162 | |
161 | 163 | public static final String PAGE_DATA_PARAMETERS = "You can specify parameters to filter the results. " + |
162 | 164 | "The result is wrapped with PageData object that allows you to iterate over result set using pagination. " + |
... | ... | @@ -169,6 +171,8 @@ public abstract class BaseController { |
169 | 171 | public static final String CUSTOMER_ID_PARAM_DESCRIPTION = "A string value representing the customer id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'"; |
170 | 172 | public static final String ASSET_ID_PARAM_DESCRIPTION = "A string value representing the asset id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'"; |
171 | 173 | public static final String ALARM_ID_PARAM_DESCRIPTION = "A string value representing the alarm id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'"; |
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'"; | |
172 | 176 | |
173 | 177 | protected final String PAGE_SIZE_DESCRIPTION = "Maximum amount of entities in a one page"; |
174 | 178 | protected final String PAGE_NUMBER_DESCRIPTION = "Sequence number of page starting from 0"; |
... | ... | @@ -179,12 +183,14 @@ public abstract class BaseController { |
179 | 183 | protected final String DASHBOARD_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the dashboard title."; |
180 | 184 | protected final String DEVICE_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the device name."; |
181 | 185 | protected final String CUSTOMER_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on the customer title."; |
186 | + protected final String EVENT_TEXT_SEARCH_DESCRIPTION = "The value is not used in searching."; | |
182 | 187 | protected final String SORT_PROPERTY_DESCRIPTION = "Property of entity to sort by"; |
183 | 188 | protected final String DASHBOARD_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, title"; |
184 | 189 | protected final String CUSTOMER_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, title, email, country, city"; |
185 | 190 | protected final String DEVICE_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, deviceProfileName, label, customerTitle"; |
186 | 191 | protected final String ASSET_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, name, type, label, customerTitle"; |
187 | 192 | protected final String ALARM_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, startTs, endTs, type, ackTs, clearTs, severity, status"; |
193 | + protected final String EVENT_SORT_PROPERTY_ALLOWABLE_VALUES = "createdTime, id"; | |
188 | 194 | protected final String SORT_ORDER_DESCRIPTION = "Sort order. ASC (ASCENDING) or DESC (DESCENDING)"; |
189 | 195 | protected final String SORT_ORDER_ALLOWABLE_VALUES = "ASC, DESC"; |
190 | 196 | 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. "; |
... | ... | @@ -195,8 +201,8 @@ public abstract class BaseController { |
195 | 201 | protected final String DEVICE_NAME_DESCRIPTION = "A string value representing the Device name."; |
196 | 202 | protected final String ASSET_NAME_DESCRIPTION = "A string value representing the Asset name."; |
197 | 203 | |
198 | - protected static final String ENTITY_TYPE_DESCRIPTION = "A string value representing the entity type. For example, 'DEVICE'"; | |
199 | - protected static final String ENTITY_ID_DESCRIPTION = "A string value representing the entity id. For example, '784f394c-42b6-435a-983c-b7beff2784f9'"; | |
204 | + protected final String EVENT_START_TIME_DESCRIPTION = "Timestamp. Events with creation time before it won't be queried."; | |
205 | + protected final String EVENT_END_TIME_DESCRIPTION = "Timestamp. Events with creation time after it won't be queried."; | |
200 | 206 | |
201 | 207 | public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
202 | 208 | protected static final String DEFAULT_DASHBOARD = "defaultDashboardId"; | ... | ... |
... | ... | @@ -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( |
52 | - @PathVariable("entityType") String strEntityType, | |
53 | - @PathVariable("entityId") String strEntityId, | |
58 | + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) | |
59 | + @PathVariable(ENTITY_TYPE) String strEntityType, | |
60 | + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) | |
61 | + @PathVariable(ENTITY_ID) String strEntityId, | |
62 | + @ApiParam(value = "A string value representing event type", example = "STATS", required = true) | |
54 | 63 | @PathVariable("eventType") String eventType, |
55 | - @RequestParam("tenantId") String strTenantId, | |
64 | + @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true) | |
65 | + @RequestParam(TENANT_ID) 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( |
81 | - @PathVariable("entityType") String strEntityType, | |
82 | - @PathVariable("entityId") String strEntityId, | |
101 | + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) | |
102 | + @PathVariable(ENTITY_TYPE) String strEntityType, | |
103 | + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) | |
104 | + @PathVariable(ENTITY_ID) 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( |
111 | - @PathVariable("entityType") String strEntityType, | |
112 | - @PathVariable("entityId") String strEntityId, | |
113 | - @RequestParam("tenantId") String strTenantId, | |
144 | + @ApiParam(value = ENTITY_TYPE_DESCRIPTION, required = true) | |
145 | + @PathVariable(ENTITY_TYPE) String strEntityType, | |
146 | + @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true) | |
147 | + @PathVariable(ENTITY_ID) String strEntityId, | |
148 | + @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true) | |
149 | + @RequestParam(TENANT_ID) 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,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; | ... | ... |