11package com .park .utmstack .web .rest ;
22
3+ import com .park .utmstack .aop .logging .AuditEvent ;
34import com .park .utmstack .domain .application_events .enums .ApplicationEventType ;
45import com .park .utmstack .service .UtmAlertService ;
56import com .park .utmstack .service .application_events .ApplicationEventService ;
7+ import com .park .utmstack .service .dto .alert .ConvertToIncidentRequestBody ;
8+ import com .park .utmstack .service .dto .alert .UpdateAlertStatusRequestBody ;
9+ import com .park .utmstack .service .dto .alert .UpdateAlertTagsRequestBody ;
610import com .park .utmstack .util .AlertUtil ;
711import com .park .utmstack .util .UtilResponse ;
812import com .park .utmstack .web .rest .util .HeaderUtil ;
1317import org .springframework .web .bind .annotation .*;
1418
1519import javax .validation .Valid ;
16- import javax .validation .constraints .NotNull ;
17- import javax .validation .constraints .Pattern ;
18- import java .util .List ;
20+ import java .io .IOException ;
1921
2022/**
2123 * REST controller for managing UtmAlert.
@@ -40,63 +42,58 @@ public UtmAlertResource(UtmAlertService utmAlertService,
4042 }
4143
4244 @ PostMapping ("/utm-alerts/status" )
43- public ResponseEntity <Void > updateAlertStatus (@ RequestBody UpdateAlertStatusRequestBody rq ) {
45+ @ AuditEvent (
46+ attemptType = ApplicationEventType .ALERT_UPDATE_ATTEMPT ,
47+ attemptMessage = "Attempt to update alert status initiated" ,
48+ successType = ApplicationEventType .ALERT_UPDATE_SUCCESS ,
49+ successMessage = "Alert status updated successfully"
50+ )
51+ public ResponseEntity <Void > updateAlertStatus (@ RequestBody UpdateAlertStatusRequestBody rq ) throws IOException {
4452 final String ctx = CLASSNAME + ".updateAlertStatus" ;
45- try {
46- utmAlertService .updateStatus (rq .getAlertIds (), rq .getStatus (), rq .getStatusObservation ());
47- return ResponseEntity .ok ().build ();
48- } catch (Exception e ) {
49- String msg = ctx + ": " + e .getMessage ();
50- log .error (msg );
51- applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
52- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
53- HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
54- }
53+
54+ utmAlertService .updateStatus (rq .getAlertIds (), rq .getStatus (), rq .getStatusObservation ());
55+ return ResponseEntity .ok ().build ();
5556 }
5657
5758 @ PostMapping ("/utm-alerts/notes" )
59+ @ AuditEvent (
60+ attemptType = ApplicationEventType .ALERT_NOTE_UPDATE_ATTEMPT ,
61+ attemptMessage = "Attempt to update alert notes initiated" ,
62+ successType = ApplicationEventType .ALERT_NOTE_UPDATE_SUCCESS ,
63+ successMessage = "Alert notes updated successfully"
64+ )
5865 public ResponseEntity <Void > updateAlertNotes (@ RequestBody (required = false ) String notes , @ RequestParam String alertId ) {
5966 final String ctx = CLASSNAME + ".updateAlertNotes" ;
60- try {
61- utmAlertService .updateNotes (alertId , notes );
62- return ResponseEntity .ok ().build ();
63- } catch (Exception e ) {
64- String msg = ctx + ": " + e .getMessage ();
65- log .error (msg );
66- applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
67- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
68- HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
69- }
67+ utmAlertService .updateNotes (alertId , notes );
68+ return ResponseEntity .ok ().build ();
7069 }
7170
7271 @ PostMapping ("/utm-alerts/tags" )
72+ @ AuditEvent (
73+ attemptType = ApplicationEventType .ALERT_TAG_UPDATE_ATTEMPT ,
74+ attemptMessage = "Attempt to update alert tags initiated" ,
75+ successType = ApplicationEventType .ALERT_TAG_UPDATE_SUCCESS ,
76+ successMessage = "Alert tags updated successfully"
77+ )
7378 public ResponseEntity <Void > updateAlertTags (@ RequestBody @ Valid UpdateAlertTagsRequestBody body ) {
74- final String ctx = CLASSNAME + ".updateAlertTags" ;
75- try {
76- utmAlertService .updateTags (body .getAlertIds (), body .getTags (), body .isCreateRule ());
77- return ResponseEntity .ok ().build ();
78- } catch (Exception ex ) {
79- String msg = ctx + ": " + ex .getMessage ();
80- log .error (msg );
81- applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
82- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
83- HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
84- }
79+
80+ utmAlertService .updateTags (body .getAlertIds (), body .getTags (), body .getCreateRule ());
81+ return ResponseEntity .ok ().build ();
8582 }
8683
8784 @ PostMapping ("/utm-alerts/convert-to-incident" )
85+ @ AuditEvent (
86+ attemptType = ApplicationEventType .ALERT_CONVERT_TO_INCIDENT_ATTEMPT ,
87+ attemptMessage = "Attempt to convert alerts to incident initiated" ,
88+ successType = ApplicationEventType .ALERT_CONVERT_TO_INCIDENT_SUCCESS ,
89+ successMessage = "Alerts converted to incident successfully"
90+ )
8891 public ResponseEntity <Void > convertToIncident (@ RequestBody @ Valid ConvertToIncidentRequestBody body ) {
8992 final String ctx = CLASSNAME + ".convertToIncident" ;
90- try {
91- utmAlertService .convertToIncident (body .getEventIds (), body .getIncidentName (),body .getIncidentId (), body .getIncidentSource ());
92- return ResponseEntity .ok ().build ();
93- } catch (Exception ex ) {
94- String msg = ctx + ": " + ex .getMessage ();
95- log .error (msg );
96- applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
97- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
98- HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
99- }
93+
94+ utmAlertService .convertToIncident (body .getEventIds (), body .getIncidentName (),body .getIncidentId (), body .getIncidentSource ());
95+ return ResponseEntity .ok ().build ();
96+
10097 }
10198
10299 @ GetMapping ("/utm-alerts/count-open-alerts" )
@@ -111,135 +108,4 @@ public ResponseEntity<Long> countOpenAlerts() {
111108 return UtilResponse .buildErrorResponse (HttpStatus .INTERNAL_SERVER_ERROR , msg );
112109 }
113110 }
114-
115- public static class UpdateAlertTagsRequestBody {
116- @ NotNull
117- private List <String > alertIds ;
118- private List <String > tags ;
119- @ NotNull
120- private Boolean createRule ;
121-
122- public List <String > getAlertIds () {
123- return alertIds ;
124- }
125-
126- public void setAlertIds (List <String > alertIds ) {
127- this .alertIds = alertIds ;
128- }
129-
130- public List <String > getTags () {
131- return tags ;
132- }
133-
134- public void setTags (List <String > tags ) {
135- this .tags = tags ;
136- }
137-
138- public Boolean isCreateRule () {
139- return createRule ;
140- }
141-
142- public void setCreateRule (Boolean createRule ) {
143- this .createRule = createRule ;
144- }
145- }
146-
147- public static class UpdateAlertStatusRequestBody {
148- @ NotNull
149- private List <String > alertIds ;
150- private String statusObservation ;
151- @ NotNull
152- private int status ;
153-
154- public List <String > getAlertIds () {
155- return alertIds ;
156- }
157-
158- public void setAlertIds (List <String > alertIds ) {
159- this .alertIds = alertIds ;
160- }
161-
162- public String getStatusObservation () {
163- return statusObservation ;
164- }
165-
166- public void setStatusObservation (String statusObservation ) {
167- this .statusObservation = statusObservation ;
168- }
169-
170- public int getStatus () {
171- return status ;
172- }
173-
174- public void setStatus (int status ) {
175- this .status = status ;
176- }
177- }
178-
179- public static class UpdateAlertSolutionRequestBody {
180- @ NotNull
181- private String alertName ;
182- @ NotNull
183- private String solution ;
184-
185- public String getAlertName () {
186- return alertName ;
187- }
188-
189- public void setAlertName (String alertName ) {
190- this .alertName = alertName ;
191- }
192-
193- public String getSolution () {
194- return solution ;
195- }
196-
197- public void setSolution (String solution ) {
198- this .solution = solution ;
199- }
200- }
201-
202- public static class ConvertToIncidentRequestBody {
203- @ NotNull
204- private List <String > eventIds ;
205- @ NotNull
206- @ Pattern (regexp = "^[^\" ]*$" , message = "Double quotes are not allowed" )
207- private String incidentName ;
208- @ NotNull
209- private Integer incidentId ;
210- @ NotNull
211- private String incidentSource ;
212-
213- public List <String > getEventIds () {
214- return eventIds ;
215- }
216-
217- public void setEventIds (List <String > eventIds ) {
218- this .eventIds = eventIds ;
219- }
220-
221- public String getIncidentName () {
222- return incidentName ;
223- }
224-
225- public void setIncidentName (String incidentName ) {
226- this .incidentName = incidentName ;
227- }
228-
229- public Integer getIncidentId () {
230- return incidentId ;
231- }
232-
233- public void setIncidentId (Integer incidentId ) {
234- this .incidentId = incidentId ;
235- }
236-
237- public String getIncidentSource () {
238- return incidentSource ;
239- }
240-
241- public void setIncidentSource (String incidentSource ) {
242- this .incidentSource = incidentSource ;
243- }
244- }
245111}
0 commit comments