0

Here is my rule

rule "Multiple bookings via same mobile"
    when
        (stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
        $travellerCount :Number() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
        init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet();),
        action(
        for(Object bookingSummary : $bookingSummaryDtoList)
        {

            if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
            {   
                String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
                Set<String> finalDuplicateSet=MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet);
                count=count+1;
            }
        }
        ),
        result( new Integer(count)))
    then
        //some action to be taken here
        System.out.println($travellerCount);
end

How do I return the set

finalDuplicateSet

from the accumulate in place of count, I don't want to use any global variables or static variables in my java class also. can this be done or do I need to follow some other approach?

Yatin
  • 727
  • 1
  • 9
  • 40

1 Answers1

0

Hope this code Help you in getting what you want :

rule "Multiple bookings via same mobile"
    when
        (stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
        $duplicateTravellerList :List() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
        init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet(); List<String> finalDuplicateSet=new ArrayList();),
        action(
        for(Object bookingSummary : $bookingSummaryDtoList)
        {

            if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
            {   
                String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
                finalDuplicateSet.add(MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet));
                count=count+1;
            }
        }
        ),
        result( new ArrayList(finalDuplicateSet)))
    then
        //some action to be taken here
        System.out.println($duplicateTravellerList);
end
Prog_G
  • 1,539
  • 1
  • 8
  • 22
  • This doesn't work, I have already tries this. here is the error text=Rule Compilation error finalDuplicateList cannot be resolved to a variable – Yatin Aug 07 '18 at 08:27
  • @Yatin Have you added finalDuplicateSet inside init statement? – Prog_G Aug 07 '18 at 11:50
  • Thanks @Prog_G I was making a very silly mistake, I was directly returning the object in the result like result(finalDuplicateSet) assuming that only primitives would have to be returned after boxing (as I was doing for int type variable count result( new Integer(count)))) but this is something drool specific. Thanks for the help – Yatin Aug 08 '18 at 11:11