package Ġcom . temp storage . console . controller Ċ Ċ import Ġcom . temp storage . console . service . scheduler . Scheduler Job Ċ import Ġcom . temp storage . console . service . scheduler . Scheduler JobService Ċ import Ġcom . temp storage . console . service . watcher . Watch List Ċ import Ġcom . temp storage . console . service . watcher . Watch List Job Ċ import Ġcom . temp storage . console . service . watcher . Watcher Service Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . web . bind . annotation .* Ċ Ċ @ RestController Ċ @ RequestMapping ("/ api / console / watch ") Ċ class ĠWatch er Controller ( ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġscheduler JobService : ĠScheduler JobService , ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġwatcher Service : ĠWatch er Service Ċ ) Ġ{ ĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġlogger Ġ= ĠLoggerFactory . getLogger ( Watcher Controller :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ("/ list ") ĊĠĠĠ Ġfun ĠgetAll Jobs (): ĠResponseEntity < List < Scheduler Job >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġscheduler JobService . getAll Scheduler Jobs () ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ("/ list /{ user }") ĊĠĠĠ Ġfun ĠgetAll Jobs ForUser (@ PathVariable (" user ") Ġuser : ĠString ): ĠResponseEntity < List < Watch List Job >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Watch List Ġ= Ġwatcher Service . getUser Watch List ( user ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġuser Watch List . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġjob Ġ= Ġscheduler JobService . get Scheduler Job ( it . scheduler Job Name ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠWatch List Job ( job . job Type , Ġjob . job Name , Ġjob . description , Ġjob . cron Expression , Ġjob . job Status , Ġit . isObject Valid ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ GetMapping ("/ { job Name }") ĊĠĠĠ Ġfun Ġget Scheduler Job (@ PathVariable (" job Name ") Ġjob Name : ĠString ): ĠResponseEntity < Scheduler Job > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġscheduler JobService . get Scheduler Job ( job Name ) ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Delete Mapping ("/ { job Name }") ĊĠĠĠ Ġfun Ġdelete Scheduler Job (@ PathVariable (" job Name ") Ġjob Name : ĠString ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . delete Scheduler Job ( job Name ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"$ job Name Ġdeleted Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġdelete Ġ$ job Name " ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ PostMapping ("/ create /{ user }") ĊĠĠĠ Ġfun Ġcreate New Scheduler Job (@ PathVariable (" user ") Ġuser : ĠString , Ġ@ RequestBody Ġscheduler Job : ĠScheduler Job ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info ("> >>> ĠCreating ĠNew ĠMonitor ĠJob Ġ= Ġ$ scheduler Job Ġfor Ġ$ user ") ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . create Scheduler Job ( scheduler Job ) ĊĠĠĠĠĠĠĠ Ġif Ġ( result ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwatcher Service . save User Watch List ( Watch List ("", Ġuser , Ġscheduler Job . job Name , Ġfalse )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"${ scheduler Job . job Name } Ġcreated Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġcreate Ġ${ scheduler Job . job Name }" ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ PostMapping ("/ trigger /{ job Name }") ĊĠĠĠ Ġfun Ġtrigger Scheduler Job (@ PathVariable (" job Name ") Ġjob Name : ĠString ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . trigger Scheduler Job ( job Name ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"$ job Name Ġcreated Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġcreate Ġ$ job Name " ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Put Mapping ("/ pause /{ job Name }") ĊĠĠĠ Ġfun Ġpause Scheduler Job (@ PathVariable (" job Name ") Ġjob Name : ĠString ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . pause Scheduler Job ( job Name ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"$ job Name Ġpaused Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġpause Ġ$ job Name " ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Put Mapping ("/ resume /{ job Name }") ĊĠĠĠ Ġfun Ġresume Scheduler Job (@ PathVariable (" job Name ") Ġjob Name : ĠString ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . resume Scheduler Job ( job Name ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"$ job Name Ġres umed Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġresume Ġ$ job Name " ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Put Mapping ("/ update ") ĊĠĠĠ Ġfun Ġupdate Scheduler Job (@ RequestBody Ġscheduler Job : ĠScheduler Job ): ĠResponseEntity < String > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġscheduler JobService . update Scheduler Job ( scheduler Job ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġif Ġ( result ) Ġ"${ scheduler Job . job Name } Ġupdated Ġsuccessfully " Ġelse Ġ" Failed Ġto Ġupdate Ġ${ scheduler Job . job Name }" ĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( response , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} Ċ } Ċ