Showing
10 changed files
with
95 additions
and
52 deletions
... | ... | @@ -203,6 +203,14 @@ public abstract class BaseController { |
203 | 203 | |
204 | 204 | protected final String EVENT_START_TIME_DESCRIPTION = "Timestamp. Events with creation time before it won't be queried."; |
205 | 205 | protected final String EVENT_END_TIME_DESCRIPTION = "Timestamp. Events with creation time after it won't be queried."; |
206 | + | |
207 | + protected final String EVENT_ERROR_FILTER_OBJ = "{ \"eventType\": \"ERROR\", \"server\": \"ip-172-31-24-152\", \"method\": \"onClusterEventMsg\", \"error\": \"Error Message\" }"; | |
208 | + protected final String EVENT_LC_EVENT_FILTER_OBJ = "{ \"eventType\": \"LC_EVENT\", \"server\": \"ip-172-31-24-152\", \"event\": \"STARTED\", \"status\": \"Success\", \"error\": \"Error Message\" }"; | |
209 | + protected final String EVENT_STATS_FILTER_OBJ = "{ \"eventType\": \"STATS\", \"server\": \"ip-172-31-24-152\", \"messagesProcessed\": 10, \"errorsOccurred\": 5 }"; | |
210 | + protected final String DEBUG_FILTER_OBJ = "\"msgDirectionType\": \"IN\", \"server\": \"ip-172-31-24-152\", \"dataSearch\": \"humidity\", \"metadataSearch\": \"deviceName\", \"entityName\": \"DEVICE\", \"relationType\": \"Success\", \"entityId\": \"de9d54a0-2b7a-11ec-a3cc-23386423d98f\", \"msgType\": \"POST_TELEMETRY_REQUEST\", \"isError\": \"false\", \"error\": \"Error Message\" }"; | |
211 | + protected final String EVENT_DEBUG_RULE_NODE_FILTER_OBJ = "{ \"eventType\": \"DEBUG_RULE_NODE\"," + DEBUG_FILTER_OBJ; | |
212 | + protected final String EVENT_DEBUG_RULE_CHAIN_FILTER_OBJ = "{ \"eventType\": \"DEBUG_RULE_CHAIN\"," + DEBUG_FILTER_OBJ; | |
213 | + | |
206 | 214 | 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."; |
207 | 215 | protected static final String RELATION_TYPE_GROUP_PARAM_DESCRIPTION = "A string value representing relation type group. For example, 'COMMON'"; |
208 | 216 | ... | ... |
... | ... | @@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
28 | 28 | import org.springframework.web.bind.annotation.ResponseBody; |
29 | 29 | import org.springframework.web.bind.annotation.RestController; |
30 | 30 | import org.thingsboard.server.common.data.Event; |
31 | -import org.thingsboard.server.common.data.event.EventFilter; | |
31 | +import org.thingsboard.server.common.data.event.BaseEventFilter; | |
32 | 32 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
33 | 33 | import org.thingsboard.server.common.data.id.EntityId; |
34 | 34 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
... | ... | @@ -45,6 +45,8 @@ import org.thingsboard.server.service.security.permission.Operation; |
45 | 45 | @RequestMapping("/api") |
46 | 46 | public class EventController extends BaseController { |
47 | 47 | |
48 | + private static final String NEW_LINE = "\n\n"; | |
49 | + | |
48 | 50 | @Autowired |
49 | 51 | private EventService eventService; |
50 | 52 | |
... | ... | @@ -135,8 +137,16 @@ public class EventController extends BaseController { |
135 | 137 | } |
136 | 138 | |
137 | 139 | @ApiOperation(value = "Get Events by event filter (getEvents)", |
138 | - notes = "Returns a page of events for specified entity by specifying event filter. " + | |
139 | - PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE) | |
140 | + notes = "Returns a page of events for the chosen entity by specifying the event filter. " + | |
141 | + PAGE_DATA_PARAMETERS + NEW_LINE + "5 different eventFilter objects could be set for different event types. " + | |
142 | + "The eventType field is required. Others are optional. If some of them are set, the filtering will be applied according to them. " + | |
143 | + "See the examples below for all the fields used for each event type filtering. " + NEW_LINE + | |
144 | + EVENT_ERROR_FILTER_OBJ + NEW_LINE + | |
145 | + EVENT_LC_EVENT_FILTER_OBJ + NEW_LINE + | |
146 | + EVENT_STATS_FILTER_OBJ + NEW_LINE + | |
147 | + EVENT_DEBUG_RULE_NODE_FILTER_OBJ + NEW_LINE + | |
148 | + EVENT_DEBUG_RULE_CHAIN_FILTER_OBJ + NEW_LINE, | |
149 | + produces = MediaType.APPLICATION_JSON_VALUE) | |
140 | 150 | @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
141 | 151 | @RequestMapping(value = "/events/{entityType}/{entityId}", method = RequestMethod.POST) |
142 | 152 | @ResponseBody |
... | ... | @@ -152,7 +162,7 @@ public class EventController extends BaseController { |
152 | 162 | @ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true) |
153 | 163 | @RequestParam int page, |
154 | 164 | @ApiParam(value = "A JSON value representing the event filter.", required = true) |
155 | - @RequestBody EventFilter eventFilter, | |
165 | + @RequestBody BaseEventFilter eventFilter, | |
156 | 166 | @ApiParam(value = EVENT_TEXT_SEARCH_DESCRIPTION) |
157 | 167 | @RequestParam(required = false) String textSearch, |
158 | 168 | @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = EVENT_SORT_PROPERTY_ALLOWABLE_VALUES) | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.common.data.event; | |
17 | + | |
18 | +import io.swagger.annotations.ApiModel; | |
19 | +import io.swagger.annotations.ApiModelProperty; | |
20 | +import lombok.Data; | |
21 | + | |
22 | +@ApiModel | |
23 | +@Data | |
24 | +public abstract class BaseEventFilter implements EventFilter { | |
25 | + | |
26 | + @ApiModelProperty(position = 1, value = "String value representing msg direction type (incoming to entity or outcoming from entity)", allowableValues = "IN, OUT") | |
27 | + protected String msgDirectionType; | |
28 | + @ApiModelProperty(position = 2, value = "String value representing the server name, identifier or ip address where the platform is running", example = "ip-172-31-24-152") | |
29 | + protected String server; | |
30 | + @ApiModelProperty(position = 3, value = "The case insensitive 'contains' filter based on data (key and value) for the message.", example = "humidity") | |
31 | + protected String dataSearch; | |
32 | + @ApiModelProperty(position = 4, value = "The case insensitive 'contains' filter based on metadata (key and value) for the message.", example = "deviceName") | |
33 | + protected String metadataSearch; | |
34 | + @ApiModelProperty(position = 5, value = "String value representing the entity type", allowableValues = "DEVICE") | |
35 | + protected String entityName; | |
36 | + @ApiModelProperty(position = 6, value = "String value representing the type of message routing", example = "Success") | |
37 | + protected String relationType; | |
38 | + @ApiModelProperty(position = 7, value = "String value representing the entity id in the event body (originator of the message)", example = "de9d54a0-2b7a-11ec-a3cc-23386423d98f") | |
39 | + protected String entityId; | |
40 | + @ApiModelProperty(position = 8, value = "String value representing the message type", example = "POST_TELEMETRY_REQUEST") | |
41 | + protected String msgType; | |
42 | + @ApiModelProperty(position = 9, value = "Boolean value to filter the errors", allowableValues = "false, true") | |
43 | + protected boolean isError; | |
44 | + @ApiModelProperty(position = 10, value = "The case insensitive 'contains' filter based on error message", example = "not present in the DB") | |
45 | + protected String errorStr; | |
46 | + @ApiModelProperty(position = 11, value = "String value representing the method name when the error happened", example = "onClusterEventMsg") | |
47 | + protected String method; | |
48 | + @ApiModelProperty(position = 12, value = "The minimum number of successfully processed messages", example = "25") | |
49 | + protected Integer messagesProcessed; | |
50 | + @ApiModelProperty(position = 13, value = "The minimum number of errors occurred during messages processing", example = "30") | |
51 | + protected Integer errorsOccurred; | |
52 | + @ApiModelProperty(position = 14, value = "String value representing the lifecycle event type", example = "STARTED") | |
53 | + protected String event; | |
54 | + @ApiModelProperty(position = 15, value = "String value representing status of the lifecycle event", allowableValues = "Success, Failure") | |
55 | + protected String status; | |
56 | + | |
57 | +} | ... | ... |
... | ... | @@ -16,23 +16,10 @@ |
16 | 16 | package org.thingsboard.server.common.data.event; |
17 | 17 | |
18 | 18 | import io.swagger.annotations.ApiModel; |
19 | -import lombok.Data; | |
20 | 19 | import org.thingsboard.server.common.data.StringUtils; |
21 | 20 | |
22 | -@Data | |
23 | 21 | @ApiModel |
24 | -public abstract class DebugEvent implements EventFilter { | |
25 | - | |
26 | - private String msgDirectionType; | |
27 | - private String server; | |
28 | - private String dataSearch; | |
29 | - private String metadataSearch; | |
30 | - private String entityName; | |
31 | - private String relationType; | |
32 | - private String entityId; | |
33 | - private String msgType; | |
34 | - private boolean isError; | |
35 | - private String error; | |
22 | +public abstract class DebugEvent extends BaseEventFilter implements EventFilter { | |
36 | 23 | |
37 | 24 | public void setIsError(boolean isError) { |
38 | 25 | this.isError = isError; |
... | ... | @@ -41,7 +28,7 @@ public abstract class DebugEvent implements EventFilter { |
41 | 28 | @Override |
42 | 29 | public boolean hasFilterForJsonBody() { |
43 | 30 | return !StringUtils.isEmpty(msgDirectionType) || !StringUtils.isEmpty(server) || !StringUtils.isEmpty(dataSearch) || !StringUtils.isEmpty(metadataSearch) |
44 | - || !StringUtils.isEmpty(entityName) || !StringUtils.isEmpty(relationType) || !StringUtils.isEmpty(entityId) || !StringUtils.isEmpty(msgType) || !StringUtils.isEmpty(error) || isError; | |
31 | + || !StringUtils.isEmpty(entityName) || !StringUtils.isEmpty(relationType) || !StringUtils.isEmpty(entityId) || !StringUtils.isEmpty(msgType) || !StringUtils.isEmpty(errorStr) || isError; | |
45 | 32 | } |
46 | 33 | |
47 | 34 | } | ... | ... |
... | ... | @@ -16,15 +16,10 @@ |
16 | 16 | package org.thingsboard.server.common.data.event; |
17 | 17 | |
18 | 18 | import io.swagger.annotations.ApiModel; |
19 | -import lombok.Data; | |
20 | 19 | import org.thingsboard.server.common.data.StringUtils; |
21 | 20 | |
22 | -@Data | |
23 | 21 | @ApiModel |
24 | -public class ErrorEventFilter implements EventFilter { | |
25 | - private String server; | |
26 | - private String method; | |
27 | - private String error; | |
22 | +public class ErrorEventFilter extends BaseEventFilter implements EventFilter { | |
28 | 23 | |
29 | 24 | @Override |
30 | 25 | public EventType getEventType() { |
... | ... | @@ -33,6 +28,6 @@ public class ErrorEventFilter implements EventFilter { |
33 | 28 | |
34 | 29 | @Override |
35 | 30 | public boolean hasFilterForJsonBody() { |
36 | - return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(method) || !StringUtils.isEmpty(error); | |
31 | + return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(method) || !StringUtils.isEmpty(errorStr); | |
37 | 32 | } |
38 | 33 | } | ... | ... |
... | ... | @@ -15,10 +15,10 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.event; |
17 | 17 | |
18 | -import com.fasterxml.jackson.annotation.JsonIgnore; | |
19 | 18 | import com.fasterxml.jackson.annotation.JsonSubTypes; |
20 | 19 | import com.fasterxml.jackson.annotation.JsonTypeInfo; |
21 | 20 | import io.swagger.annotations.ApiModel; |
21 | +import io.swagger.annotations.ApiModelProperty; | |
22 | 22 | |
23 | 23 | @ApiModel |
24 | 24 | @JsonTypeInfo( |
... | ... | @@ -33,7 +33,8 @@ import io.swagger.annotations.ApiModel; |
33 | 33 | @JsonSubTypes.Type(value = StatisticsEventFilter.class, name = "STATS") |
34 | 34 | }) |
35 | 35 | public interface EventFilter { |
36 | - @JsonIgnore | |
36 | + | |
37 | + @ApiModelProperty(position = 1, required = true, value = "String value representing the event type", example = "STATS") | |
37 | 38 | EventType getEventType(); |
38 | 39 | |
39 | 40 | boolean hasFilterForJsonBody(); | ... | ... |
... | ... | @@ -16,16 +16,10 @@ |
16 | 16 | package org.thingsboard.server.common.data.event; |
17 | 17 | |
18 | 18 | import io.swagger.annotations.ApiModel; |
19 | -import lombok.Data; | |
20 | 19 | import org.thingsboard.server.common.data.StringUtils; |
21 | 20 | |
22 | -@Data | |
23 | 21 | @ApiModel |
24 | -public class LifeCycleEventFilter implements EventFilter { | |
25 | - private String server; | |
26 | - private String event; | |
27 | - private String status; | |
28 | - private String error; | |
22 | +public class LifeCycleEventFilter extends BaseEventFilter implements EventFilter { | |
29 | 23 | |
30 | 24 | @Override |
31 | 25 | public EventType getEventType() { |
... | ... | @@ -34,6 +28,6 @@ public class LifeCycleEventFilter implements EventFilter { |
34 | 28 | |
35 | 29 | @Override |
36 | 30 | public boolean hasFilterForJsonBody() { |
37 | - return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(event) || !StringUtils.isEmpty(status) || !StringUtils.isEmpty(error); | |
31 | + return !StringUtils.isEmpty(server) || !StringUtils.isEmpty(event) || !StringUtils.isEmpty(status) || !StringUtils.isEmpty(errorStr); | |
38 | 32 | } |
39 | 33 | } | ... | ... |
... | ... | @@ -16,15 +16,10 @@ |
16 | 16 | package org.thingsboard.server.common.data.event; |
17 | 17 | |
18 | 18 | import io.swagger.annotations.ApiModel; |
19 | -import lombok.Data; | |
20 | 19 | import org.thingsboard.server.common.data.StringUtils; |
21 | 20 | |
22 | -@Data | |
23 | 21 | @ApiModel |
24 | -public class StatisticsEventFilter implements EventFilter { | |
25 | - private String server; | |
26 | - private Integer messagesProcessed; | |
27 | - private Integer errorsOccurred; | |
22 | +public class StatisticsEventFilter extends BaseEventFilter implements EventFilter { | |
28 | 23 | |
29 | 24 | @Override |
30 | 25 | public EventType getEventType() { | ... | ... |
... | ... | @@ -39,10 +39,6 @@ import org.thingsboard.server.dao.event.EventDao; |
39 | 39 | import org.thingsboard.server.dao.model.sql.EventEntity; |
40 | 40 | import org.thingsboard.server.dao.sql.JpaAbstractDao; |
41 | 41 | |
42 | -import java.sql.Connection; | |
43 | -import java.sql.PreparedStatement; | |
44 | -import java.sql.ResultSet; | |
45 | -import java.sql.SQLException; | |
46 | 42 | import java.util.List; |
47 | 43 | import java.util.Objects; |
48 | 44 | import java.util.Optional; |
... | ... | @@ -196,7 +192,7 @@ public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implemen |
196 | 192 | eventFilter.getEntityId(), |
197 | 193 | eventFilter.getMsgType(), |
198 | 194 | eventFilter.isError(), |
199 | - eventFilter.getError(), | |
195 | + eventFilter.getErrorStr(), | |
200 | 196 | eventFilter.getDataSearch(), |
201 | 197 | eventFilter.getMetadataSearch(), |
202 | 198 | DaoUtil.toPageable(pageLink))); |
... | ... | @@ -212,7 +208,7 @@ public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implemen |
212 | 208 | notNull(pageLink.getEndTime()), |
213 | 209 | eventFilter.getServer(), |
214 | 210 | eventFilter.getMethod(), |
215 | - eventFilter.getError(), | |
211 | + eventFilter.getErrorStr(), | |
216 | 212 | DaoUtil.toPageable(pageLink)) |
217 | 213 | ); |
218 | 214 | } |
... | ... | @@ -231,7 +227,7 @@ public class JpaBaseEventDao extends JpaAbstractDao<EventEntity, Event> implemen |
231 | 227 | eventFilter.getEvent(), |
232 | 228 | statusFilterEnabled, |
233 | 229 | statusFilter, |
234 | - eventFilter.getError(), | |
230 | + eventFilter.getErrorStr(), | |
235 | 231 | DaoUtil.toPageable(pageLink)) |
236 | 232 | ); |
237 | 233 | } | ... | ... |
... | ... | @@ -91,13 +91,13 @@ export interface BaseFilterEventBody { |
91 | 91 | |
92 | 92 | export interface ErrorFilterEventBody extends BaseFilterEventBody { |
93 | 93 | method?: string; |
94 | - error?: string; | |
94 | + errorStr?: string; | |
95 | 95 | } |
96 | 96 | |
97 | 97 | export interface LcFilterEventEventBody extends BaseFilterEventBody { |
98 | 98 | event?: string; |
99 | 99 | status?: string; |
100 | - error?: string; | |
100 | + errorStr?: string; | |
101 | 101 | } |
102 | 102 | |
103 | 103 | export interface StatsFilterEventBody extends BaseFilterEventBody { |
... | ... | @@ -115,7 +115,7 @@ export interface DebugFilterRuleNodeEventBody extends BaseFilterEventBody { |
115 | 115 | dataSearch?: string; |
116 | 116 | metadataSearch?: string; |
117 | 117 | isError?: boolean; |
118 | - error?: string; | |
118 | + errorStr?: string; | |
119 | 119 | } |
120 | 120 | |
121 | 121 | export type FilterEventBody = ErrorFilterEventBody & LcFilterEventEventBody & StatsFilterEventBody & DebugFilterRuleNodeEventBody; | ... | ... |