/**************************************************************** * Ċ Ġ* ĠGrid n ine ĠAB Ġhttp :// www . grid n ine . com Ċ Ġ* ĠProject : Ġj tasks Ċ Ġ***************************************************************** / Ċ package Ġcom . grid n ine . j tasks . server . core . timer . rest Ċ Ċ import Ġcom . grid n ine . jasmine . common . core . model . L 1 0 n Message Ċ import Ġcom . grid n ine . jasmine . common . core . model . Xe ption Ċ import Ġcom . grid n ine . jasmine . common . core . storage . Storage Ċ import Ġcom . grid n ine . jasmine . common . core . storage . search Query Ċ import Ġcom . grid n ine . jasmine . common . core . utils . Auth Utils Ċ import Ġcom . grid n ine . jasmine . server . core . rest . Rest Handler Ċ import Ġcom . grid n ine . jasmine . server . core . rest . Rest Operation Context Ċ import Ġcom . grid n ine . j tasks . common . core . model . domain . Timer Record Ċ import Ġcom . grid n ine . j tasks . common . core . model . domain . Timer Status Ċ import Ġcom . grid n ine . j tasks . common . core . model . domain . User Account Index Ċ import Ġcom . grid n ine . j tasks . common . core . model . rest . Start Timer Record Request Ċ import Ġcom . grid n ine . j tasks . common . core . model . rest . Start Timer Record Response Ċ import Ġjava . time . Duration Ċ import Ġjava . time . LocalDate Ċ import Ġjava . time . LocalDateTime Ċ Ċ class ĠStart Timer Record Rest Handler : Rest Handler < Start Timer Record Request , ĠStart Timer Record Response > Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġservice ( request : ĠStart Timer Record Request , Ġctx : ĠRest Operation Context ): ĠStart Timer Record Response Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrecord Ġ= ĠStorage . get (). load Asset ( Timer Record :: class , Ġrequest . timer Uid ) !! ĊĠĠĠĠĠĠĠ Ġif ( record . date Ġ!= ĠLocalDate . now ()){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠX e ption . for End User ( L 1 0 n Message (" Ð¼Ð¾Ð¶ Ð½Ð¾ ĠÐ²ÑĭÐ± ÑĢ Ð°ÑĤÑĮ ĠÑĤÐ¾Ð»ÑĮÐºÐ¾ ĠÑĤ Ð°Ð¹ Ð¼ ÐµÑĢ ĠÐ·Ð° ĠÑĤÐµÐº ÑĥÑī ÑĥÑİ ĠÐ´ Ð°ÑĤ Ñĥ "), Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġcurrent Task Ġ= Ġfind Current Running Task () ĊĠĠĠĠĠĠĠ Ġif ( current Task Ġ!= Ġnull ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( current Task . uid Ġ== Ġrequest . timer Uid ){ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġcreate Response ( current Task ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstop Task ( current Task ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġrecord . last Started Ġ= ĠLocalDateTime . now () ĊĠĠĠĠĠĠĠ Ġrecord . status Ġ= ĠTimer Status . STARTED ĊĠĠĠĠĠĠĠ ĠStorage . get (). save Asset ( record , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġreturn Ġcreate Response ( record ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Response ( record : ĠTimer Record ): ĠStart Timer Record Response Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠStart Timer Record Response (). also Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . committed Time Ġ= Ġrecord . committed Time !! ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . last Started Ġ= Ġrecord . last Started ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . task Key Ġ= record . task . toString () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . task Title Ġ= Ġrecord . task Name !! ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . task Uid Ġ= Ġrecord . task !!. uid ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġcompanion Ġobject { ĊĠĠĠĠĠĠĠ Ġfun Ġstop Task ( current Task : ĠTimer Record ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Task . status Ġ= ĠTimer Status . STOP PED ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif ( current Task . last Started Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Task . committed Time Ġ= Ġ Ġcurrent Task . committed Time !! + ĠDuration . between Ġ( current Task . last Started !! , ĠLocalDateTime . now ()). to Seconds (). toInt () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Task . last Started Ġ= Ġnull ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStorage . get (). save Asset ( current Task , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfun Ġfind Current Running Task (): Timer Record ? { ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġquery Ġ= Ġsearch Query Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwhere Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġeq ( Timer Record . date Property , ĠLocalDate . now ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġeq ( Timer Record . status Property , ĠTimer Status . STARTED ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġeq ( Timer Record . assign ee Property , ĠStorage . get (). find Unique Document Reference ( User Account Index :: class , ĠUser Account Index . login Property , ĠAuth Utils . getCurrent User ()) !! ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrecords Ġ= ĠStorage . get (). search Assets ( Timer Record :: class , Ġquery , Ġtrue ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif ( records . isEmpty ()) Ġnull Ġelse Ġrecords . first () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }