You import a Java™ project,
and create a rule project and a business object model (BOM).
About this task
In this tutorial, you follow a bottom-up approach
to creating a vocabulary in Rule
Designer.
This means that you use existing application objects as the basis
for your vocabulary. For this purpose, we have provided a Java project that models car rental concepts.
You do the following:
- Import the Java project
to be used as the execution object model.
- Create a rule project that references the XOM.
- Create a business object model (BOM) entry in the rule project
and verbalize it by default.
Note: If you have imported the answer projects
for the tutorial, close or delete them before importing the start
projects.
You start by importing the Java project into your Eclipse workspace:
- Open the Samples Console in the en_US (American English)
locale (see Running samples from the Samples Console).
- Import the Java project:
You use this Java project
as the XOM, which serves as the basis of the BOM in rule editing.
To
store and organize the BOM and rule artifacts, you need to create
a rule project.
- Switch to the Java perspective.
- On the File menu, click Import.
- In the Import wizard, open the General folder,
select Existing Projects into Workspace, and
then click Next.
- On the next page of the Import wizard, click Browse and
select carrental-xom from the shared directory:
<InstallDir>/studio/tutorials/shared
- Make sure that Copy projects into workspace is
checked, and click Finish.
The carrental-xom project
appears in the Package Explorer view.
- Create the rule project:
- On the File menu, click .
- In the New Project wizard, select Rule Project,
and then click Next.
- Under Decision Service Rule Projects, select Main
Rule Project, and then click Next.
- In the Project name field, type vocabulary-rules, and
then click Next.
- On the Main Rule Project References page, click Finish without
defining any references. Click Yes to open
the Rule perspective.
The main rule project vocabulary-rules now
appears in the Rule Explorer view. You can see that it contains a rules directory
for rule artifacts, a bom directory for BOM entries,
and directories for deployment, queries, resources,
and templates.
In this tutorial, you write the following rules:
Action
rule Loyalty.AwardLoyalty
if
the duration of the rental agreement is more than 20
then
make it true that the customer of the rental agreement is loyalty program member;
Action rule Eligibility.UnderAge
if
the age of the customer of the rental agreement is less than 18
then
make it true that the rental agreement is rejected;
display the message "The rental agreement is rejected";
Action rule BranchInfo
if
the state of the branch is one of { "Massachusetts" , "New Hampshire" }
then
display the message "The branch is in Massachusetts or New Hampshire" ;
Now you import the XOM in the main rule project.
- Import XOM:
- Select the vocabulary-rules project
in the Rule Explorer view.
- In the Decision Service Map, click Import
XOM.
- In the Import XOM wizard, make sure Java
execution object model is selected and click OK.
- In the Java Execution Object Model wizard, select carental-xom and
click OK.
Now you create a BOM entry and verbalize the elements
of the vocabulary that are required to make these rules. Verbalizing
is the process of associating terms and phrases with elements of the
BOM.
- Create the BOM entry:
- In the Rule Explorer view, right-click the rule project vocabulary-rules,
and click .
- In the New BOM Entry wizard, leave the default name model in the
Name field, select Create a BOM entry from a XOM, and
then click Next.
- On the BOM Entry page, click Browse XOM.
- In the Browse XOM dialog, select the Java project platform:carrental-xom,
and then click OK.
The Select classes field displays
the carrental package.
- In the Select classes field,
open the carrental package and select the classes Customer and RentalAgreement.
- Make sure the option Load getters and setters
as attributes is selected, and then click Next.
- On the BOM Verbalization page, make sure the options Getters, Setters,
and Static References are selected, and then
click Finish.
- In the Rule Explorer view, expand , and then double-click model.
The Outline view and the BOM Editor show the BOM model.
The
BOM contains warnings, that you can see in the Problems view:
The classes you added to the BOM entry include references
to classes that are not in the BOM entry. While you do not need to
verbalize all the members of these classes, the BOM entry still needs
to include them. You fix this problem in the next task of the tutorial.Before
you do so, take a minute to look at the default verbalization of the
classes in the BOM entry.
- Look at the default verbalization:
- In the BOM Editor, expand the carrental package
and double-click the class Customer.
On the Class page, in the Class Verbalization
section, you can see the verbalization of this class as the business
term customer.
- In the Members section of the Class page, double-click
the attribute firstName.
On the Member
page, in the Member Verbalization section, you can view the verbalization
of this attribute as the navigation phrase {first name} of {this}.
- On the Window menu, click .
In the Vocabulary
view, you can look at all your vocabulary elements.
Results
In the next task, you fix the warnings by updating
the BOM entry to include the missing classes, and verbalize new elements.