package Ġcom . template Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . Unique Identifier Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . node . services . query By Ċ import Ġnet . cord a . core . node . services . vault . Query Criteria Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ import Ġjava . lang . IllegalStateException Ċ Ċ /** Ċ Ġ* ĠChange Ġthe Ġstatus Ġof Ġa Ġ[ M ilestone ] Ġin Ġa Ġ[ Job State ] Ġfrom Ġ[ M ilestone Status . COMPLETED ] Ġto Ġeither : Ċ Ġ* Ġ Ġ* Ġ[ M ilestone Status . STARTED ] Ġif Ġthe Ġ[ M ilestone ] Ġis Ġconsidered Ġincomplete Ġand Ġrequires Ġadditional Ġwork Ċ Ġ* Ġ Ġ* Ġ[ M ilestone Status . ACCEPT ED ] Ġif Ġthe Ġ[ M ilestone ] Ġis Ġconsidered Ġcomplete Ċ Ġ* Ċ Ġ* ĠShould Ġbe Ġrun Ġby Ġthe Ġdeveloper , Ġwho Ġperforms Ġthe Ġinspection . Ċ Ġ* Ċ Ġ* Ġ@ param Ġlinear Id Ġthe Ġ[ Job State ] Ġto Ġupdate . Ċ Ġ* Ġ@ param Ġmilestone Index Ġthe Ġindex Ġof Ġthe Ġ[ M ilestone ] Ġto Ġbe Ġupdated Ġin Ġthe Ġ[ Job State ]. Ċ Ġ*/ Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ class ĠAccept Or Reject Flow ( val Ġlinear Id : ĠUnique Identifier , Ġprivate Ġval Ġapproved : ĠBoolean , Ġprivate Ġval Ġmilestone Reference : ĠString ) Ġ: ĠFlow Logic < Unique Identifier >() Ġ{ ĊĊĠĠĠ Ġoverride Ġval Ġprogress Tracker Ġ= ĠProgress Tracker () ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠUnique Identifier Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġquery Criteria Ġ= ĠQuery Criteria . Linear State Query Criteria ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlinear Id Ġ= ĠlistOf ( linear Id )) ĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġservice Hub . vault Service . query By < Job State >( query Criteria ) ĊĠĠĠĠĠĠĠ Ġval Ġinput State And Ref Ġ= Ġresults . states . single OrNull () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠFlow Exception (" There Ġis Ġno ĠJob State Ġwith Ġlinear ĠID Ġ$ linear Id ") ĊĠĠĠĠĠĠĠ Ġval Ġinput State Ġ= Ġinput State And Ref . state . data ĊĊĠĠĠĠĠĠĠ Ġif Ġ( input State . developer Ġ!= Ġour Identity ) Ġthrow ĠIllegalStateException (" The Ġdeveloper Ġmust Ġstart Ġthis Ġflow .") ĊĊĠĠĠĠĠĠĠ Ġval Ġupdated M ilestones Ġ= Ġinput State . m ilestones . to Mutable List () ĊĊĠĠĠĠĠĠĠ Ġval Ġmilestone Index Ġ= Ġfind M ilestone ( updated M ilestones , Ġmilestone Reference ) ĊĊĠĠĠĠĠĠĠ Ġval Ġjob State Ġ= Ġif Ġ( approved ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġupdated M ilestones [ milestone Index ] Ġ= Ġupdated M ilestones [ milestone Index ]. copy ( status Ġ= ĠM ilestone Status . ACCEPT ED ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinput State . copy ( m ilestones Ġ= Ġupdated M ilestones ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġupdated M ilestones [ milestone Index ] Ġ= Ġupdated M ilestones [ milestone Index ]. copy ( status Ġ= ĠM ilestone Status . STARTED ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinput State . copy ( m ilestones Ġ= Ġupdated M ilestones ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġcommand Type Ġ= Ġif Ġ( approved ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠJob Contract . Commands . Accept M ilestone ( milestone Index ) ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠJob Contract . Commands . Reject M ilestone ( milestone Index ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġcommand Ġ= ĠCommand ( command Type , ĠlistOf ( our Identity . own ing Key )) ĊĊĠĠĠĠĠĠĠ Ġval Ġtransaction Builder Ġ= ĠTransaction Builder ( input State And Ref . state . not ary ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Input State ( input State And Ref ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Output State ( job State , ĠJob Contract . ID ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Command ( command ) ĊĊĠĠĠĠĠĠĠ Ġtransaction Builder . verify ( service Hub ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsigned Transaction Ġ= Ġservice Hub . sign Initial Transaction ( transaction Builder ) ĊĊĠĠĠĠĠĠĠ Ġsub Flow ( Final ity Flow ( signed Transaction )) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġjob State . linear Id ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfind M ilestone ( m ilestones Ġ: ĠList < M ilestone >, Ġmilestone Reference Ġ: Ġ ĠString ) Ġ: ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmilestone Result Ġ= Ġ Ġm ilestones . filter { Ġmilestone Ġ-> Ġmilestone . reference Ġ== Ġmilestone Reference Ġ} ĊĊĠĠĠĠĠĠĠ Ġif ( milestone Result . isEmpty ()){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalStateException (" Cannot Ġfind ĠM ilestone Ġwith Ġreference Ġ[ ". plus ( milestone Reference ). plus (" ] ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġm ilestones . indexOf ( milestone Result [ 0 ]) ĊĠĠĠ Ġ} Ċ }