Introduction:
A Decision Table is an alternative way of declaration of Business rule. Decision table presents multiple business rules with conditions and actions presented in a tabular format. When many rule combinations are needed for property values, we can use decision table to create a set of rules.
This article demonstrates how to select carrier value depends on the fulfillment price using Decision Table in Business Rule. Follow the below steps to implement Decision table in SOA application.
- Create a SOA application with SOA project. Click on File -> New -> Application and select SOA Application from Applications Enter application name DecisionTableBRApplication
- Click on Next and enter project name DecisionTableBRDemo
- Click on Next and select composite type as Composite With Business Rule
- Click on Finish and Create Business Rule wizard will open. Enter business rule name as CarrierRule.
- Create input and output parameters. Click on green plus icon and select Input Parameter
- Select Input value from fulfillment.xsd. Import fulfillment.xsd file in the project and select fulfillment as input value. Uncheck the check box Maintain original directory structure for imported files.
- Select output value from fulfillment.xsd. Select CarrierSelection as output value
- Now Create Business Rule wizard will look like below screenshot
- Click on OK and CarrierRule.rule file will be created. Navigate to Facts tab and select the checkbox in the visible column for FulfillmentType andA�CarrierSelection.
- Go to Value Sets tab and CarrierValue is created automatically
- Navigate to Rule Set tab. Click on green plus icon beside Rule Set and create new rule set. Now create rules under rule set. Click on green plus icon in Decision Tables
- Below window will open
- Click on insert condition and select total from FulfillmentType
- Click on pencil icon (Edit Value Set)A�beside the Local Range Value Set.
- Edit the value set as per the below screenshot
- Click on icon A�and from the list select Split Table option
- Condition part of the Decision table will look like below screenshot
- Click on insert action and select assert new
- Select CarrierSelection in the Facts and select carrier as property
- Click on OK
- Select carrier value against each row in fulfillment type. Click on box below the check box in R1 column for selecting carrier value. Select NONE as carrier value in R1, USPS in R2, UPS in R3 and FED_EX in R4 like the below screenshot
- One more action can be inserted against each condition according to business requirement. Click on assert new CarrierSelection and select insert after -> assert new. Another action will be inserted after the first one.
- Save the project. Select BPEL process from component palette and drag and drop it in the component lane
- Create BPEL Process wizard will open and enter BPEL process name. Select template type as Asynchronous BPEL Process and except default input and output value
- Connect BPEL process and Business rule
- Create a variable in BPEL process to hold the reply from the Business Rule. Click on variable icon in the main scope.
- Click on green plus icon to create new variable
- Enter variable name CarrierVar and select variable type as string.
- Double click on BPEL process to open the process. Select Business Rule from SOA Components and drag and drop it in between receiveInput and callbackClient
- Double click on Rule1 and select CarrierRule as Dictionary. Service and Operation will be selected automatically based on the value of Dictionary.
- Create input fact and output fact . Click on green plus icon in the Assign input Facts Select input payload of BPEL process in the From part and select total in the To part as per the below screenshot
- Navigate to Assign Output Facts tab and create new output fact. Select CarrierValue from dsOut payload in the From part and select CarrierVar variable in the To part
- Drag and drop IF activity below the Business Rule. Add three more elseif conditions in the IF activity and delete the else part
- Add conditions in each IF Write condition in the expression builder of IF condition like below screenshot
- Add the below conditions in the rest of the IF conditions$inputVariable.payload/client:input > 100 and $inputVariable.payload/client:input < 500
$inputVariable.payload/client:input > 500 and $inputVariable.payload/client:input < 1000
$inputVariable.payload/client:input >= 1000 - Select Assign activity from Basic Activities and drag and drop it in each IF section
- Double click on Assign activity and map the output payload with BPEL variable
- Do the same for the other three assign activities.
- Now the BPEL process will look like below screenshot
- Deploy the project and test the project in Enterprise Manager Console
- Enter 200 in the input payload and click on Test Web Service
- Output should be USPS. Click on Launch Flow Trace to check the output value. Click on DecisionTableBPELProcess
- Go to Audit Trail tab and click on View Payload after callback client
- Check the result
- You can visualize the whole process flow in the Flow tab. Here the input amount was 200, so the second If condition is selected.
Test the project with different input values and check the output payload. In this example carrier value is selected based on the rules in the Decision Table. Business user can change the rule in SOA Composer (http://localhost:7101/soa/composer)