Tip:
Highlight text to annotate it
X
Corticon makes it easy to create and update
complex business rules that are deployed as web services.
Let's see how to model a rule based on a condition, and test the execution of that rule in our
development environment. Our scenario involves grocery store checkout
computers. The law requires the grocery store to check the age of any customer purchasing
liquor. This video demonstrates how to create a rule that detects when a customer is purchasing
liquor and reminds the clerk to check the customer's ID.
A good first step when creating a rule is to model the entities, attributes, and associations.
This UML diagram shows the model we will use for the grocery store project.
In Corticon Studio, I created a Corticon Project and defined the data model as a Corticon Vocabulary.
When we expand the Customer entity, notice how the associations imply a hierarchy:
• A customer has a preferredCard. • A customer has a shoppingCart.
• A customer's shopping cart has Items. To handle the case where a customer tries
to purchase liquor, let's create a rulesheet from the menu command.
We name the file checks, then go Next. We choose our vocabulary file name, groceryStore.ecore,
and then Finish We choose the advanced view so we can define
the Scope section of the Rulesheet .
Scope is a powerful and important concept. It helps us tell the Corticon rule engine
which data to use when evaluating and executing rules
We drag the Customer to the Scope area.
Then we drag the ShoppingCart association within the customer, and drop it on the Customer
in the rulesheet. We want the system to process not just any shopping cart, but this customers'
shopping cart.
We open the ShoppingCart's alias entry and assign it the alias currentCart.
Now let's do the same for items in a shopping cart, and assign it the alias items.
These aliases will be used in our rules. We will need aliases in our rules when we start
to use collection operators. Our first test is to see if we have items
from the liquor department, code 291. We determine that from the bar-code so we need to bring
the bar-code and item attributes into our scope.
Now we drag the scoped department to an Actions line.
We edit the line to add 'equals the department portion of the barcode'
Specifically "= items.barCode.substring(4,6)" Then we check the column 0 checkbox to show
that this is a non-conditional rule -- it always applies.
We need to see if any items came from department 291, Liquor.
Since we only need one alert per checkout transaction, we use a collection operator
which will evaluate once per collection, and not once per item.
We add a Condition. The simplest test says if there is any item code is liquor department,
the test is true. Our collection test is
items -> exists(items.department='291') and then T in column 1
So what is the action? We check the customer's ID. Enter currentCart.checkID, and in column
1, enter T. We add a warning statement that will post
on the clerk's screen saying that the clerk must check the ID.
Time for a test. We will create a ruletest to try our rulesheet .
We drag the entities and attributes we are using into the test and then add test data.
As we will test two items, drag the Customer's ShoppingCart's Item again to the Ruletest's
Input column, and then drop on the ShoppingCart. A second item is created for the test.
Double-click each attribute of the items, and then use the entry box to enter the test
data Note that we do not enter the department.
Our rule will get it from the barcode. There!
Choose the menu command Ruletest > Run All Tests.
Our Condition/Action rule works! We change the department from 291 to 290 and
test again. No check. Correct! That concludes our look at how to create and
test a rule.