Samples > Rule Studio Authoring Extensions > How to Populate a BOM Domain from a Data Source

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

Key features include:

Installing this Sample

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:

  1. Click Help > Software Updates > Manage Configuration.
  2. Click the Add an Extension Location link.
  3. Select the <InstallDir>/studio/samples/eclipse folder and click OK.
  4. If prompted to restart the Eclipse Workbench, click Yes.
  5. Eclipse shuts down and restarts.

To check that the Business Object Model Domain Populate Sample feature is enabled:

  1. Click Help > Software Updates > Manage Configuration.
  2. In the left pane of the Product Configuration page, expand 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:

  1. Click File > Import.
  2. In the Import Wizard, select ILOG Rule Studio Samples and Tutorials.
  3. Click Next.
  4. On the Sample or Tutorial page, select the sample: samples > authoring > bomdomainpopulate.
  5. Click Finish.
    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:

  1. Switch to the Java or Rules perspective.
  2. Click Run > Run and select the Java Application > bomdomainpopulate-StartDatabase launcher.
  3. Click Run.
  4. A process is started and the following message is displayed in the Console view: Server is ready to accept connections on port 1527. Keep this process running as long as you are testing the bomdomainpopulate sample.

To populate the database table:

  1. Click Run > Run and select the Java Application > bomdomainpopulate-CreateAndPopulateTable launcher.
  2. Click Run.
  3. In the console, an SQL script execution output appears. Tables are dropped and created from scratch.

Running this Sample

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:

  1. In the Rule Explorer, open the bomdomainpopulate-rules project.
  2. You should notice an error message: value(String) `CompanyX' is incorrect. This is an expected error and we will fix it later.
  3. In the bom folder, double-click the domains BOM entry to open it in the BOM Editor and edit the trade.CurrencyType virtual class.
  4. images/editbomdomain.png
  5. In the Domain section of the Class tab, click the Edit the domain hyperlink and remove all its static references, as follows.
  6. images/editstaticrefs.png
  7. In the Members section of the Class tab, select all three members in the list and click Remove.
  8. Click the Synchronize with dynamic values hyperlink.
  9. Three domains (USDOLLAR, EURO and AUSDOLLAR) are restored from the database into the domain definition, along with their corresponding verbalization and translation.
  10. Edit the trade.MessageType virtual class and remove its static references and members.
  11. In the Tasks section of the Package tab, click the Update the dynamic domains of this BOM entry hyperlink.
  12. The Dynamic Domains dialog box allows you to populate one or more dynamic domains of a BOM entry in a single step. By default, all dynamic domains are selected.
    images/populatedyndom.png
  13. In the Dynamic Domains dialog box, click Finish.
  14. Two domains (BlackListedStocks and INAPPROPRIATE_CUSTOMER) are restored from the database into the MessageType domain definition, together with their corresponding verbalization and translation.
  15. Save your changes (CTRL+S).

To synchronize your domain classes using the dynamic values from the table:

  1. Open the CheckOrder.OrderType rule in the Rule Editor.
  2. Delete the text "CompanyX" (including the quotes) from the condition part of the rule.
  3. With the cursor positioned at the end of the line (leaving a space after the keyword is), press CTRL+SPACE to display the completion menu.
  4. A list of companies is extracted from the database and displayed in the completion menu.
  5. Press CTRL+SHIFT+SPACE to display the tree representation of the available values. These values are still coming from a live request to the database.
  6. Double-click one of the company names in the completion menu to insert it into the condition part of the rule.
  7. Switch to the IRL tab in the Rule Editor. You will see that the translation of the chosen item is also extracted from the database.
  8. Save your changes (CTRL+S) and close the Rule Editor.

To update your domain and handle deprecation of certain items:

  1. Modify the database by running the bomdomainpopulate-ModifyTable launch configuration.
  2. In the console, an SQL script execution output appears. Several table values have been modified or deleted.
  3. Reopen the trade.CurrencyType virtual class in the BOM Editor and click the Synchronize hyperlink to synchronize its domain once more.
  4. Several additional currency types are added to the domain, together with their corresponding verbalization and translation.
    The AUSDOLLAR domain item is set to deprecated.
  5. Save your changes (CTRL+S).
  6. Note that deprecation of the AUSDOLLAR domain item generates a warning message in the Problems view.
  7. Edit the CheckOrder.OrderType rule again in the Rule Editor. Delete the company name you entered (including the quotes) from the condition part of the rule.
  8. With the cursor positioned at the end of the line (leaving a space after the keyword is), try the different completion modes (CTRL+SPACE, CTRL+SHIFT+SPACE) to see the new entries in the completion menu for the stock value.
  9. Reset the database values again by running the bomdomainpopulate-CreateAndPopulateTable launch configuration.
  10. The synchronization on the CurrencyType virtual class removes the deprecation property on the AUSDOLLAR item, but adds it to Pound, JPYen, and PRCRMB.
  11. In the 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:

Source Files

To display the source code of the bomdomainpopulate sample plug-in:

  1. Click File > Import.
  2. In the Import Wizard, select External Plug-ins and Fragments and click Next.
  3. In the Import As section, select the Projects with source folders option and click Next.
  4. In the Plug-ins and Fragments Found list, scroll down and select the ilog.rules.studio.samples.bomdomainpopulate plug-in (be careful not to select ilog.rules.studio.samples.bomdomainpopulate.source), then click Add.
  5. Click Finish.
  6. The source code of the plug-in is imported and appears in the Rule Explorer.
  7. Switch to the Plug-in Development perspective.
  8. In the Package Explorer, navigate to the Java source file ilog.rules.studio.samples.bomdomainpopulate.actions.UpdateBomDomainAction.java.
  9. Examine the code of the UpdateBomDomainAction class.

Highlights

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.

images/customproperties.png

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.

images/tradeorderstockproperties.png

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.

Related Tasks

Creating a Value Provider

Related Samples and Tutorials

Import Samples and Tutorials Wizard