This documentation is for WSO2 Business Rules Server 2.0.0.View documentation for the latest release.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Drools Rule File

Code Block
languagenone
titleorderApprovalRules.drl
package OrderApproval;

import samples.userguide.OrderAccept;
import samples.userguide.OrderReject;
import samples.userguide.PlaceOrder;

rule "Order Approval Rule" dialect "mvel" no-loop true salience 4

when
$placeOrder : PlaceOrder( ( symbol == "Company A" && quantity > 10 ) || ( symbol == "SUNCompany B" && price > 100 ) || ( symbol == "MSFTCompany C" && price > 50 && quantity < 200 ) )
then

OrderAccept orderAccept = new OrderAccept();
orderAccept.setMessage("Accepted order for: "+ $placeOrder.quantity + " stocks of "+
$placeOrder.symbol +" at$ " + $placeOrder.price);
insertLogical(orderAccept);

end

rule "Company A Order Deny Rule" dialect "mvel" no-loop true salience 3

when
not ( OrderAccept())
$placeOrder : PlaceOrder( symbol == "Company A" )
then
retract($placeOrder);
OrderReject orderReject = new OrderReject();
orderReject.setReason("An Order for stocks of Company A is accepted only if the number of stocks is higher than 10.");
insertLogical(orderReject);
end

rule "SUNCompany B Order Deny Rule" dialect "mvel" no-loop true salience 2
when
not ( OrderAccept())
$placeOrder : PlaceOrder( symbol == "SUNCompany B" )
then
retract($placeOrder);
OrderReject orderReject = new OrderReject();
orderReject.setReason("An Order for stocks of Company SUNB is accepted only if the stock price is higher than 100 $.");
insertLogical(orderReject);
end

rule "MSFTCompany C Order Deny Rule" dialect "mvel" no-loop true salience 1
when
not ( OrderAccept())
$placeOrder : PlaceOrder( symbol == "MSFTCompany C" )
then
retract($placeOrder);
OrderReject orderReject = new OrderReject();
orderReject.setReason("An Order for stocks of Company MSFTC is accepted only if the stock price is higher than 50 $ and the number of stocks is lower than 200.");
insertLogical(orderReject);
end