Drools - Exercise Solutions

From Training Material
Jump to navigation Jump to search


Advanced Part 2

Exercise 3 - Sorting

 rule "Sample"
 when 
  $e : Emp()
  not Emp(sal < $e.sal)
 then    
   System.out.println($e.name + " " + $e.sal)
   retract($e)
 end

Exercise 30

  • /
declare MinSalaryByMgr
   mgr : Number
   minSal : Number
end
rule "Sample"
when
   e1:Emp(mgr:mgr)
   not MinSalaryByMgr(e1.mgr == mgr)
   accumulate(e :Emp(mgr==e1.mgr),min:min(e.sal))
then    
    System.out.println(e1.mgr + "\t" +  min  )
    insert(new MinSalaryByMgr(e1.mgr,min))
end