0

I have to write a drool function on a list which has to do the following thing

  1. create a summation
  2. check whether the summation is greater than 100.

below is the drool rule I have created

    rule "001"   
when 
       $charge : MainClass(subList.size() > 0)
       $item   : SubListClass(number < 0) from  $charge.subOrderROList
       $total  : Number() from accumulate(SubListClass( $p : number ),sum( $p ) 
then
       int index = $charge.SubListClass.indexOf($item)+1;
    violations.error(kcontext, "ad", "ad.message", new String[]{String.valueOf(index),$item.getNumber().toString()},index);
   end` 

I am not able to check whether the $total is greater than 100

thanks

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
prashant s
  • 148
  • 1
  • 1
  • 9

1 Answers1

2

This would be correct if it were possible to obtain a sum > 100 by adding negative numbers. I have kept the constraints as they were in the Q, so change this as appropriate. Maybe number > 0?

rule "001"   
when 
  $charge: MainClass(subList.size() > 0)
  $total: Number( intValue > 100 )
          from accumulate( SubListClass($p: number < 0)
                           from  $charge.subOrderROList,
                           sum( $p ) )
then
laune
  • 31,114
  • 3
  • 29
  • 42