Samples > Rule Studio Authoring Extensions > How to Populate a Decision Table from a Data Source

This sample shows how to fill an empty, structured decision table using Rule Studio APIs. The values used to populate the decision table model come from a customized data provider object providing the decision table content. This sample comes with three providers:

This sample uses the Apache Derby engine and the Jxl class library provided with ILOG JRules.

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. In the Product Configuration dialog, click the Add an Extension Location link.
  3. In the Browse dialog, select the folder <InstallDir>/studio/samples/eclipse.
  4. If prompted to restart the Eclipse Workbench, click Yes.
  5. Eclipse shuts down and restarts.

When Eclipse restarts, you need to check that the Decision Table Loading Sample feature is enabled.

To check that the Decision Table Loading 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 Decision Table Loading Sample 1.0.0. is listed.

You can now import the sample project files.

To import the dtpopulate 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 authoring > dtpopulate.
  5. Click Finish.
  6. If one or more files already exist in your workspace, a warning message is displayed indicating that the file(s) were not re-imported. Close the message window.
  7. The imported sample project files are displayed in the Rule Explorer. You should see three new projects:
    - dtpopulate-rule. The target sample rule project. This project contains the decision table that will be populated.
    - dtpopulate-xom. A Java project containing the execution model of dtpopulate-rule.
    - dtpopulate-application. A Java project including an Ant build file (build.xml) which contains different Ant tasks that will be used in order to demonstrate different execution scenarios.
    Note
    The target init.runtime was added in the build.xml file to help Eclipse set the runtime properties: os (operating system), ws (window system) and arch (architecture) before running the sample. This should work for most common configurations. If it does not match your runtime environment, you can modify the Ant target to force the values of these properties.

Running this Sample

The sample is run in several stages.

To run the File Provider:

  1. If necessary, switch to the Rule perspective:
  2. Click Window > Open Perspective > Other. Select Rule Perspective, then click OK.
  3. Click Run > External Tools > External Tools.
  4. The External Tools window is displayed.
  5. In the Configurations list, click Ant Build > dtpopulate-application.
  6. Click the Targets tab.
  7. Clear the run.xl and run.db target check boxes and check the run.file target checkbox.
  8. Click Run.
  9. Output is displayed in the Console view:
...
[java] Starting application:
[java] Received arguments:
[java] targetproject='dtpopulate-rule'
[java] dtname='dtsample'
[java] driver=' '
[java] url='file://./data/script/data.txt'
[java] user=''
[java] password=''
[java] data=';'
[java] Inserting...
[java] dtsample successfully loaded 
  1. In the Rule Explorer, right-click the decision table dtpopulate-rule > rules > dtsample and click Refresh.
  2. Double-click the decision table dtsample to open it and load the associated data.
  3. Close the dtsample decision table.
  4. Right-click the dtsample decision table and click Refresh.

To run the Excel Provider:

  1. In the Rule perspective, on the Run menu, click External Tools > External Tools.
  2. The External Tools window is displayed.
  3. In the Configurations list, click Ant Build > dtpopulate-application.
  4. Click the Targets tab.
  5. Clear the run.file and run.db target checkbox and check the run.xl target checkbox.
  6. Click Run.
  7. Output is displayed in the Console view:
...
[java] Starting application:
[java] Received arguments:
[java] targetproject='dtpopulate-rule'
[java] dtname='dtsample'
[java] driver=' '
[java] url='xl://./data/script/data.xls'
[java] user=''
[java] password=''
[java] data='sheet'
[java] Inserting ...
[java] dtsample successfully loaded 
  1. In the Rule Explorer, right-click the decision table dtpopulate-rule > rules > dtsample and click Refresh to refresh the decision table.
  2. Double-click the decision table dtsample to open it and load the associated data.
  3. Close the dtsample decision table.
  4. Right-click the dtsample decision table and click Refresh to refresh the decision table.

To run the Database Provider:

  1. In the Rule perspective, on the Run menu, click External Tools > External Tools.
  2. The External Tools window is displayed.
  3. In the Configurations list, click Ant Build > dtpopulate-application.
  4. Click the Targets tab.
  5. Clear the run.file and run.xl target checkbox and check the run.db target checkbox.
  6. Click Run.
  7. The run.db target first creates and loads a simple Derby database schema. Output is displayed in the Console view:
...
[java] Received arguments:
[java] targetproject='dtpopulate-rule'
[java] dtname='dtsample'
[java] driver='org.apache.derby.jdbc.ClientDriver'
[java] url='jdbc:derby://localhost:1527/../DTPOPULATION'
[java] user='DTPOPULATIONSAMPLE'
[java] password='DTPOPULATIONSAMPLE'
[java] data='SELECT * FROM DATATABLE'
[java] Inserting ...
[java] dtsample successfully loaded
...
  1. In the Rule Explorer, right-click the dtpopulate-rule > rules > dtsample decision table and click Refresh to refresh the decision table.
  2. Double-click the dtsample to open it and load the associated data.
  3. Close the dtsample decision table.
  4. Right-click the dtsample decision table and click Refresh to refresh the decision table.

Source Files

To display the source code of the dtpopulate Eclipse 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.dtpopulate plug-in (be careful not to select ilog.rules.studio.samples.dtpopulate.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. Click Window > Open Perspective > Other. Select the Plug-in Development perspective then click OK.
  9. In the Package Explorer, navigate to the Java source files in the ilog.rules.studio.samples.dtpopulate > src-dtpopulate folder.
  10. The following source files are of interest and are described below in the Highlights section of this sample:
    ilog.rules.studio.samples.dtpopulate.DTFeeder
    ilog.rules.studio.samples.dtpopulate.helper.Argument
    ilog.rules.studio.samples.dtpopulate.helper.FileLoader
    ilog.rules.studio.samples.dtpopulate.helper.JdbcLoader
    ilog.rules.studio.samples.dtpopulate.helper.ExcelLoader
    ilog.rules.studio.samples.dtpopulate.helper.DataProvider

Highlights

Highlights of this sample include:

Related Concepts

Decision Tables
Rule Model API for Rule Studio

Related Tasks

Working With Decision Tables

Related Samples and Tutorials

Import Samples and Tutorials Wizard