package Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . controller Ċ Ċ import Ġorg . hibernate . validator . constraints . Length Ċ import Ġorg . springframework . boot . autoconfigure . condition . Conditional On Web Application Ċ import Ġorg . springframework . stereotype . Controller Ċ import Ġorg . springframework . ui . Model Map Ċ import Ġorg . springframework . validation . Binding Result Ċ import Ġorg . springframework . web . bind . annotation . GetMapping Ċ import Ġorg . springframework . web . bind . annotation . Model Attribute Ċ import Ġorg . springframework . web . bind . annotation . PathVariable Ċ import Ġorg . springframework . web . bind . annotation . PostMapping Ċ import Ġorg . springframework . web . bind . annotation . RequestParam Ċ import Ġorg . springframework . web . bind . annotation . Session Attributes Ċ import Ġorg . springframework . web . servlet . mvc . support . Redirect Attributes Ċ import Ġorg . springframework . web . util . Uri Components Builder Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . controller . Manage Jo urney Price Catalog ue Controller . Companion . SEARCH _ JO UR NE YS _ RESULTS _ URL Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . controller . Map Friendly Location Controller . Companion . LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . controller . constraints . Valid Duplicate Location Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . domain . location . Location Type Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . service . B asm Client ApiService Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . service . locations . Locations Service Ċ import Ġuk . gov . just ice . digital . h mp ps . pec s . j pc . util . logger For Ċ import Ġjavax . validation . Valid Ċ import Ġjavax . validation . constraints . NotBlank Ċ import Ġjavax . validation . constraints . NotEmpty Ċ import Ġjavax . validation . constraints . NotNull Ċ Ċ /** Ċ Ġ* ĠController Ġto Ġhelp Ġwith Ġmapping Ġa Ġuser - friendly Ġlocation Ġname Ġto Ġagency ĠID ĠSchedule Ġ 3 4 Ġlocations Ġnames . Ċ Ġ*/ Ċ private Ġval Ġlogger Ġ= Ġlogger For < Map Friendly Location Controller >() Ċ Ċ @ Controller Ċ @ Session Attributes ( SUP PLIER _ ATTRIBUTE , ĠP ICK _ UP _ ATTRIBUTE , ĠDROP _ OFF _ ATTRIBUTE , ĠLOC ATION _ ORIGIN _ SESSION _ ATTRIBUTE ) Ċ @ Conditional On Web Application Ċ class ĠMap Friendly Location Controller ( ĊĠ Ġprivate Ġval Ġservice : ĠLoc ations Service , ĊĠ Ġprivate Ġval Ġb asm Client ApiService : ĠB asm Client ApiService Ċ ) Ġ: ĠPrimary NavigationBar Ġ{ ĊĊĠ Ġoverride Ġfun Ġprimary Navigation Choice () Ġ= ĠPrimary Navigation . LOCATION ĊĊĠ Ġ@ GetMapping ("$ MAP _ LOCATION /{ agency - id }") ĊĠ Ġfun Ġmap Friendly Location ( ĊĠĠĠ Ġ@ PathVariable (" agency - id ") Ġagency Id : ĠString , ĊĠĠĠ Ġ@ RequestParam ( name Ġ= ĠLOC ATION _ ORIGIN _ SESSION _ ATTRIBUTE , Ġrequired Ġ= Ġfalse ) Ġorigin : ĠString ?, ĊĠĠĠ Ġmodel : ĠModel Map ĊĠ Ġ): ĠString Ġ{ ĊĠĠĠ Ġlogger . info (" getting Ġmap Ġfriendly Ġlocation Ġfor Ġ$ agency Id ") ĊĊĠĠĠ Ġval Ġnom is Location Name Ġ= Ġb asm Client ApiService . find Nom is Ag ency Location Name By ( agency Id ) ĊĠĠĠĠĠ Ġ?: Ġ" Sorry , Ġwe Ġare Ġcurrently Ġunable Ġto Ġretrieve Ġthe ĠNO MIS ĠLocation ĠName . ĠPlease Ġtry Ġagain Ġlater ." ĊĊĠĠĠ Ġservice . find Ag ency Location And Type ( agency Id )?. let Ġ{ ĊĠĠĠĠĠ Ġmodel . addAttribute ( ĊĠĠĠĠĠĠĠ Ġ" form ", ĊĠĠĠĠĠĠĠ ĠMap Location Form ( ĊĠĠĠĠĠĠĠĠĠ Ġagency Id Ġ= Ġit . first , ĊĠĠĠĠĠĠĠĠĠ Ġlocation Name Ġ= Ġit . second , ĊĠĠĠĠĠĠĠĠĠ Ġlocation Type Ġ= Ġit . third , ĊĠĠĠĠĠĠĠĠĠ Ġoperation Ġ= Ġ" update ", ĊĠĠĠĠĠĠĠĠĠ Ġnom is Location Name Ġ= Ġnom is Location Name ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġmodel . addAttribute ( ĊĠĠĠĠĠĠĠ Ġ" history ", ĊĠĠĠĠĠĠĠ Ġservice . location History For Ag ency Id ( agency Id ) ĊĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġhistory Ġ-> ĠLocation History Dto . valueOf ( history ) Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. sorted By Descending Ġ{ Ġlh Ġ-> Ġlh . datetime Ġ} ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġmodel . add Cancel Link For ( Uri Components Builder . from Uri String ( SEARCH _ JO UR NE YS _ RESULTS _ URL )) ĊĠĠĠĠĠ Ġmodel . remember Location Change Type Prior ToUpdate ( origin !! ) ĊĊĠĠĠĠĠ Ġreturn Ġ" update - location " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġmodel . addAttribute ( ĊĠĠĠĠĠ Ġ" form ", ĊĠĠĠĠĠ ĠMap Location Form ( ĊĠĠĠĠĠĠĠ Ġagency Id Ġ= Ġagency Id , ĊĠĠĠĠĠĠĠ Ġoperation Ġ= Ġ" create ", ĊĠĠĠĠĠĠĠ Ġnom is Location Name Ġ= Ġnom is Location Name ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġreturn Ġ" add - location " ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠModel Map . remember Location Change Type Prior ToUpdate ( type : ĠString ) Ġ{ ĊĠĠĠ Ġthis . addAttribute ( LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE , Ġtype ) ĊĠ Ġ} ĊĊĠ Ġ@ PostMapping ( MAP _ LOCATION ) ĊĠ Ġfun Ġmap Friendly Location ( ĊĠĠĠ Ġ@ Valid Ġ@ Model Attribute (" form ") Ġform : ĠMap Location Form , ĊĠĠĠ Ġresult : ĠBinding Result , ĊĠĠĠ Ġmodel : ĠModel Map , ĊĠĠĠ Ġredirect Attributes : ĠRedirect Attributes ĊĠ Ġ): ĠString Ġ{ ĊĠĠĠ Ġlogger . info (" mapping Ġfriendly Ġlocation Ġfor Ġagency Ġid Ġ${ form . agency Id }") ĊĊĠĠĠ Ġval Ġsearch Results Url Ġ= ĠUri Components Builder . from Uri String ( SEARCH _ JO UR NE YS _ RESULTS _ URL ) ĊĊĠĠĠ Ġresult . reject If Contains Invalid Characters ( form . location Name , Ġ" location Name ", Ġ" Invalid Ġlocation ") ĊĊĠĠĠ Ġif Ġ( result . has Errors ()) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( form . operation Ġ== Ġ" update ") Ġ{ ĊĠĠĠĠĠĠĠ Ġmodel . add Cancel Link For ( search Results Url ) ĊĊĠĠĠĠĠĠĠ Ġmodel . addAttribute ( ĊĠĠĠĠĠĠĠĠĠ Ġ" history ", ĊĠĠĠĠĠĠĠĠĠ Ġservice . location History For Ag ency Id ( form . agency Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġhistory Ġ-> ĠLocation History Dto . valueOf ( history ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. sorted By Descending Ġ{ Ġlh Ġ-> Ġlh . datetime Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġ" update - location " ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġreturn Ġ" add - location " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġservice . setLocation Details ( form . agency Id , Ġform . location Name , Ġform . location Type !! ) ĊĊĠĠĠ Ġif Ġ( form . operation Ġ== Ġ" create ") Ġ{ ĊĠĠĠĠĠ Ġredirect Attributes . inform User Of Changes On Redirect (" location - mapped ", Ġform ) ĊĠĠĠĠĠ Ġreturn Ġ" redirect :/ jo urney s " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġif Ġ( form . operation Ġ== Ġ" update ") Ġ{ ĊĠĠĠĠĠ Ġwhen Ġ( val Ġorigin Ġ= Ġmodel . getLocation Origin ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġ" from " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġreflect Change To Location When Return To SearchResults Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . get Optional Attribute ( P ICK _ UP _ ATTRIBUTE ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Results Url . query Param ( P ICK _ UP _ ATTRIBUTE , Ġform . location Name . uppercase ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . addAttribute ( P ICK _ UP _ ATTRIBUTE , Ġform . location Name . uppercase ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . get Optional Attribute ( DROP _ OFF _ ATTRIBUTE ) Ġ{ Ġsearch Results Url . query Param ( DROP _ OFF _ ATTRIBUTE , Ġit ) Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ" to " Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġreflect Change To Location When Return To SearchResults Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . get Optional Attribute ( P ICK _ UP _ ATTRIBUTE ) Ġ{ Ġsearch Results Url . query Param ( P ICK _ UP _ ATTRIBUTE , Ġit ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . get Optional Attribute ( DROP _ OFF _ ATTRIBUTE ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Results Url . query Param ( DROP _ OFF _ ATTRIBUTE , Ġform . location Name . uppercase ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . addAttribute ( DROP _ OFF _ ATTRIBUTE , Ġform . location Name . uppercase ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠRuntimeException (" Unknown Ġlocation Ġorigin Ġ'$ origin '") ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġredirect Attributes . inform User Of Changes On Redirect (" location - updated ", Ġform ) ĊĠĠĠĠĠ Ġmodel . addAttribute ( LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE , Ġ"") ĊĊĠĠĠĠĠ Ġreturn Ġ" redirect :${ search Results Url . build (). to Uri () }" ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġthrow ĠThrowable (" Invalid Ġoperation Ġ${ form . operation }") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġreflect Change To Location When Return To SearchResults ( callback : Ġ() Ġ-> ĠUnit ) Ġ= Ġcallback () ĊĊĠ Ġprivate Ġfun ĠRedirect Attributes . inform User Of Changes On Redirect ( operation : ĠString , Ġform : ĠMap Location Form ) Ġ{ ĊĠĠĠ Ġthis . add Flash Attribute (" flash Message ", Ġoperation ) ĊĠĠĠ Ġthis . add Flash Attribute (" flash Attr Mapped Location Name ", Ġform . location Name . uppercase ()) ĊĠĠĠ Ġthis . add Flash Attribute (" flash Attr Mapped Ag ency Id ", Ġform . agency Id ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠModel Map . add Cancel Link For ( url : ĠUri Components Builder ) Ġ{ ĊĠĠĠ Ġthis . get Optional Attribute ( P ICK _ UP _ ATTRIBUTE ) Ġ{ Ġpick Up Ġ-> Ġurl . query Param ( P ICK _ UP _ ATTRIBUTE , Ġpick Up ) Ġ} ĊĠĠĠ Ġthis . get Optional Attribute ( DROP _ OFF _ ATTRIBUTE ) Ġ{ Ġdrop Off Ġ-> Ġurl . query Param ( DROP _ OFF _ ATTRIBUTE , Ġdrop Off ) Ġ} ĊĠĠĠ Ġthis . addAttribute (" cancel Link ", Ġurl . build (). to Uri String ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠModel Map . get Optional Attribute ( attr : ĠString , Ġcallback : Ġ( s : ĠString ) Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġwhen Ġ( val Ġvalue Ġ= Ġthis . getAttribute ( attr )) Ġ{ ĊĠĠĠĠĠ Ġis ĠString Ġ-> Ġif Ġ( value . isNotBlank ()) Ġcallback ( value ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠModel Map . getLocation Origin (): ĠString Ġ{ ĊĠĠĠ Ġwhen Ġ( val Ġvalue Ġ= Ġthis . getAttribute ( LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE )) Ġ{ ĊĠĠĠĠĠ Ġis ĠString Ġ-> Ġif Ġ( value . isNotBlank ()) Ġreturn Ġvalue Ġelse Ġthrow ĠRuntimeException (" Expected Ġattribute Ġ'$ LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE ' Ġis Ġnull Ġor Ġempty ") ĊĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠNullPointerException (" Expected Ġattribute Ġ'$ LOCATION _ ORIGIN _ SESSION _ ATTRIBUTE Ġis Ġmissing ") ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Valid Duplicate Location ĊĠ Ġdata Ġclass ĠMap Location Form ( ĊĠĠĠ Ġ@ get : ĠNot Empty ( message Ġ= Ġ" Enter ĠNO MIS Ġagency Ġid ") ĊĠĠĠ Ġval Ġagency Id : ĠString , ĊĊĠĠĠ Ġ@ get : ĠNot Blank ( message Ġ= Ġ" Enter ĠSchedule Ġ 3 4 Ġlocation ") ĊĠĠĠ Ġ@ get : ĠLength ( max Ġ= Ġ 2 5 5 , Ġmessage Ġ= Ġ" Enter Ġdetails Ġu pto Ġ 2 5 5 Ġcharacters ") ĊĠĠĠ Ġval Ġlocation Name : ĠString Ġ= Ġ"", ĊĊĠĠĠ Ġ@ get : ĠNot Null ( message Ġ= Ġ" Enter ĠSchedule Ġ 3 4 Ġlocation Ġtype ") ĊĠĠĠ Ġval Ġlocation Type : ĠLocation Type ? Ġ= Ġnull , ĊĊĠĠĠ Ġval Ġoperation : ĠString Ġ= Ġ" create ", ĊĊĠĠĠ Ġval Ġnom is Location Name : ĠString ĊĠ Ġ) ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġconst Ġval ĠLOC ATION _ ORIGIN _ SESSION _ ATTRIBUTE Ġ= Ġ" origin " ĊĊĠĠĠ Ġconst Ġval ĠMAP _ LOCATION Ġ= Ġ"/ map - location " ĊĠ Ġ} Ċ } Ċ