This sample demonstrates an order approval process which uses business rules to check whether the required conditions for approving an order are met.
To run this sample:
- Windows, Linux or Solaris operating system should exist.
- WSO2 BRS should be installed. To install the BRS, refer Installing the Product. This also includes installing Apache Ant as one of the Installation Prerequisites.
- WSO2 BRS should be started as described in Running the Product.
Sample Rule Definition
Rule 1 : An order for stocks of Company A is accepted only if the number of stocks is higher than 10.
Rule 2 : An order for stocks of Company B is accepted only if the stock price is higher than 100 $.
Rule 3 : An order for stocks of Company C is accepted only if the stock price is higher than 50 $ and the number of stocks is lower than 200.
There is one fact named
Customer Places and Order. OrderAccept and
OrderReject are used to capture the result of the service.
Rule Service Configuration (service.rsl)
Executing the sample
To execute the sample, run the
ant command from the
<PRODUCT_HOME>/samples/quotation.service directory to run the OrderApproval Service.
Deploying and testing the service
- Deploy the rule service through the BRS management console. You can follow either of the two methods:
- Bundle all artifacts in an .aar file and upload it (Rule Service -> Upload menu).
- Create using the Rule Service wizard UI (Rule Service -> Create menu).
The above steps are discussed in detail in section Exposing Rules as Services.
- After deployment, click on List under Services in the main tab of the management console. The service will appear in the Deployed Services page.
- Click OrderApproval to access the dashboard of the service.
- Click Try this service in the Client Operations widget of the dashboard to invoke the Try-it tool.
- Issue a request similar to the following in the OrderApprovalService window.
You would get the following response:
- Alternatively, you can use Generate Client link in the
Client Operationswidget of the dashboard to invoke the service. A client using generated stub codes is shown below where the codes were generated with the Unpacks the data binding classes check box checked.