| Samples > Rule Studio Authoring Extensions > How to Populate a BOM Domain from a Data Source |
How to Populate a BOM Domain from a Data Source |
PREVIOUS NEXT |
This sample shows how to synchronize a set of BOM domain items with values stored in a database. It also demonstrates a basic use of the valueinfo provider to populate the completion menu of a BOM member with items stored in a database, making rule editing immediately reactive to changes in the database.
Key features include:
valueinfo provider connection with a database for a BOM member
org.eclipse.ui.popupMenus
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 this sample.
To install the plug-in samples extension site:
<InstallDir>/studio/samples/eclipse folder and click OK.
To check that the Business Object Model Domain Populate Sample feature is enabled:
C:\ILOG\JRules\studio\samples\eclipse and check that Business Object Model Domain Populate Sample 1.0.0. is listed.
To import the bomdomainpopulate sample:
ILOG Rule Studio Samples and Tutorials.
samples > authoring > bomdomainpopulate.
| Note |
| Before trying to start the database server, make sure that port 1527 is open, otherwise the sample might not run correctly. |
To start the local Derby database server:
Java Application > bomdomainpopulate-StartDatabase launcher.
To populate the database table:
Java Application > bomdomainpopulate-CreateAndPopulateTable launcher.
Note that there is no execution layer as such on the rule project attached to this sample, because the aim of the sample is to show you how to load the domain from a data source.
To run the sample:
bomdomainpopulate-rules project.
value(String) `CompanyX' is incorrect. This is an expected error and we will fix it later.
bom folder, double-click the domains BOM entry to open it in the BOM Editor and edit the trade.CurrencyType virtual class.
trade.MessageType virtual class and remove its static references and members.
BlackListedStocks and INAPPROPRIATE_CUSTOMER) are restored from the database into the MessageType domain definition, together with their corresponding verbalization and translation.
To synchronize your domain classes using the dynamic values from the table:
CheckOrder.OrderType rule in the Rule Editor.
CompanyX" (including the quotes) from the condition part of the rule.
is), press CTRL+SPACE to display the completion menu.
To update your domain and handle deprecation of certain items:
bomdomainpopulate-ModifyTable launch configuration.
trade.CurrencyType virtual class in the BOM Editor and click the Synchronize hyperlink to synchronize its domain once more.
CheckOrder.OrderType rule again in the Rule Editor. Delete the company name you entered (including the quotes) from the condition part of the rule.
is), try the different completion modes (CTRL+SPACE, CTRL+SHIFT+SPACE) to see the new entries in the completion menu for the stock value.
bomdomainpopulate-CreateAndPopulateTable launch configuration.
CurrencyType virtual class removes the deprecation property on the AUSDOLLAR item, but adds it to Pound, JPYen, and PRCRMB.
CheckOrder.OrderType rule, the completion menu for the stock name takes into account the original values that were just reset in the database.
To customize your development environment:
domains BOM entry in the Rule Explorer and click BOM Entry > Contribution from bomdomainpopulate Sample.
To display the source code of the bomdomainpopulate sample plug-in:
External Plug-ins and Fragments and click Next.
ilog.rules.studio.samples.bomdomainpopulate plug-in (be careful not to select ilog.rules.studio.samples.bomdomainpopulate.source), then click Add.
ilog.rules.studio.samples.bomdomainpopulate.actions.UpdateBomDomainAction.java.
UpdateBomDomainAction class.
The update of the BOM domain is performed through a common class located in the sample plug-in code:
ilog.rules.studio.model.bomDomainValueProviders, which implements ilog.rules.vocabulary.model.bom.IlrBOMDomainValueProvider. This class is connected to the extension point ilog.rules.studio.model.bomDomainValueProviders, declared in the plugin.xml file of the sample plug-in. It delegates most of its implementation to the ilog.rules.studio.samples.bomdomainpopulate.DataBaseDomainHelper class.
The connection of a static reference domain with the domain provider declared in the sample plug-in is done by setting the custom property domainValueProviderName to derbyDataBaseDomainProvider.
The database connection parameters are defined in the file: ilog.rules.samples.bomdomainpopulate/data/database.properties
The table and column mappings for each domain class are defined in the file: ilog.rules.samples.bomdomainpopulate/data/mapping.properties.
The syntax of this mapping property file is as follows:
<fullyqualifiedname>.table=<tableName> <fullyqualifiedname>.itemname=<nameColumn> <fullyqualifiedname>.itemverbalization=<verbalizationColumn> <fullyqualifiedname>.itemtranslation=<translationColumn>
In the domains BOM entry of the bomdomainpopulate sample, each domain class is a BOM virtual class that maps to the java.lang.String execution class. Hence, in the database, the BOM to XOM translation defined in the translationColumn of each class is of the form return <string>;.
In the plug-in code, a simple model has been implemented in the package ilog.rules.studio.samples.bomdomainpopulate.stock. This model is updated and accessed through the class ilog.rules.studio.samples.bomdomainpopulate.stock.StockValueInfo, defined in the sample plug-in.
The StockValueInfo class delegates the translation, completion proposal and checking features of the Intellirule Editor to the StockValueTranslator, StockValueProvider and StockValueChecker classes, which are all defined in the ilog.rules.studio.samples.bomdomainpopulate.stock package.
The stock model is updated at each completion request triggered by either the CTRL+SPACE, or CTRL+SHIFT+SPACE combination. A safer or smarter approach might be to perform the model update in a specific thread, on a timer-based basis.
The Java part of this plug-in code is less generic and only addresses the completion of the trade.Order.stock attribute, defined in the model BOM entry. The connection with the value info plug-in contribution is performed using the custom property valueInfo which is set to ilog.rules.studio.samples.bomdomainpopulate.Stock.
This sample also illustrates the use of a custom user interface contribution, visible when right clicking on a BOM entry in the Rule Explorer. Selecting BOM Entry > Contribution from bomdomainpopulate Sample in the context menu displays a simple message dialog.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |