| Samples > Rule Studio Business Rule Management Extensions > How to Customize the Rule Model |
How to Customize the Rule Model |
PREVIOUS NEXT |
This sample shows how to extend the Business Rule model of ILOG Rule Studio with additional dynamic properties and dedicated editors. The editors are declared and implemented in an Eclipse plug-in.
Key features include:
This sample extends the Rule Studio API, and the required sample plug-ins are delivered as pre-deployed. If you have not already done so, you must install the samples extension site in Eclipse before running the sample.
To install the plug-in samples extension site:
<InstallDir>/studio/samples/eclipse folder.
To check that the Custom Rule Model Sample feature is enabled:
loanvalidation-rules project.
C:\ILOG\JRules\studio\samples\eclipse and check that Custom Rule Model Sample 1.0.0. is listed.
You can now import the sample project files. However, as this sample installs a custom rule model that replaces the default rule model, it is strongly recommended that you install and run it in a separate workspace to avoid any unwanted impact on other rule projects in your default workspace.
To import the sample project files:
ILOG Rule Studio > RuleModelExtension, change the Default extension to:
customrulemodel sample:
ILOG Rule Studio Samples and Tutorials then click Next.
brmanagement > customrulemodel.
To run the sample:
customrulemodel-rules project and open one of the rule project's rules. You will see that some new properties have been added in the Properties view.
data/rulestudiocustommodel.brmx. All the business rules inside the customrulemodel-rules rule project are of type ExtendedRule which extends the default type: ActionRule.
Enum and Hierarchy property types is defined in the model's data file data/rulestudiocustommodel.brdx located inside the rule project. For example, productionLevel items and authority node values are defined in this file.
ExtendedRule type's business rules using the new business rule assistant (New > Business Rule) by selecting ExtendedRule in the Type drop down list selector.
To display the source code of the customrulemodel sample plug-in:
External Plug-ins and Fragments and click Next.
ilog.rules.studio.samples.customrulemodel plug-in (be careful not to select ilog.rules.studio.samples.customrulemodel.source), then click Add.
Through code, this sample demonstrates how to define validators to check the content when Properties view's cells are edited.
There are two types of validators:
String property requestorEmail, to check if the string is a valid email address.
Integer properties minorVersion, majorVersion and patchLevel to check if the values are within bounds.
When a property is edited and its cell content does not match what is defined inside its validator, an error message is raised immediately in the Eclipse status bar in the bottom left corner of the application window.
In order to redefine the default cell editors used in the Properties view for our custom properties, we need to use an extension point provided by Rule Studio ilog.rules.studio.ui.propertyEditors.
RequestorMailCellEditor class, in the package ilog.rules.studio.samples.customrulemodel.editors, extends org.eclipse.jface.viewers.TextCellEditor and provides a validator to check if the cell content is an email address. The validator class needs to implement org.eclipse.jface.viewers.ICellEditorValidator.
In our example, RequestorMailCellEditor's MailValidator inner class is the validator that will be used.
The validator provides a method called isValid which takes a Java object as parameter and returns:
String containing an error message if the content is not validated.
null if the cell content is validated
You can try to edit the requestorEmail property of an Extended type rule to see the validator in action. If the cell content does not contain "@" or "." characters, error messages will be output to the Eclipse status bar in the bottom left corner of the application window.
We used the same technique to check if an integer is within bounds. ConstrainedIntegerCellEditor class, in the same package as RequestorMailCellEditor class, also extends TextCellEditor.
Some methods of TextCellEditor need to be redefined to work with integers: doGetValue and doSetValue.
In this example, we read the value of the boundaries from a property file: data/boundaries.properties. Boundaries are retrieved on a class name basis. For each class, values are set for:
These values are red inside the cell editor validator class. All our constrained properties: minorVersion, majorVersion and patchLevel have their implementation classes inheriting from ConstrainedIntegerCellEditor (abstract class).
You can add one of your own by creating an empty class extending ConstrainedIntegerCellEditor and by adding your lower and upper bound values inside the data/boundaries.properties file.
The CountryCellEditor class demonstrates how to dynamically change a list of possible values for a property. In our example, the drop down list displays the names of the countries but the value that is returned and persisted when an item is selected, is a country code.
We redefined createControl() in order to change the combo box default behaviors, and customized doGetValue(), doSetValue() and getItems() in order to populate and set the values we wanted.
CountryCellEditor retrieves its value from an xml file. The current list depends on another property: region.
In ilog.rules.studio.samples.customrulemodel.propertyextension.MyPropertyExtension which implements IlrPropertyExtension, we created a custom case in afterChange() in order to reset the territory (selected country code) when another region is selected.
The MyPropertyExtension class is also used to make a constraint on the date property effectiveDate. If the date does not match the predefined pattern, it can not be set and an error message is displayed in the status bar.
The ilog.rules.studio.samples.customrulemodel.propertyextension.MyInitialValue is a callback class that implements the IlrInitialValue interface. It is triggered when the expirationDate or the majorVersion properties are about to be set for a new artefact. The connection with these properties is specified in the plug-in.xml file of this sample:
<extension
id="ilog.rules.studio.samples.customrulemodel.initialValue"
point="ilog.rules.studio.model.initialValueCallbacks">
<initialValueCallback
id="BusinessRule.expirationDate"
callbackClass="ilog.rules.studio.samples.customrulemodel.propertyextension.MyInitialValue">
</initialValueCallback>
<initialValueCallback
id="ExtendedRule.majorVersion"
callbackClass="ilog.rules.studio.samples.customrulemodel.propertyextension.MyInitialValue">
</initialValueCallback>
</extension>
The extension point ilog.rules.studio.ui.propertyEditors is used to set the class associated to a rule model property.
For example:
<propertyEditor target="ExtendedRule.minorVersion"
cellEditorClass="ilog.rules.studio.samples.customrulemodel.editors.MinorVersionCellEditor"> </propertyEditor>
target references one property defined inside the rule model extension.
cellEditorClass references the class associated with the rule model property. This class needs to extend the abstract class org.eclipse.jface.viewers.CellEditor or one of its children.
The extension point ilog.rules.studio.ui.propertyExtensions is used to perform custom actions on the rule properties cell editor events. In our sample:
<propertyExtension propertyExtensionClass="ilog.rules.studio.samples.customrulemodel.propertyextension.
MyPropertyExtension"> </propertyExtension>
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |