...
|
...
|
@@ -15,8 +15,11 @@ |
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.apache.commons.lang3.StringUtils;
|
19
|
21
|
import org.springframework.http.HttpStatus;
|
|
22
|
+import org.springframework.http.MediaType;
|
20
|
23
|
import org.springframework.security.access.prepost.PreAuthorize;
|
21
|
24
|
import org.springframework.web.bind.annotation.PathVariable;
|
22
|
25
|
import org.springframework.web.bind.annotation.RequestBody;
|
...
|
...
|
@@ -55,11 +58,25 @@ import java.util.List; |
55
|
58
|
public class AlarmController extends BaseController {
|
56
|
59
|
|
57
|
60
|
public static final String ALARM_ID = "alarmId";
|
|
61
|
+ private static final String ALARM_SECURITY_CHECK = "If the user has the authority of 'Tenant Administrator', the server checks that the alarm is owned by the same tenant. " +
|
|
62
|
+ "If the user has the authority of 'Customer User', the server checks that the alarm belongs to the customer. ";
|
|
63
|
+ private static final String ALARM_QUERY_SEARCH_STATUS_DESCRIPTION = "A string value representing one of the AlarmSearchStatus enumeration value";
|
|
64
|
+ private static final String ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES = "ANY, ACTIVE, CLEARED, ACK, UNACK";
|
|
65
|
+ private static final String ALARM_QUERY_STATUS_DESCRIPTION = "A string value representing one of the AlarmStatus enumeration value";
|
|
66
|
+ private static final String ALARM_QUERY_STATUS_ALLOWABLE_VALUES = "ACTIVE_UNACK, ACTIVE_ACK, CLEARED_UNACK, CLEARED_ACK";
|
|
67
|
+ private static final String ALARM_QUERY_TEXT_SEARCH_DESCRIPTION = "The case insensitive 'startsWith' filter based on of next alarm fields: type, severity or status";
|
|
68
|
+ private static final String ALARM_QUERY_START_TIME_DESCRIPTION = "The start timestamp(milliseconds) of the search time range over the alarm object field: 'createdTime'.";
|
|
69
|
+ private static final String ALARM_QUERY_END_TIME_DESCRIPTION = "The end timestamp(milliseconds) of the search time range over the alarm object field: 'createdTime'.";
|
|
70
|
+ private static final String ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION = "A boolean value to specify if the alarm originator name will be " +
|
|
71
|
+ "filled in the AlarmInfo object field: 'originatorName' or will returns as null.";
|
58
|
72
|
|
59
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
73
|
+ @ApiOperation(value = "Get Alarm (getAlarmById)",
|
|
74
|
+ notes = "Fetch the Alarm object based on the provided Alarm Id. " + ALARM_SECURITY_CHECK, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
75
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
60
|
76
|
@RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.GET)
|
61
|
77
|
@ResponseBody
|
62
|
|
- public Alarm getAlarmById(@PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
|
78
|
+ public Alarm getAlarmById(@ApiParam(value = ALARM_ID_PARAM_DESCRIPTION)
|
|
79
|
+ @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
63
|
80
|
checkParameter(ALARM_ID, strAlarmId);
|
64
|
81
|
try {
|
65
|
82
|
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
...
|
...
|
@@ -69,10 +86,14 @@ public class AlarmController extends BaseController { |
69
|
86
|
}
|
70
|
87
|
}
|
71
|
88
|
|
72
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
89
|
+ @ApiOperation(value = "Get Alarm Info (getAlarmInfoById)",
|
|
90
|
+ notes = "Fetch the Alarm Info object based on the provided Alarm Id. " +
|
|
91
|
+ ALARM_SECURITY_CHECK + ALARM_INFO_DESCRIPTION, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
92
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
73
|
93
|
@RequestMapping(value = "/alarm/info/{alarmId}", method = RequestMethod.GET)
|
74
|
94
|
@ResponseBody
|
75
|
|
- public AlarmInfo getAlarmInfoById(@PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
|
95
|
+ public AlarmInfo getAlarmInfoById(@ApiParam(value = ALARM_ID_PARAM_DESCRIPTION)
|
|
96
|
+ @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
76
|
97
|
checkParameter(ALARM_ID, strAlarmId);
|
77
|
98
|
try {
|
78
|
99
|
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
...
|
...
|
@@ -82,10 +103,14 @@ public class AlarmController extends BaseController { |
82
|
103
|
}
|
83
|
104
|
}
|
84
|
105
|
|
85
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
106
|
+ @ApiOperation(value = "Create or update Alarm (saveAlarm)",
|
|
107
|
+ notes = "Creates or Updates the Alarm. Platform generates random Alarm Id during alarm creation. " +
|
|
108
|
+ "The Alarm Id will be present in the response. Specify the Alarm Id when you would like to update the Alarm. " +
|
|
109
|
+ "Referencing non-existing Alarm Id will cause an error.", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
110
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
86
|
111
|
@RequestMapping(value = "/alarm", method = RequestMethod.POST)
|
87
|
112
|
@ResponseBody
|
88
|
|
- public Alarm saveAlarm(@RequestBody Alarm alarm) throws ThingsboardException {
|
|
113
|
+ public Alarm saveAlarm(@ApiParam(value = "A JSON value representing the alarm.") @RequestBody Alarm alarm) throws ThingsboardException {
|
89
|
114
|
try {
|
90
|
115
|
alarm.setTenantId(getCurrentUser().getTenantId());
|
91
|
116
|
|
...
|
...
|
@@ -106,10 +131,12 @@ public class AlarmController extends BaseController { |
106
|
131
|
}
|
107
|
132
|
}
|
108
|
133
|
|
109
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
134
|
+ @ApiOperation(value = "Delete Alarm (deleteAlarm)",
|
|
135
|
+ notes = "Deletes the Alarm. Referencing non-existing Alarm Id will cause an error.", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
136
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
110
|
137
|
@RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.DELETE)
|
111
|
138
|
@ResponseBody
|
112
|
|
- public Boolean deleteAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
|
139
|
+ public Boolean deleteAlarm(@ApiParam(value = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
113
|
140
|
checkParameter(ALARM_ID, strAlarmId);
|
114
|
141
|
try {
|
115
|
142
|
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
...
|
...
|
@@ -124,15 +151,17 @@ public class AlarmController extends BaseController { |
124
|
151
|
sendAlarmDeleteNotificationMsg(getTenantId(), alarmId, relatedEdgeIds, alarm);
|
125
|
152
|
|
126
|
153
|
return alarmService.deleteAlarm(getTenantId(), alarmId);
|
127
|
|
- } catch (Exception e) {
|
|
154
|
+ } catch (Exception e) {
|
128
|
155
|
throw handleException(e);
|
129
|
156
|
}
|
130
|
157
|
}
|
131
|
158
|
|
132
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
159
|
+ @ApiOperation(value = "Acknowledge Alarm (ackAlarm)",
|
|
160
|
+ notes = "Acknowledge the Alarm. Referencing non-existing Alarm Id will cause an error.", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
161
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
133
|
162
|
@RequestMapping(value = "/alarm/{alarmId}/ack", method = RequestMethod.POST)
|
134
|
163
|
@ResponseStatus(value = HttpStatus.OK)
|
135
|
|
- public void ackAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
|
164
|
+ public void ackAlarm(@ApiParam(value = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
136
|
165
|
checkParameter(ALARM_ID, strAlarmId);
|
137
|
166
|
try {
|
138
|
167
|
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
...
|
...
|
@@ -149,10 +178,12 @@ public class AlarmController extends BaseController { |
149
|
178
|
}
|
150
|
179
|
}
|
151
|
180
|
|
152
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
181
|
+ @ApiOperation(value = "Clear Alarm (clearAlarm)",
|
|
182
|
+ notes = "Clear the Alarm. Referencing non-existing Alarm Id will cause an error.", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
183
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
153
|
184
|
@RequestMapping(value = "/alarm/{alarmId}/clear", method = RequestMethod.POST)
|
154
|
185
|
@ResponseStatus(value = HttpStatus.OK)
|
155
|
|
- public void clearAlarm(@PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
|
186
|
+ public void clearAlarm(@ApiParam(value = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
|
156
|
187
|
checkParameter(ALARM_ID, strAlarmId);
|
157
|
188
|
try {
|
158
|
189
|
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
|
...
|
...
|
@@ -169,21 +200,36 @@ public class AlarmController extends BaseController { |
169
|
200
|
}
|
170
|
201
|
}
|
171
|
202
|
|
|
203
|
+ @ApiOperation(value = "Get Alarms (getAlarms)",
|
|
204
|
+ notes = "Returns a page of alarms for the selected entity. Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
|
|
205
|
+ PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
|
172
|
206
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
173
|
207
|
@RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
|
174
|
208
|
@ResponseBody
|
175
|
209
|
public PageData<AlarmInfo> getAlarms(
|
|
210
|
+ @ApiParam(value = ENTITY_TYPE_DESCRIPTION)
|
176
|
211
|
@PathVariable("entityType") String strEntityType,
|
|
212
|
+ @ApiParam(value = ENTITY_ID_DESCRIPTION)
|
177
|
213
|
@PathVariable("entityId") String strEntityId,
|
|
214
|
+ @ApiParam(value = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES)
|
178
|
215
|
@RequestParam(required = false) String searchStatus,
|
|
216
|
+ @ApiParam(value = ALARM_QUERY_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_STATUS_ALLOWABLE_VALUES)
|
179
|
217
|
@RequestParam(required = false) String status,
|
|
218
|
+ @ApiParam(value = PAGE_SIZE_DESCRIPTION)
|
180
|
219
|
@RequestParam int pageSize,
|
|
220
|
+ @ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
181
|
221
|
@RequestParam int page,
|
|
222
|
+ @ApiParam(value = ALARM_QUERY_TEXT_SEARCH_DESCRIPTION)
|
182
|
223
|
@RequestParam(required = false) String textSearch,
|
|
224
|
+ @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES)
|
183
|
225
|
@RequestParam(required = false) String sortProperty,
|
|
226
|
+ @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
184
|
227
|
@RequestParam(required = false) String sortOrder,
|
|
228
|
+ @ApiParam(value = ALARM_QUERY_START_TIME_DESCRIPTION)
|
185
|
229
|
@RequestParam(required = false) Long startTime,
|
|
230
|
+ @ApiParam(value = ALARM_QUERY_END_TIME_DESCRIPTION)
|
186
|
231
|
@RequestParam(required = false) Long endTime,
|
|
232
|
+ @ApiParam(value = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
|
187
|
233
|
@RequestParam(required = false) Boolean fetchOriginator
|
188
|
234
|
) throws ThingsboardException {
|
189
|
235
|
checkParameter("EntityId", strEntityId);
|
...
|
...
|
@@ -204,20 +250,35 @@ public class AlarmController extends BaseController { |
204
|
250
|
throw handleException(e);
|
205
|
251
|
}
|
206
|
252
|
}
|
207
|
|
-
|
208
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
253
|
+ @ApiOperation(value = "Get All Alarms (getAllAlarms)",
|
|
254
|
+ notes = "Returns a page of alarms that belongs to the current user owner. " +
|
|
255
|
+ "If the user has the authority of 'Tenant Administrator', the server returns alarms that belongs to the tenant of current user. " +
|
|
256
|
+ "If the user has the authority of 'Customer User', the server returns alarms that belongs to the customer of current user. " +
|
|
257
|
+ "Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
|
|
258
|
+ PAGE_DATA_PARAMETERS, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
259
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
209
|
260
|
@RequestMapping(value = "/alarms", method = RequestMethod.GET)
|
210
|
261
|
@ResponseBody
|
211
|
262
|
public PageData<AlarmInfo> getAllAlarms(
|
|
263
|
+ @ApiParam(value = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES)
|
212
|
264
|
@RequestParam(required = false) String searchStatus,
|
|
265
|
+ @ApiParam(value = ALARM_QUERY_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_STATUS_ALLOWABLE_VALUES)
|
213
|
266
|
@RequestParam(required = false) String status,
|
|
267
|
+ @ApiParam(value = PAGE_SIZE_DESCRIPTION)
|
214
|
268
|
@RequestParam int pageSize,
|
|
269
|
+ @ApiParam(value = PAGE_NUMBER_DESCRIPTION)
|
215
|
270
|
@RequestParam int page,
|
|
271
|
+ @ApiParam(value = ALARM_QUERY_TEXT_SEARCH_DESCRIPTION)
|
216
|
272
|
@RequestParam(required = false) String textSearch,
|
|
273
|
+ @ApiParam(value = SORT_PROPERTY_DESCRIPTION, allowableValues = SORT_PROPERTY_ALLOWABLE_VALUES)
|
217
|
274
|
@RequestParam(required = false) String sortProperty,
|
|
275
|
+ @ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
218
|
276
|
@RequestParam(required = false) String sortOrder,
|
|
277
|
+ @ApiParam(value = ALARM_QUERY_START_TIME_DESCRIPTION)
|
219
|
278
|
@RequestParam(required = false) Long startTime,
|
|
279
|
+ @ApiParam(value = ALARM_QUERY_END_TIME_DESCRIPTION)
|
220
|
280
|
@RequestParam(required = false) Long endTime,
|
|
281
|
+ @ApiParam(value = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
|
221
|
282
|
@RequestParam(required = false) Boolean fetchOriginator
|
222
|
283
|
) throws ThingsboardException {
|
223
|
284
|
AlarmSearchStatus alarmSearchStatus = StringUtils.isEmpty(searchStatus) ? null : AlarmSearchStatus.valueOf(searchStatus);
|
...
|
...
|
@@ -239,13 +300,19 @@ public class AlarmController extends BaseController { |
239
|
300
|
}
|
240
|
301
|
}
|
241
|
302
|
|
242
|
|
- @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
303
|
+ @ApiOperation(value = "Get Highest Alarm Severity (getHighestAlarmSeverity)",
|
|
304
|
+ notes = "Returns highest AlarmSeverity object for the selected entity.", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
305
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
243
|
306
|
@RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET)
|
244
|
307
|
@ResponseBody
|
245
|
308
|
public AlarmSeverity getHighestAlarmSeverity(
|
|
309
|
+ @ApiParam(value = ENTITY_TYPE_DESCRIPTION)
|
246
|
310
|
@PathVariable("entityType") String strEntityType,
|
|
311
|
+ @ApiParam(value = ENTITY_ID_DESCRIPTION)
|
247
|
312
|
@PathVariable("entityId") String strEntityId,
|
|
313
|
+ @ApiParam(value = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_SEARCH_STATUS_ALLOWABLE_VALUES)
|
248
|
314
|
@RequestParam(required = false) String searchStatus,
|
|
315
|
+ @ApiParam(value = ALARM_QUERY_STATUS_DESCRIPTION, allowableValues = ALARM_QUERY_STATUS_ALLOWABLE_VALUES)
|
249
|
316
|
@RequestParam(required = false) String status
|
250
|
317
|
) throws ThingsboardException {
|
251
|
318
|
checkParameter("EntityId", strEntityId);
|
...
|
...
|
|