3333import java .time .ZoneOffset ;
3434import java .util .Arrays ;
3535import java .util .List ;
36+ import java .util .NoSuchElementException ;
3637import java .util .Optional ;
3738
3839/**
@@ -78,7 +79,7 @@ public ResponseEntity<UtmDashboard> createUtmDashboard(@Valid @RequestBody UtmDa
7879 UtmDashboard result = null ;
7980 try {
8081 utmDashboard .setUserCreated (
81- SecurityUtils .getCurrentUserLogin ().orElseThrow (() -> new UtmEntityCreationException ("Missing user login" )));
82+ SecurityUtils .getCurrentUserLogin ().orElseThrow (() -> new UtmEntityCreationException ("Missing user login" )));
8283 utmDashboard .setCreatedDate (LocalDateTime .now ().toInstant (ZoneOffset .UTC ));
8384
8485 // Set the next system sequence value only if the environment is dev
@@ -89,19 +90,19 @@ public ResponseEntity<UtmDashboard> createUtmDashboard(@Valid @RequestBody UtmDa
8990
9091 result = utmDashboardService .save (utmDashboard );
9192 return ResponseEntity .created (new URI ("/api/utm-dashboards/" + result .getId ())).headers (
92- HeaderUtil .createEntityCreationAlert (ENTITY_NAME , result .getId ().toString ())).body (result );
93+ HeaderUtil .createEntityCreationAlert (ENTITY_NAME , result .getId ().toString ())).body (result );
9394 } catch (DataIntegrityViolationException e ) {
9495 String msg = ctx + ": " + e .getMostSpecificCause ().getMessage ().replaceAll ("\n " , "" );
9596 log .error (msg );
9697 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
9798 return ResponseEntity .status (HttpStatus .CONFLICT ).headers (HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg ))
98- .body (result );
99+ .body (result );
99100 } catch (Exception e ) {
100101 String msg = ctx + ": " + e .getMessage ();
101102 log .error (msg );
102103 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
103104 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
104- HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).body (result );
105+ HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).body (result );
105106 }
106107 }
107108
@@ -123,25 +124,25 @@ public ResponseEntity<UtmDashboard> updateUtmDashboard(@Valid @RequestBody UtmDa
123124 UtmDashboard result = null ;
124125 try {
125126 utmDashboard .setUserModified (
126- SecurityUtils .getCurrentUserLogin ().orElseThrow (() -> new UtmEntityCreationException ("Missing user login" )));
127+ SecurityUtils .getCurrentUserLogin ().orElseThrow (() -> new UtmEntityCreationException ("Missing user login" )));
127128 utmDashboard .setModifiedDate (Instant .now ());
128129 utmDashboard .setSystemOwner (utmDashboard .getSystemOwner () == null ? utmDashboard .getId () < 1000000 : utmDashboard .getSystemOwner ());
129130
130131 result = utmDashboardService .save (utmDashboard );
131132 return ResponseEntity .ok ().headers (
132- HeaderUtil .createEntityUpdateAlert (ENTITY_NAME , utmDashboard .getId ().toString ())).body (result );
133+ HeaderUtil .createEntityUpdateAlert (ENTITY_NAME , utmDashboard .getId ().toString ())).body (result );
133134 } catch (DataIntegrityViolationException e ) {
134135 String msg = ctx + ": " + e .getMostSpecificCause ().getMessage ().replaceAll ("\n " , "" );
135136 log .error (msg );
136137 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
137138 return ResponseEntity .status (HttpStatus .CONFLICT ).headers (HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg ))
138- .body (result );
139+ .body (result );
139140 } catch (Exception e ) {
140141 String msg = ctx + ": " + e .getMessage ();
141142 log .error (msg );
142143 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
143144 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
144- HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).body (result );
145+ HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).body (result );
145146 }
146147 }
147148
@@ -163,7 +164,7 @@ public ResponseEntity<List<UtmDashboard>> getAllUtmDashboards(UtmDashboardCriter
163164 log .error (msg );
164165 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
165166 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
166- HeaderUtil .createFailureAlert (null , null , msg )).body (null );
167+ HeaderUtil .createFailureAlert (null , null , msg )).body (null );
167168 }
168169 }
169170
@@ -184,14 +185,15 @@ public ResponseEntity<UtmDashboard> getUtmDashboard(@PathVariable Long id) {
184185 log .error (msg );
185186 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
186187 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
187- HeaderUtil .createFailureAlert (null , null , msg )).body (null );
188+ HeaderUtil .createFailureAlert (null , null , msg )).body (null );
188189 }
189190 }
190191
191192 /**
192193 * DELETE /utm-dashboards/:id : delete the "id" utmDashboard.
193194 *
194195 * @param id the id of the utmDashboard to delete
196+ * @throws NoSuchElementException 404 (Not Found) if the dashboard does not exist or is a system owner
195197 * @return the ResponseEntity with status 200 (OK)
196198 */
197199 @ DeleteMapping ("/utm-dashboards/{id}" )
@@ -200,12 +202,18 @@ public ResponseEntity<Void> deleteUtmDashboard(@PathVariable Long id) {
200202 try {
201203 utmDashboardService .delete (id );
202204 return ResponseEntity .ok ().headers (HeaderUtil .createEntityDeletionAlert (ENTITY_NAME , id .toString ())).build ();
205+ } catch (NoSuchElementException e ) {
206+ String msg = ctx + ": " + e .getMessage ();
207+ log .error (msg );
208+ applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
209+ return ResponseEntity .status (HttpStatus .NOT_FOUND ).headers (
210+ HeaderUtil .createFailureAlert ("" , "" , msg )).body (null );
203211 } catch (Exception e ) {
204212 String msg = ctx + ": " + e .getMessage ();
205213 log .error (msg );
206214 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
207215 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
208- HeaderUtil .createFailureAlert (null , null , msg )).body (null );
216+ HeaderUtil .createFailureAlert (null , null , msg )).body (null );
209217 }
210218 }
211219
@@ -223,13 +231,13 @@ public ResponseEntity<Void> importDashboards(@Valid @RequestBody ImportDashboard
223231 log .error (msg );
224232 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
225233 return ResponseEntity .status (HttpStatus .CONFLICT ).headers (HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg ))
226- .build ();
234+ .build ();
227235 }
228236 msg = ctx + ": " + e .getMessage ();
229237 log .error (msg );
230238 applicationEventService .createEvent (msg , ApplicationEventType .ERROR );
231239 return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).headers (
232- HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).build ();
240+ HeaderUtil .createFailureAlert (ENTITY_NAME , null , msg )).build ();
233241 }
234242 }
235243
0 commit comments