package Ġch . max ant . k dc . mf . partners . control Ċ Ċ import Ġch . max ant . k dc . mf . library . Message Builder Ċ import Ġch . max ant . k dc . mf . partners . adapter . Organ isation Adapter Ċ import Ġch . max ant . k dc . mf . partners . boundary . Create Partner Relationship Command Ċ import Ġch . max ant . k dc . mf . partners . entity . Address Entity Ċ import Ġch . max ant . k dc . mf . partners . entity . Address Type Ċ import Ġch . max ant . k dc . mf . partners . entity . Partner Relationship Entity Ċ import Ġch . max ant . k dc . mf . partners . entity . Role Ċ import Ġorg . eclipse . micro profile . metrics . Metric Units Ċ import Ġorg . eclipse . micro profile . metrics . annotation . Timed Ċ import Ġorg . eclipse . micro profile . op entr acing . Tr aced Ċ import Ġorg . eclipse . micro profile . reactive . messaging . Channel Ċ import Ġorg . eclipse . micro profile . reactive . messaging . Emitter Ċ import Ġorg . eclipse . micro profile . rest . client . inject . RestClient Ċ import Ġorg . jboss . logging . Logger Ċ import Ġjava . util .* Ċ import Ġjavax . enterprise . context . Application Scoped Ċ import Ġjavax . enterprise . event . Ob serves Ċ import Ġjavax . enterprise . event . Transaction Phase Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . persistence . EntityManager Ċ import Ġjavax . transaction . Transactional Ċ import Ġjavax . validation . ValidationException Ċ Ċ @ Application Scoped Ċ @ SuppressWarnings (" unused ") Ċ class ĠPartner Service ( ĊĠĠĠĠĠĠĠ Ġ@ Inject ĊĠĠĠĠĠĠĠ Ġvar Ġem : ĠEntity Manager , ĊĊĠĠĠĠĠĠĠ Ġ@ Inject ĊĠĠĠĠĠĠĠ Ġvar Ġmessage Builder : ĠMessage Builder Ċ ) Ġ{ ĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġ@ RestClient Ġ// Ġb izar re ly Ġthis Ġdoesnt Ġwork Ġwith Ġconstructor Ġinjection ĊĠĠĠ Ġlateinit Ġvar Ġorganisation Adapter : ĠOrgan isation Adapter ĊĊĠĠĠ Ġ@ Inject Ġ// Ġthis Ġdoesnt Ġappear Ġto Ġwork Ġin Ġthe Ġconstructor ĊĠĠĠ Ġ@ Channel (" partners - out ") ĊĠĠĠ Ġlateinit Ġvar Ġpart ners Out : ĠEmit ter < String > ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpartner Relationship Event : Ġjavax . enterprise . event . Event < Partner Relationship Entity > ĊĊĠĠĠ Ġprivate Ġval Ġlog Ġ= ĠLogger . getLogger ( this . java Class ) ĊĊĠĠĠ Ġ@ Transactional ĊĠĠĠ Ġ@ Timed ( unit Ġ= ĠMetric Units . MILLISECONDS ) ĊĠĠĠ Ġ@ Tr aced ĊĠĠĠ Ġfun Ġcreate Relationship ( command : ĠCreate Partner Relationship Command ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlog . info (" creating Ġa Ġpartner Ġrelationship : Ġ$ command ") ĊĊĠĠĠĠĠĠĠ Ġval Ġrelationships Ġ= Ġmutable ListOf < Partner Relationship Entity >() ĊĊĠĠĠĠĠĠĠ Ġrelationships . add ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPartner Relationship Entity ( UUID . randomUUID (), Ġcommand . partner Id , Ġcommand . foreign Id , Ġcommand . start , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcommand . end , Ġcommand . role )) ĊĠĠĠĠĠĠĠ Ġcommand . additional Relationship sTo Create . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( it Ġ== ĠRole . SAL ES _ REP ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlog . info (" adding Ġsales Ġrep Ġrelationship ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprimary Address Ġ= ĠAddress Entity . Queries ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. select By Partner Id ( em , Ġcommand . partner Id ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. find Ġ{ Ġaddress Ġ-> Ġaddress . type Ġ== ĠAddress Type . PRIMARY Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠPartner Has No Primary Address ValidationException ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Partner Ġ${ command . partner Id } Ġhas Ġno Ġprimary Ġaddress Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" and Ġso Ġno Ġsales Ġrep Ġcan Ġbe Ġselected ") ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsales Rep Ġ= Ġorganisation Adapter . get Staff By Role And PostCode ( Role . SAL ES _ REP , Ġprimary Address . postcode ) ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrelationships . add ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPartner Relationship Entity ( UUID . randomUUID (), Ġsales Rep . partner Id , Ġcommand . foreign Id , Ġcommand . start , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcommand . end , Ġit )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġthrow ĠIllegalArgumentException (" unexpected Ġrole Ġ$ it ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġlog . info (" pers isting Ġrelationships ") ĊĠĠĠĠĠĠĠ Ġrelationships . forEach Ġ{ Ġem . persist ( it ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġrelationships . forEach Ġ{ Ġsend Partner Relationship Changed Event ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Tr aced ĊĠĠĠ Ġprivate Ġfun Ġsend Partner Relationship Changed Event ( relationship : ĠPartner Relationship Entity ) Ġ{ ĊĠĠĠĠĠĠĠ Ġpartner Relationship Event . fire ( relationship ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ SuppressWarnings (" unused ") ĊĠĠĠ Ġ@ Tr aced ĊĠĠĠ Ġprivate Ġfun Ġsend (@ Ob serves ( during Ġ= ĠTransaction Phase . AFTER _ SUCCESS ) Ġrelationship : ĠPartner Relationship Entity ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpr ce Ġ= ĠPartner Relationship Changed Event ( relationship . partner Id , Ġrelationship . foreign Id , Ġrelationship . role ) ĊĠĠĠĠĠĠĠ Ġval Ġmsg Ġ= Ġmessage Builder . build ( relationship . foreign Id , Ġpr ce , Ġevent Ġ= Ġ" CHANGED _ PART NER _ REL ATION SHIP ") ĊĠĠĠĠĠĠĠ Ġpart ners Out . send ( msg ) Ġ// Ġrelationships Ġalso Ġgo Ġon Ġthe Ġsame Ġtopic Ġas Ġactual Ġpartner Ġchanges ĊĠĠĠ Ġ} Ċ } Ċ Ċ data Ġclass ĠPartner Relationship Changed Event ( ĊĠĠĠĠĠĠĠ Ġval Ġpartner Id : ĠUUID , ĊĠĠĠĠĠĠĠ Ġval Ġforeign Id : ĠString , ĊĠĠĠĠĠĠĠ Ġval Ġrole : ĠRole Ċ ) Ċ Ċ class ĠPartner Has No Primary Address ValidationException ( msg : ĠString ): ĠValidation Exception ( msg )