package Ġcom . ci enet . np . web . rest Ċ Ċ import Ġcom . ci enet . np d app . number . Number Access Flow Ċ import Ġcom . ci enet . np d app . number . Number State Ċ import Ġcom . ci enet . np . cord a . Node RPC Connection Ċ import Ġcom . ci enet . np . cord a . Rpc Info Ċ import Ġcom . ci enet . np . service . dto . Number DTO Ċ import Ġcom . ci enet . np d app . number . Number Transfer From Flow Ċ import Ġcom . co da h ale . metrics . annotation . Timed Ċ import Ġnet . cord a . core . messaging . C ord a RP CO ps Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . Response Entity Ċ import Ġorg . springframework . web . bind . annotation .* Ċ import Ġnet . cord a . core . contracts . State And Ref Ċ import Ġnet . cord a . core . flows . Flow Exception Ċ import Ġnet . cord a . core . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . core . messaging . start Tracked Flow Ċ import Ġnet . cord a . core . node . services . Vault Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria Ċ import Ġnet . cord a . core . utilities . get OrThrow Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ Ċ @ RestController Ċ @ RequestMapping ("/ api ") Ċ class ĠNumber Resource ( private Ġval Ġnode Rpc Connection : ĠNode RPC Connection , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ param : Value ("\ ${ cord app . server }") Ġprivate Ġval Ġserver : ĠString ) Ġ{ ĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠLoggerFactory . getLogger ( Number Resource :: class . java ) ĊĊĠĠĠ Ġprivate Ġval Ġrpc Info Map Ġ= Ġmap Of ( ĊĠĠĠĠĠĠĠ Ġ" operator 1 " Ġto ĠRpc Info ( server , Ġ 1 0 0 0 6 , Ġ" user 1 ", Ġ" test "), ĊĠĠĠĠĠĠĠ Ġ" operator 2 " Ġto ĠRpc Info ( server , Ġ 1 0 0 0 9 , Ġ" user 1 ", Ġ" test "), ĊĠĠĠĠĠĠĠ Ġ" operator 3 " Ġto ĠRpc Info ( server , Ġ 1 0 0 1 2 , Ġ" user 1 ", Ġ" test ")) ĊĊĠĠĠ Ġ@ GetMapping ("/ number /{ operator }") ĊĠĠĠ Ġ@ Timed ĊĠĠĠ Ġfun ĠgetAll Numbers (@ PathVariable Ġoperator : ĠString ): ĠResponseEntity < List < Number DTO >> Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" Get ĠNumber Ġresources Ġfor Ġoperator : Ġ$ operator ") ĊĠĠĠĠĠĠĠ Ġvar Ġnumber List Ġ= ĠlistOf < Number DTO >() ĊĠĠĠĠĠĠĠ Ġrpc Info Map [ operator ]?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġproxy : ĠC ord a RP CO ps Ġ= Ġnode Rpc Connection . get Rpc Connection ( it ). proxy ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnumber List Ġ= Ġquery All State ( proxy ). map Ġ{ Ġstate Ref Ġ-> ĠNumber DTO . from Model ( operator , Ġstate Ref . state . data . number , Ġ 1 )}. toList () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn ĠResponseEntity ( number List , ĠHttpStatus . OK ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ PostMapping ("/ number ") ĊĠĠĠ Ġ@ Timed ĊĠĠĠ Ġfun Ġpublish Number (@ RequestParam (" operator ") Ġoperator : ĠString , Ġ@ RequestParam (" number ") Ġnumber : ĠString ) Ġ: ĠNumber DTO Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" Issue Ġa Ġnumber : Ġ$ number Ġto Ġoperator : Ġ$ operator .") ĊĠĠĠĠĠĠĠ Ġrpc Info Map [ operator ]?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġproxy : ĠC ord a RP CO ps Ġ= Ġnode Rpc Connection . get Rpc Connection ( it ). proxy ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġret Ġ= Ġperform Access Flow ( number , Ġproxy ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠNumber DTO . from Model ( operator , Ġret . state . data . number , ĠĠ 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn ĠNumber DTO . from Model ( operator , Ġ"", Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ PostMapping ("/ number / port ing ") ĊĠĠĠ Ġ@ Timed ĊĠĠĠ Ġfun Ġport ing Number (@ RequestParam (" number ") Ġnumber : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ RequestParam (" operator From ") Ġoperator From : ĠString , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ@ RequestParam (" operator To ") Ġoperator To : ĠString ): ĠNumber DTO Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" Port ing Ġa Ġnumber : Ġ$ number Ġfrom Ġ$ operator From Ġto Ġ$ operator To .") ĊĊĠĠĠĠĠĠĠ Ġval Ġfrom Operator Name : ĠC ord a X 5 0 0 Name ? Ġ= Ġrpc Info Map [ operator From ]?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnode Rpc Connection . get Rpc Connection ( it ). proxy . node Info (). legal Id entities . first (). name OrNull () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġrpc Info Map [ operator To ]?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġproxy : ĠC ord a RP CO ps Ġ= Ġnode Rpc Connection . get Rpc Connection ( it ). proxy ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġret Ġ= Ġperform Transfer From Flow ( number , Ġfrom Operator Name !! , Ġproxy ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠNumber DTO . from Model ( operator To , Ġret . state . data . number , ĠĠ 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn ĠNumber DTO . from Model ( operator To , Ġ"", Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġquery All State ( cord a RP CO ps : ĠC ord a RP CO ps ): ĠList < State And Ref < Number State >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcriteria Ġ= ĠQuery Criteria . Vault Query Criteria ( Vault . State Status . UN CON SU MED ) ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġc ord a RP CO ps . vault Query By Criteria ( criteria , ĠNumber State :: class . java ) ĊĠĠĠĠĠĠĠ Ġreturn Ġresults . states . filter { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġit . state . data . curr Operator Ġ== Ġc ord a RP CO ps . node Info (). legal Id entities . first () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}. toList () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġquery State By ( number : ĠString , Ġc ord a RP CO ps : ĠC ord a RP CO ps ): ĠState And Ref < Number State > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcriteria Ġ= ĠQuery Criteria . Vault Query Criteria ( Vault . State Status . UN CON SU MED ) ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġc ord a RP CO ps . vault Query By Criteria ( criteria , ĠNumber State :: class . java ) ĊĠĠĠĠĠĠĠ Ġreturn Ġresults . states . stream () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter { it . state . data . number Ġ== Ġnumber Ġ&& Ġit . state . data . curr Operator Ġ== Ġc ord a RP CO ps . node Info (). legal Id entities . first ()} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Any () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. orElse ( null ) Ġ?: Ġthrow ĠFlow Exception (" Can Ġnot Ġfind Ġthis Ġnumber Ġbelongs Ġto Ġthe Ġthis Ġparty .") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġperform Access Flow ( number : ĠString , Ġc ord a RP CO ps : ĠC ord a RP CO ps ): ĠState And Ref < Number State > Ġ{ ĊĠĠĠĠĠĠĠ Ġc ord a RP CO ps . start Tracked Flow ( Number Access Flow :: Init iator , Ġnumber ). returnValue . get OrThrow () ĊĠĠĠĠĠĠĠ Ġreturn Ġquery State By ( number , Ġc ord a RP CO ps ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġperform Transfer From Flow ( number : ĠString , Ġparty Name : ĠC ord a X 5 0 0 Name , Ġc ord a RP CO ps : ĠC ord a RP CO ps ): ĠState And Ref < Number State > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġother Party Ġ= Ġc ord a RP CO ps . well Known Party From X 5 0 0 Name ( party Name ) Ġ?: Ġthrow ĠFlow Exception (" Can Ġnot Ġfind Ġthis Ġparty .") ĊĠĠĠĠĠĠĠ Ġc ord a RP CO ps . start Tracked Flow ( Number Transfer From Flow :: Init iator , Ġnumber , Ġother Party ). returnValue . get OrThrow () ĊĠĠĠĠĠĠĠ Ġreturn Ġquery State By ( number , Ġc ord a RP CO ps ) ĊĠĠĠ Ġ} Ċ } Ċ