package Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . services Ċ Ċ import Ġorg . springframework . data . domain . Page Ċ import Ġorg . springframework . data . domain . Page able Ċ import Ġorg . springframework . stereotype . Service Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Draft Ad jud ication Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Incident Details Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Incident Role Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Incident Statement Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Off ence Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Off ence Rule Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . d tos . Reported Ad jud ication Dto Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Draft Ad jud ication Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Incident Details Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Incident Role Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Incident Statement Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Off ence Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Reported Ad jud ication Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Reported Ad jud ication Status Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . entities . Reported Off ence Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . repositories . Draft Ad jud ication Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . repositories . Reported Ad jud ication Repository Ċ import Ġuk . gov . just ice . digital . h mp ps . h mp ps manage adj ud ic ations api . security . Authentication Facade Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . time . Local Time Ċ import Ġjava . util . Optional Ċ import Ġjavax . persistence . Entity NotFoundException Ċ Ċ @ Service Ċ class ĠReport ed Ad jud ication Service ( ĊĠ Ġval Ġdraft Ad jud ication Repository : ĠDraft Ad jud ication Repository , ĊĠ Ġval Ġreported Ad jud ication Repository : ĠReport ed Ad jud ication Repository , ĊĠ Ġval Ġoff ence Code Lookup Service : ĠOff ence Code Lookup Service , ĊĠ Ġval Ġauthentication Facade : ĠAuthentication Facade Ċ ) Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġfun Ġthrow Entity NotFoundException ( id : ĠLong ): ĠNothing Ġ= ĊĠĠĠĠĠ Ġthrow ĠEntity NotFoundException (" Reported Ad jud ication Ġnot Ġfound Ġfor Ġ$ id ") ĊĠĠĠ Ġfun Ġreports From ( startDate : ĠLocalDate ): ĠLocalDateTime Ġ= ĠstartDate . at Start OfDay () ĊĠĠĠ Ġfun Ġreports To ( endDate : ĠLocalDate ): ĠLocalDateTime Ġ= ĠendDate . at Time ( Local Time . MAX ) ĊĠĠĠ Ġfun Ġstatuses ( status : ĠOptional < Reported Ad jud ication Status >): ĠList < Reported Ad jud ication Status > Ġ= Ġstatus . map Ġ{ ĠlistOf ( it ) Ġ}. orElse ( Reported Ad jud ication Status . values (). toList ()) ĊĠ Ġ} ĊĊĠ Ġfun Ġget Reported Ad jud ication Details ( adj ud ication Number : ĠLong ): ĠReport ed Ad jud ication Dto Ġ{ ĊĠĠĠ Ġval Ġreported Ad jud ication Ġ= ĊĠĠĠĠĠ Ġreported Ad jud ication Repository . findBy Report Number ( adj ud ication Number ) ĊĊĠĠĠ Ġreturn Ġreported Ad jud ication ?. to Dto ( off ence Code Lookup Service ) Ġ?: Ġthrow Entity NotFoundException ( adj ud ication Number ) ĊĠ Ġ} ĊĊĠ Ġfun ĠgetAll Reported Ad jud ic ations ( agency Id : ĠString , ĠstartDate : ĠLocalDate , ĠendDate : ĠLocalDate , Ġstatus : ĠOptional < Reported Ad jud ication Status >, Ġpage able : ĠPage able ): ĠPage < Reported Ad jud ication Dto > Ġ{ ĊĠĠĠ Ġval Ġreported Ad jud ic ations Page Ġ= ĊĠĠĠĠĠ Ġreported Ad jud ication Repository . findBy Ag ency Id And DateTime Of Incident Between And Status In ( ĊĠĠĠĠĠĠĠ Ġagency Id , Ġreports From ( startDate ), Ġreports To ( endDate ), Ġstatuses ( status ), Ġpage able ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġreturn Ġreported Ad jud ic ations Page . map Ġ{ Ġit . to Dto ( off ence Code Lookup Service ) Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġget My Reported Ad jud ic ations ( agency Id : ĠString , ĠstartDate : ĠLocalDate , ĠendDate : ĠLocalDate , Ġstatus : ĠOptional < Reported Ad jud ication Status >, Ġpage able : ĠPage able ): ĠPage < Reported Ad jud ication Dto > Ġ{ ĊĠĠĠ Ġval Ġusername Ġ= Ġauthentication Facade . current Username ĊĊĠĠĠ Ġval Ġreported Ad jud ic ations Page Ġ= ĊĠĠĠĠĠ Ġreported Ad jud ication Repository . findBy CreatedBy UserId And Ag ency Id And DateTime Of Incident Between And Status In ( ĊĠĠĠĠĠĠĠ Ġusername !! , Ġagency Id , Ġreports From ( startDate ), Ġreports To ( endDate ), Ġstatuses ( status ), Ġpage able ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġreturn Ġreported Ad jud ic ations Page . map Ġ{ Ġit . to Dto ( off ence Code Lookup Service ) Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġcreate Draft From Reported Ad jud ication ( adj ud ication Number : ĠLong ): ĠDraft Ad jud ication Dto Ġ{ ĊĠĠĠ Ġval Ġfound Reported Ad jud ication Ġ= ĊĠĠĠĠĠ Ġreported Ad jud ication Repository . findBy Report Number ( adj ud ication Number ) ĊĊĠĠĠ Ġval Ġreported Ad jud ication Ġ= Ġfound Reported Ad jud ication Ġ?: Ġthrow Entity NotFoundException ( adj ud ication Number ) ĊĊĠĠĠ Ġval Ġdraft Ad jud ication Ġ= ĠDraft Ad jud ication ( ĊĠĠĠĠĠ Ġreport Number Ġ= Ġreported Ad jud ication . report Number , ĊĠĠĠĠĠ Ġreport By UserId Ġ= Ġreported Ad jud ication . created By UserId , ĊĠĠĠĠĠ Ġpr isoner Number Ġ= Ġreported Ad jud ication . pr isoner Number , ĊĠĠĠĠĠ Ġagency Id Ġ= Ġreported Ad jud ication . agency Id , ĊĠĠĠĠĠ Ġincident Details Ġ= ĠInc ident Details ( ĊĠĠĠĠĠĠĠ Ġlocation Id Ġ= Ġreported Ad jud ication . location Id , ĊĠĠĠĠĠĠĠ ĠdateTime Of Incident Ġ= Ġreported Ad jud ication . dateTime Of Incident , ĊĠĠĠĠĠĠĠ Ġhand over Deadline Ġ= Ġreported Ad jud ication . hand over Deadline ĊĠĠĠĠĠ Ġ), ĊĠĠĠĠĠ Ġincident Role Ġ= ĠInc ident Role ( ĊĠĠĠĠĠĠĠ Ġrole Code Ġ= Ġreported Ad jud ication . incident Role Code , ĊĠĠĠĠĠĠĠ Ġassociated Pr ison ers Number Ġ= Ġreported Ad jud ication . incident Role Associated Pr ison ers Number , ĊĠĠĠĠĠ Ġ), ĊĠĠĠĠĠ Ġoff ence Details Ġ= Ġto Draft Off ence ( reported Ad jud ication . off ence Details ), ĊĠĠĠĠĠ Ġincident Statement Ġ= ĠInc ident Statement ( ĊĠĠĠĠĠĠĠ Ġstatement Ġ= Ġreported Ad jud ication . statement , ĊĠĠĠĠĠĠĠ Ġcompleted Ġ= Ġtrue ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġreturn Ġdraft Ad jud ication Repository ĊĠĠĠĠĠ Ġ. save ( draft Ad jud ication ) ĊĠĠĠĠĠ Ġ. to Dto ( off ence Code Lookup Service ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġto Draft Off ence ( off ences : ĠMutable List < Reported Off ence >? ): ĠMutable List < Off ence > Ġ{ ĊĠĠĠ Ġreturn Ġ( off ences Ġ?: Ġmutable ListOf ()). map Ġ{ Ġoff ence Ġ-> ĊĠĠĠĠĠ ĠOff ence ( ĊĠĠĠĠĠĠĠ Ġoff ence Code Ġ= Ġoff ence . off ence Code , ĊĠĠĠĠĠĠĠ Ġparagraph Code Ġ= Ġoff ence . paragraph Code , ĊĠĠĠĠĠĠĠ Ġv ictim Pr ison ers Number Ġ= Ġoff ence . v ictim Pr ison ers Number , ĊĠĠĠĠĠĠĠ Ġv ictim Staff Username Ġ= Ġoff ence . v ictim Staff Username , ĊĠĠĠĠĠĠĠ Ġv ictim Other Pers ons Name Ġ= Ġoff ence . v ictim Other Pers ons Name , ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ}. to Mutable List () ĊĠ Ġ} ĊĊĠ Ġfun ĠsetStatus ( adj ud ication Number : ĠLong , Ġstatus : ĠReport ed Ad jud ication Status , Ġstatus Reason : ĠString ? Ġ= Ġnull , Ġstatus Details : ĠString ? Ġ= Ġnull ): ĠReport ed Ad jud ication Dto Ġ{ ĊĠĠĠ Ġval Ġreported Ad jud ication Ġ= Ġreported Ad jud ication Repository . findBy Report Number ( adj ud ication Number ) ĊĠĠĠ Ġreported Ad jud ication ?. let Ġ{ ĊĠĠĠĠĠ Ġit . transition ( status , Ġstatus Reason , Ġstatus Details ) ĊĠĠĠĠĠ Ġreturn Ġreported Ad jud ication Repository . save ( it ). to Dto ( this . off ence Code Lookup Service ) ĊĠĠĠ Ġ} Ġ?: Ġthrow Entity NotFoundException ( adj ud ication Number ) ĊĠ Ġ} Ċ } Ċ Ċ fun ĠReport ed Ad jud ication . to Dto ( off ence Code Lookup Service : ĠOff ence Code Lookup Service ): ĠReport ed Ad jud ication Dto Ġ= ĠReport ed Ad jud ication Dto ( ĊĠ Ġadj ud ication Number Ġ= Ġreport Number , ĊĠ Ġpr isoner Number Ġ= Ġpr isoner Number , ĊĠ Ġbooking Id Ġ= Ġbooking Id , ĊĠ Ġincident Details Ġ= ĠInc ident Details Dto ( ĊĠĠĠ Ġlocation Id Ġ= Ġlocation Id , ĊĠĠĠ ĠdateTime Of Incident Ġ= ĠdateTime Of Incident , ĊĠĠĠ Ġhand over Deadline Ġ= Ġhand over Deadline ĊĠ Ġ), ĊĠ Ġincident Role Ġ= ĠInc ident Role Dto ( ĊĠĠĠ Ġrole Code Ġ= Ġincident Role Code , ĊĠĠĠ Ġoff ence Rule Ġ= ĠInc ident Role Rule Lookup . get Off ence Rule Details ( incident Role Code ), ĊĠĠĠ Ġassociated Pr ison ers Number Ġ= Ġincident Role Associated Pr ison ers Number , ĊĠ Ġ), ĊĠ Ġoff ence Details Ġ= Ġto Reported Off ence ( off ence Details , Ġoff ence Code Lookup Service ), ĊĠ Ġincident Statement Ġ= ĠInc ident Statement Dto ( ĊĠĠĠ Ġstatement Ġ= Ġstatement , ĊĠĠĠ Ġcompleted Ġ= Ġtrue , ĊĠ Ġ), ĊĠ Ġcreated By UserId Ġ= Ġcreated By UserId !! , ĊĠ Ġcreated DateTime Ġ= Ġcreate DateTime !! , ĊĠ Ġstatus Ġ= Ġstatus , ĊĠ Ġstatus Reason Ġ= Ġstatus Reason , ĊĠ Ġstatus Details Ġ= Ġstatus Details , Ċ ) Ċ Ċ private Ġfun Ġto Reported Off ence ( off ences : ĠMutable List < Reported Off ence > ?, Ġoff ence Code Lookup Service : ĠOff ence Code Lookup Service ): ĠList < Off ence Dto > Ġ{ ĊĠ Ġreturn Ġ( off ences Ġ?: Ġmutable ListOf ()). map Ġ{ Ġoff ence Ġ-> ĊĠĠĠ ĠOff ence Dto ( ĊĠĠĠĠĠ Ġoff ence Code Ġ= Ġoff ence . off ence Code , ĊĠĠĠĠĠ Ġoff ence Rule Ġ= ĠOff ence Rule Dto ( ĊĠĠĠĠĠĠĠ Ġparagraph Number Ġ= Ġoff ence Code Lookup Service . get Paragraph Number ( off ence . off ence Code ), ĊĠĠĠĠĠĠĠ Ġparagraph Description Ġ= Ġoff ence Code Lookup Service . get Paragraph Description ( off ence . off ence Code ), ĊĠĠĠĠĠ Ġ), ĊĠĠĠĠĠ Ġv ictim Pr ison ers Number Ġ= Ġoff ence . v ictim Pr ison ers Number , ĊĠĠĠĠĠ Ġv ictim Staff Username Ġ= Ġoff ence . v ictim Staff Username , ĊĠĠĠĠĠ Ġv ictim Other Pers ons Name Ġ= Ġoff ence . v ictim Other Pers ons Name , ĊĠĠĠ Ġ) ĊĠ Ġ}. toList () Ċ } Ċ