I have a following Facts domain ProposedFare and Fare.
The idea here is ProposedFare could be a competitor fare and from that create/clone/update Fare.
A rule can further update Fare which was already cloned.
And my drl is as follows:
dialect "mvel"
rule "Set Carrier Code to AA"
salience 100
when
$prf : ProposedFare()
then
Fare fare = new Fare();
fare.setCarrierCode("AA");
fare.setOrigin($prf.getOrigin());
fare.setDestination($prf.getDestination());
fare.setTariffNumber($prf.getTariffNumber());
fare.setFareClassCode($prf.getFareClassCode());
fare.setFootnoteCode("3B");
fare.setFareAmount($prf.getFareAmount());
fare.setCurrencyCode($prf.getCurrencyCode());
fare.setRoundTripIndicator($prf.getRoundTripIndicator());
insert(fare);
end
rule "Increase Fare Amount by double"
salience 99
when
$fare : Fare(origin=="ABC", destination=="XYZ")
then
modify($fare){
setFareAmount($fare.getFareAmount() * 2),
setFareClassCode("2X")
}
end
rule "Change Fare ClassCode"
salience 95
when
$prf : ProposedFare(origin=="ABC", destination=="XYZ")
then
Fare fare = new Fare();
fare.setCarrierCode($prf.getCarrierCode());
fare.setOrigin($prf.getOrigin());
fare.setDestination($prf.getDestination());
fare.setTariffNumber($prf.getTariffNumber());
fare.setFareClassCode("1X");
fare.setFootnoteCode($prf.getFootnoteCode());
fare.setFareAmount($prf.getFareAmount());
fare.setCurrencyCode($prf.getCurrencyCode());
fare.setRoundTripIndicator($prf.getRoundTripIndicator());
insert(fare);
end
rule "Change CarrierCode"
salience 90
when
$fare : Fare(origin=="ABC", destination=="XYZ", fareClassCode=="1X")
then
modify($fare){
setCarrierCode("AB")
}
end
For the new Fare that is inserted by salience 95, I do not want that fact to execute from rule 100, instead it should only execute rules where salience is < 95.
(Once new fact is inserted by any rule, only rules that have salience lower than that rule should be executed on that fact).
However, when I insert the new Fare at salience 95, it starts getting executed from very first rule.
insert(notupdate) all lower salience rules will be re-evaluated ... that's just how it works. If you're seeing something different, please provide a unit test/reproducer.not(Fare()). So as long as there's a Fare in working memory, the salience 100 rule won't fire.