/* Ċ Ġ* ĠCopyright Ġ 2 0 1 8 ĠNet flix , ĠInc . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . netflix . spin n aker . ke el . rest Ċ Ċ import Ġcom . netflix . spin n aker . ke el . api . Asset Ċ import Ġcom . netflix . spin n aker . ke el . api . Asset Name Ċ import Ġcom . netflix . spin n aker . ke el . events . Asset Event Ċ import Ġcom . netflix . spin n aker . ke el . events . Asset EventType . CREATE Ċ import Ġcom . netflix . spin n aker . ke el . events . Asset EventType . DELETE Ċ import Ġcom . netflix . spin n aker . ke el . events . Asset EventType . UPDATE Ċ import Ġcom . netflix . spin n aker . ke el . persistence . Asset Repository Ċ import Ġcom . netflix . spin n aker . ke el . persistence . NoSuch Asset Exception Ċ import Ġcom . netflix . spin n aker . ke el . persistence . get Ċ import Ġcom . netflix . spin n aker . ke el . yaml . APPLICATION _ YAML _ VALUE Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġorg . springframework . context . Application Event Publisher Ċ import Ġorg . springframework . http . HttpStatus . NOT _ FOUND Ċ import Ġorg . springframework . http . MediaType . APPLICATION _ JSON _ VALUE Ċ import Ġorg . springframework . web . bind . annotation . Delete Mapping Ċ import Ġorg . springframework . web . bind . annotation . ExceptionHandler Ċ import Ġorg . springframework . web . bind . annotation . GetMapping Ċ import Ġorg . springframework . web . bind . annotation . PathVariable Ċ import Ġorg . springframework . web . bind . annotation . PostMapping Ċ import Ġorg . springframework . web . bind . annotation . Put Mapping Ċ import Ġorg . springframework . web . bind . annotation . RequestBody Ċ import Ġorg . springframework . web . bind . annotation . RequestMapping Ċ import Ġorg . springframework . web . bind . annotation . ResponseStatus Ċ import Ġorg . springframework . web . bind . annotation . RestController Ċ Ċ @ RestController Ċ @ RequestMapping ( path Ġ= Ġ["/ assets "]) Ċ class ĠAsset Controller ( ĊĠ Ġprivate Ġval Ġpublisher : ĠApplication Event Publisher , ĊĠ Ġprivate Ġval Ġasset Repository : ĠAsset Repository Ċ ) Ġ{ ĊĊĠ Ġprivate Ġval Ġlog Ġby Ġlazy Ġ{ ĠLoggerFactory . getLogger ( java Class ) Ġ} ĊĊĠ Ġ@ PostMapping ( ĊĠĠĠ Ġconsume s Ġ= Ġ[ APPLICATION _ YAML _ VALUE , ĠAP PLICATION _ JSON _ VALUE ], ĊĠĠĠ Ġproduces Ġ= Ġ[ APPLICATION _ YAML _ VALUE , ĠAP PLICATION _ JSON _ VALUE ] ĊĠ Ġ) ĊĠ Ġfun Ġcreate (@ RequestBody Ġresource : ĠAsset < *> ): ĠAsset < *> Ġ{ ĊĠĠĠ Ġlog . info (" Creating : Ġ$ resource ") ĊĠĠĠ Ġpublisher . publish Event ( Asset Event ( CREATE , Ġresource )) ĊĠĠĠ Ġreturn Ġresource Ġ// ĠTODO : Ġafter Ġit 's Ġbeen Ġth ru Ġk 8 s ĊĠ Ġ} ĊĊĠ Ġ@ GetMapping ( ĊĠĠĠ Ġpath Ġ= Ġ[" /{ name } "], ĊĠĠĠ Ġproduces Ġ= Ġ[ APPLICATION _ YAML _ VALUE , ĠAP PLICATION _ JSON _ VALUE ] ĊĠ Ġ) ĊĠ Ġfun Ġget (@ PathVariable (" name ") Ġname : ĠAs setName ): ĠAsset < Any > Ġ{ ĊĠĠĠ Ġlog . info (" Getting : Ġ$ name ") ĊĠĠĠ Ġreturn Ġasset Repository . get ( name ) ĊĠ Ġ} ĊĊĠ Ġ@ Put Mapping ( ĊĠĠĠ Ġpath Ġ= Ġ[" /{ name } "], ĊĠĠĠ Ġproduces Ġ= Ġ[ APPLICATION _ YAML _ VALUE , ĠAP PLICATION _ JSON _ VALUE ] ĊĠ Ġ) ĊĠ Ġfun Ġupdate (@ PathVariable (" name ") Ġname : ĠAs setName , Ġ@ RequestBody Ġresource : ĠAsset < *> ): ĠAsset < *> Ġ{ ĊĠĠĠ Ġlog . info (" Updating : Ġ$ resource ") ĊĠĠĠ Ġpublisher . publish Event ( Asset Event ( UPDATE , Ġresource )) ĊĠĠĠ Ġreturn Ġresource Ġ// ĠTODO : Ġafter Ġit 's Ġbeen Ġth ru Ġk 8 s ĊĠ Ġ} ĊĊĠ Ġ@ Delete Mapping ( ĊĠĠĠ Ġpath Ġ= Ġ[" /{ name } "], ĊĠĠĠ Ġproduces Ġ= Ġ[ APPLICATION _ YAML _ VALUE , ĠAP PLICATION _ JSON _ VALUE ] ĊĠ Ġ) ĊĠ Ġfun Ġdelete (@ PathVariable (" name ") Ġname : ĠAs setName ): ĠAsset < *> Ġ{ ĊĠĠĠ Ġlog . info (" Deleting : Ġ$ name ") ĊĠĠĠ Ġval Ġresource Ġ= Ġasset Repository . get < Any >( name ) ĊĠĠĠ Ġpublisher . publish Event ( Asset Event ( DELETE , Ġresource )) ĊĠĠĠ Ġreturn Ġresource Ġ// ĠTODO : Ġafter Ġit 's Ġbeen Ġth ru Ġk 8 s ĊĠ Ġ} ĊĊĠ Ġ@ ExceptionHandler ( NoSuch Asset Exception :: class ) ĊĠ Ġ@ ResponseStatus ( NOT _ FOUND ) ĊĠ Ġfun Ġon NotFound ( e : ĠNoSuch Asset Exception ) Ġ{ ĊĠĠĠ Ġlog . error ( e . message ) ĊĠ Ġ} Ċ } Ċ