@@ -72,14 +72,17 @@ public class TaskAdminController {
7272 private final Scheduler scheduler ;
7373 private final TaskManagerService taskManagerService ;
7474 private final SearchIndexRepository searchIndexRepository ;
75+ private final JsonMapper jsonMapper ;
7576
7677 public TaskAdminController (
7778 @ Autowired Scheduler scheduler ,
7879 @ Autowired TaskManagerService taskManagerService ,
79- @ Autowired SearchIndexRepository searchIndexRepository ) {
80+ @ Autowired SearchIndexRepository searchIndexRepository ,
81+ JsonMapper jsonMapper ) {
8082 this .scheduler = scheduler ;
8183 this .taskManagerService = taskManagerService ;
8284 this .searchIndexRepository = searchIndexRepository ;
85+ this .jsonMapper = jsonMapper ;
8386 }
8487
8588 @ Operation (summary = "List all tasks, optionally filtered by type" , description = """
@@ -127,7 +130,7 @@ public ResponseEntity<Object> list(@RequestParam(required = false) String type)
127130 logger .error ("Error getting task state" , e );
128131 state = null ;
129132 }
130- tasks .add (new JsonMapper ()
133+ tasks .add (this . jsonMapper
131134 .createObjectNode ()
132135 .put (Task .TYPE_KEY , jobDetail .getKey ().getGroup ())
133136 .put (Task .UUID_KEY , jobDetail .getKey ().getName ())
@@ -146,9 +149,9 @@ public ResponseEntity<Object> list(@RequestParam(required = false) String type)
146149 throw new ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , "Error getting tasks" , e );
147150 }
148151
149- return ResponseEntity .ok (new JsonMapper ()
152+ return ResponseEntity .ok (this . jsonMapper
150153 .createObjectNode ()
151- .set ("tasks" , new JsonMapper () .createArrayNode ().addAll (tasks )));
154+ .set ("tasks" , this . jsonMapper .createArrayNode ().addAll (tasks )));
152155 }
153156
154157 @ Operation (summary = "List all details for a given task" , description = """
@@ -217,7 +220,7 @@ public ResponseEntity<Object> details(@PathVariable TaskType type, @PathVariable
217220 result [0 ] = jobExecutionContext .getResult ();
218221 });
219222
220- return ResponseEntity .ok (new JsonMapper ()
223+ return ResponseEntity .ok (this . jsonMapper
221224 .createObjectNode ()
222225 // immutable uuid, type and description
223226 .put (Task .TYPE_KEY , jobDetail .getKey ().getGroup ())
@@ -277,7 +280,7 @@ public ResponseEntity<Object> startTask(@PathVariable TaskType type, @PathVariab
277280 }
278281 scheduler .triggerJob (jobKey );
279282 return ResponseEntity .status (HttpStatusCode .valueOf (HTTP_ACCEPTED ))
280- .body (new JsonMapper () .createObjectNode ().put ("message" , "Task starting accepted" ));
283+ .body (this . jsonMapper .createObjectNode ().put ("message" , "Task starting accepted" ));
281284
282285 } catch (SchedulerException e ) {
283286 throw new ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , "Error getting task" , e );
@@ -329,13 +332,13 @@ public ResponseEntity<Object> stopTask(@PathVariable TaskType type, @PathVariabl
329332 scheduler .getJobDetail (jobKey ).getJobClass ())) {
330333 boolean interrupted = scheduler .interrupt (jobKey );
331334 return ResponseEntity .status (HttpStatusCode .valueOf (HTTP_ACCEPTED ))
332- .body (new JsonMapper ()
335+ .body (this . jsonMapper
333336 .createObjectNode ()
334337 .put ("message" , "Task stopping accepted" )
335338 .put ("succes" , interrupted ));
336339 } else {
337340 return ResponseEntity .status (HttpStatusCode .valueOf (HTTP_BAD_REQUEST ))
338- .body (new JsonMapper ()
341+ .body (this . jsonMapper
339342 .createObjectNode ()
340343 .put ("message" , "Task cannot be stopped" )
341344 .put ("succes" , false ));
@@ -397,7 +400,7 @@ private void deleteScheduleFromSearchIndex(UUID uuid) {
397400 private ResponseEntity <Object > handleTaskNotFound () {
398401 return ResponseEntity .status (HttpStatusCode .valueOf (HTTP_NOT_FOUND ))
399402 .contentType (MediaType .APPLICATION_JSON )
400- .body (new JsonMapper ()
403+ .body (this . jsonMapper
401404 .createObjectNode ()
402405 .put ("message" , "Task not found" )
403406 .put ("code" , HTTP_NOT_FOUND ));
0 commit comments