Data sources for BOM domains sample details

You use Rule Designer to run this sample.

Before you 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 Configurations, expand Java Application, and select bomdomainpopulate-StartDatabase.
  3. Click the Arguments tab, and replace the program arguments with start -noSecurityManager.
  4. Click Run. The Console view displays a message that the server is started and is ready to accept connections on port 1527. Run this process for as long as you are testing the bomdomainpopulate sample.
  5. Click Run > Run Configurations, expand Java Application, and select bomdomainpopulate-CreateAndPopulateTable.
  6. Click Run. The console displays an SQL script execution output. The execution creates and drops tables from scratch.

Running this sample

Note that there is no execution layer on the rule project that is 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 this sample:
  1. In the Rule Explorer, open the bomdomainpopulate-rules project.

    You notice an error message: value(String) ‘CompanyX’ is incorrect. You fix this error later.

  2. In the bom folder, double-click the domains BOM entry to open it in the BOM Editor, and edit the trade.CurrencyType virtual class.
  3. In the Domain section of the Class tab, click the Edit the domain link to display the list of static references.
  4. Select the three static references, click Remove, and then click Finish to close the Domains wizard.
  5. In the Members section of the Class tab, select all three members in the list and click Delete.
  6. When a message asks whether you want to remove these three members, click Yes.
  7. In the Domain section, click the Synchronize with dynamic values link.

    Three domains (USDOLLAR, EURO, and AUSDOLLAR) are restored from the database into the domain definition, along with their corresponding verbalization and conversion.

  8. In the bom folder, double-click the domains BOM entry to open it in the BOM Editor. Edit the trade.MessageType virtual class, and remove its static references and members.
  9. In the Tasks section of the Package tab, click the Update the dynamic domains of this BOM entry link.

    You use the Dynamic Domains dialog box to populate one or more dynamic domains of a BOM entry in a single step. By default, all dynamic domains are selected.

    Images shows the dynamic domains of a BOM entry.
  10. In the Dynamic Domains dialog box, click Finish.

    The database restores two domains (BlackListedStocks and INAPPROPRIATE_CUSTOMER), into the MessageType domain definition, together with their corresponding verbalization and translation.

  11. Save your changes (press Ctrl+S).
To synchronize your domain classes by using the dynamic values from the table:
  1. Open the CheckOrder.OrderType rule in the Intellirule editor.
  2. Delete the text “CompanyX” (including the quotes) from the condition part of the rule.
  3. With the cursor that is positioned at the end of the line (leaving a space after the keyword is), press Ctrl+Space to display the completion menu.

    Rule Designer extracts a list of companies from the database and displays it in the completion menu.

  4. Press Ctrl+Shift+Space to display the tree representation of the available values. These values come from a live request to the database.
  5. Double-click one of the company names in the completion menu to insert it into the condition part of the rule.
  6. Save your changes (press Ctrl+S) and close the rule editor.
To update your domain and handle deprecation of certain items:
  1. Modify the database by clicking Run > Run Configurations, expand Java Application and select bomdomainpopulate-ModifyTable.

    Click Run. In the console, an SQL script execution output displays. The execution modifies and deletes several table values.

  2. Reopen the trade.CurrencyType virtual class in the BOM Editor and click the Synchronize with dynamic values link to synchronize its domain again.

    The execution adds several more currency types to the domain, together with their corresponding verbalization and conversion.

    The execution sets the AUSDOLLAR domain item to deprecated.

  3. Save your changes (press Ctrl+S).

    Note that deprecation of the AUSDOLLAR domain item generates a warning message in the Problems view.

  4. Edit the CheckOrder.OrderType rule again in the Intellirule editor. Delete the company name that you entered (including the quotation marks) from the condition part of the rule.
  5. With the cursor that is positioned at the end of the line (leaving a space after the keyword is), try the different completion modes (press Ctrl+Space or Ctrl+shift+Space) to see the new entries in the completion menu for the stock value.
  6. Reset the database values again by running the bomdomainpopulate-CreateAndPopulateTable launch configuration.

    The synchronization on the CurrencyType virtual class removes the deprecation property on the AUSDOLLAR item, but adds it to Pound, JPYen, and PRCRMB.

  7. Save your changes (Ctrl + S).
  8. In the CheckCurrency.CurrencyRestriction rule, the completion menu for the stock name takes into account the original values that were reset in the database.

How this sample works

The update of the BOM domain is through a common class that is located in the sample plug-in code:

ilog.rules.studio.samples.bomdomainpopulate.DataBaseDomainValueProvider, which implements ilog.rules.shared.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.

To connect a static reference domain with the domain provider declared in the sample plug-in, you set the custom property domainValueProviderName to derbyDataBaseDomainProvider.

Setting the custom property

The definition of the database connection parameters is 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 conversion defined in the translationColumn of each class is of the form return <string>;.

In the plug-in code, a simple model is implemented in the package ilog.rules.studio.samples.bomdomainpopulate.stock. This update this model, you access it using the class ilog.rules.studio.samples.bomdomainpopulate.stock.StockValueInfo, defined in the sample plug-in.

The StockValueInfo class delegates the conversion, completion proposal, and checking features of the Intellirule editor to the StockValueTranslator, StockValueProvider and StockValueChecker classes, which are defined in the ilog.rules.studio.samples.bomdomainpopulate.stock package.

The press Ctrl+Space or Ctrl+Shift+Space combination triggers the update of the stock model at each completion request. A better approach might be to do 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, which is defined in the model BOM entry. To connect to the value info plug-in, you use the custom property valueInfo and set it to ilog.rules.studio.samples.bomdomainpopulate.Stock.

Trade order stock properties

Source files

To display the source code of the bomdomainpopulate sample plug-in:
  1. Click File  > Import.
  2. In the Import wizard, select Plug-in Development > 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, and then click Add.
  5. Click Finish.

    Rule Explorer displays the imported source code of the plug-in.

  6. Switch to the Plug-in Development perspective.
  7. In the Package Explorer, navigate to the Java source files in the ilog.rules.studio.samples.bomdomainpopulate/bomdomainpopulatesrc/ilog.rules.studio.samples.bomdomainpopulate.actions folder.
  8. Examine the code of the UpdateBomDomainAction class.