1

I am new to drools, I would like to know how to sort a collection based on two properties of an object. The below objects are stored in a collection.

class Schedule{
  private String datePlan;
  private String orderNumber;
  //more fields
}

I tried by configuring the below rule but seems like there is an issue.

rule "ORDER RULE"
    dialect "java"
    when        
        // OrderBy DatePlan asc, OrderNo asc
        not Schedule(planYearMonth == $schedule.planYearMonth,
                            carSeries == $schedule.carSeries,
                            porCode == $schedule.porCode,
                            productionFamilyCode == $schedule.productionFamilyCode,
                            endItemModelCode == $schedule.endItemModelCode,
                            endItemColorCode == $schedule.endItemColorCode,
                            datePlan < $schedule.datePlan || 
                            orderNumber< $schedule.orderNumber))            

    then        

        retract($order);        
        retract($schedule);

end

The below logic is to store Orders & Schedules

rule "insert Orders"    
    when
        $inlist         : OrderList( $inIdx : size > 0)
    then
        for (int i=0; i < $inIdx; i++){
            Order order = (Order)$inlist.get(i);
            insert(order);
        }
        retract($inlist);

end


rule "insert Schedules" 
    when
        $inlist         : ScheduleList( $inIdx : size > 0)
    then
        for (int i=0; i < $inIdx; i++){
            Schedule schedule = (Schedule)$inlist.get(i);
            insert(schedule);
        }
        retract($inlist);

end
  • Where do you declare `$schedule` and `$order` ? Your rule basically says "When there is no schedule in working memory that meets these conditions, then remove $order and $schedule from working memory." That sounds nothing like what you're asking about. – Roddy of the Frozen Peas Jan 23 '20 at 05:51
  • Thanks Roddy for replying, I editied the question above please take a look. – user12757795 Jan 24 '20 at 07:10
  • Ok so you've got a collection of Schedule and Order objects in working memory, but I still don't see where you declare the $schedule or $order _variables_ in your initial rule. – Roddy of the Frozen Peas Jan 24 '20 at 15:23

0 Answers0