...
Rules
Rule 1: If the customer has bronze status, then the item costs five dollars.
Rule 2 : If the customer has silver status, then the item costs four dollars.
Rule 3 : If the customer has gold status, then the item costs three dollars.
Facts
There is one fact, which is "a fact named A customer made a get quote request
". Quotation
is used to capture the result of the rules execution.
Code Block | ||
---|---|---|
| ||
package samples.userguide; package samples.quotation; /** * Customer fact */ public class Customer { private String status; public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } } package samples.quotation; /** * Quotation result */ public class Quotation { private int price; public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } } |
Rule Service Configuration (service.rsl)
Code Block | ||
---|---|---|
| ||
<ruleService name="GetQuoteService" xmlns="http://wso2.org/carbon/rules" targetNamespace="http://com.test/quotation"> <ruleSet> <rule resourceType="regular" sourceType="inline"> <![CDATA[ package quotation import samples.quotation.Customer; import samples.quotation.Quotation; rule "Gold Customer" when Customer( status == "gold" ) then Quotation q = new Quotation(); q.setPrice(3); insertLogical(q); end rule "Silver Customer" when Customer( status == "silver" ) then Quotation q = new Quotation(); q.setPrice(4); insertLogical(q); end rule "Bronze Customer" when Customer( status == "bronze" ) then Quotation q = new Quotation(); q.setPrice(5); insertLogical(q); end ]]> </rule> </ruleSet> <operation name="getQuote"> <input wrapperElementName="placeCustomerDetail" namespace="http://com.test/placeCustomerDetail"> <fact elementName="customerDetail" namespace="http://com.test/placeCustomerDetail" type="samples.quotation.Customer"></fact> </input> <output wrapperElementName="placeCustomerDetailRespone" namespace="http://com.test/placeCustomerDetail"> <fact elementName="getQuotation" namespace="http://com.test/placeCustomerDetail" type="samples.quotation.Quotation"></fact> </output> </operation> </ruleService> |
...