Drools rule "not exists"

Nigel Wu picture Nigel Wu · Mar 20, 2012 · Viewed 14k times · Source

I'm using JBoss Drools to write some business rules. I got a problem on the "not exists" rule.Here is my code.

rule "ATL 27R-A12 Subfleet A319-100 Departure configuration list has flap 1"
    salience 20
    no-loop true
    when
        AircraftConfig(aircraftType=="A319-100")
        RunwayInfo(airport3lCode== "ATL", runwayId == "27R-A12" )
        not (exists (DepartureConfiguration( flap == 1 )))
    then
        throw new RuleNotMatchException("The configurations do not match the rule of this runway.");
end

My facts contains:An AircraftConfig, an RunwayInfo and several DepartureConfigurations. I want to fire the rule when there are no DepartureConfiguration which flap=1. I mean, if there are three DepartureConfigurations, one of them has the flap=1, the others are flap=2 or flap=3, then this rule will not fire. How could I make this work?

Answer

mike9322 picture mike9322 · Mar 20, 2012

The keyword for checking for the non-existence of a fact is not, not not exists. Change the last line of your condition to:

not DepartureConfiguration( flap == 1 )