Automated classic rule project deployment sample details

You use Rule Designer to run this sample.

Running this sample

The sample works with the classic rule engine.

To run this sample:

  1. In the Rule perspective, clickRun > Run Configurations.
  2. In Run Project, select the rulesextraction-rules-execution launch configuration.
  3. Click Run.

    The Console view shows output that is similar to the following information:

    ** Error ** Bill Jona's competence interview is before his hire date.
    > Mike Levy works in Africa
    > Billy Edouards works in Africa
    > Naomie Parker works in America
    > John Smith works in America
    > Dick Roberts works in Asia
    > Nate Arris works in Asia
    > Paul Ellis works in Asia
    > Ed Matthews works in Europe
    > Kim Fisher works in Europe
    > Tracy Cooper works in Europe
    > Bill Jona works in Europe
    > Patrick Doe works in Europe
    > Vanessa Arisson works in Oceania
    > Bob Arthur works in Oceania
    $ Dick Roberts hire date is: 01/01/1992
    $ Ed Matthews hire date is: 02/01/1992
    $ Mike Levy hire date is: 12/01/2002
    $ Naomie Parker hire date is: 08/01/2004
    $ Kim Fisher hire date is: 03/01/1997
    $ Vanessa Arisson hire date is: 06/01/1991
    $ Nate Arris hire date is: 05/01/1995
    $ Paul Ellis hire date is: 09/01/1984
    $ Billy Edouards hire date is: 11/01/1988
    $ Tracy Cooper hire date is: 05/01/2003
    $ Bob Arthur hire date is: 04/01/1985
    $ Bill Jona hire date is: 12/01/1995
    $ John Smith hire date is: 10/01/1980
    $ Patrick Doe hire date is: 05/01/2000
    + ASIA: Dick Roberts needs to have a competence evaluation
    + EUROPE: Ed Matthews needs to have a competence evaluation
    + EUROPE: Kim Fisher needs to have a competence evaluation
    + EUROPE: Tracy Cooper needs to have a competence evaluation
    + EUROPE: Bill Jona needs to have a competence evaluation
    + EUROPE: Patrick Doe needs to have a competence evaluation
    + OCEANIA: Vanessa Arisson needs to have a competence evaluation
    + OCEANIA: Bob Arthur needs to have a competence evaluation
    + AMERICA: John Smith needs to have a competence evaluation
    ++ We need to adjust Bill Jona's position
  4. Generate a ruleset archive and run it:
    1. In the rulesetextraction_application project, click build.xml to select it.
    2. On the Run menu, click External Tools > Run As > 1 Ant Build.

    The build generates, parses, and runs the ruleset archive under output/extractionsample.jar in the same project. The Default Extractor is used as the extractor. The build generates a ruleset archive (extraction target) first, and then runs it (execute target). The execution task calls RulesetExecution with the ruleset archive as a parameter. This class is defined in the rulesetextraction_application project.

    In the Ruleset Extractors section of the project properties, you can look at the extractor that is defined in the project.

  5. Try the following Ant tasks to see how the results differ depending on how the extractor is defined.

    To run each example:

    1. Click Run > External Tools > Run As > 2 Ant Build.
    2. Select the Targets tab.
    3. Select the check box next to your target, and clear all the other target check boxes.
    4. Click Run.

The extraction1 target uses a Custom Extractor that is inside the rule project, and does not use a validator. The query returns only rules for Europe.

The execution output of the rules for extraction1:

> Ed Matthews works in Europe
> Kim Fisher works in Europe
> Tracy Cooper works in Europe
> Bill Jona works in Europe
> Patrick Doe works in Europe
+ EUROPE: Ed Matthews needs to have a competence evaluation
+ EUROPE: Kim Fisher needs to have a competence evaluation
+ EUROPE: Tracy Cooper needs to have a competence evaluation
+ EUROPE: Bill Jona needs to have a competence evaluation
+ EUROPE: Patrick Doe needs to have a competence evaluation

The extraction2 target does not use an extractor, but one is generated in the code. No query is used. The validator Test Validator discards the following rules from the generated ruleset archive:

  • Rules with test in their names (Other HR Rules > Competence eval and Other HR Rules > hire test).
  • Expired rules, whose rule property expirationDate value that predates the current date (America HR Rules > employee).
  • Rules that contain the word Oceania in their definitions (Oceania HR Rules > employee).
  • Rules whose status property is set to defined or rejected:
    • Asia HR Rules > employee: defined
    • Europe HR Rules > employee: inactive
    • Other HR Rules > Display hire dates: rejected

    The execution output of the rules for extraction2:

    > Mike Levy works in Africa
    > Billy Edouards works in Africa
    + ASIA: Dick Roberts needs to have a competence evaluation
    + EUROPE: Ed Matthews needs to have a competence evaluation
    + EUROPE: Kim Fisher needs to have a competence evaluation
    + EUROPE: Tracy Cooper needs to have a competence evaluation
    + EUROPE: Bill Jona needs to have a competence evaluation
    + EUROPE: Patrick Doe needs to have a competence evaluation
    + OCEANIA: Vanessa Arisson needs to have a competence evaluation
    + OCEANIA: Bob Arthur needs to have a competence evaluation
    + AMERICA: John Smith needs to have a competence evaluation
    ++ We need to adjust Bill Jona's position

The extraction3 target uses a Custom Extractor that is defined inside the rule project, and another query is set for the extractor, without using a validator. Keep Europe rules only replaces Keep America rules only in the extractor Custom Extractor. Only rules in America HR Rules are run. In this target, the build is forced before the ruleset archive is generated.

Note: Forcing the build is useful when the rule project is not built before the ruleset is extracted, or if the source of the rule project changes and the build does not occur before ruleset extraction.

The execution output of the rules for extraction3:

> Naomie Parker works in America
> John Smith works in America
+ AMERICA: John Smith needs to have a competence evaluation

How this sample works

The ruleset extraction process uses the ilog.rules.studio.samples.rulesetextraction.RulesetExtractor class. This class is defined in the Eclipse plug-in description file as an extension for org.eclipse.core.runtime.applications, and implements org.eclipse.core.runtime.IPlatformRunnable.

The class is run as an Eclipse headless application by using ilog.rules.studio.samples.rulesetextraction.headless.application.

This application expects the following mandatory parameters:

  • project: the rule project
  • file: the expected ruleset archive file name

The application also accepts the following optional parameters:

  • extractor: the extractor
  • query: the query that is used in the extractor
  • validator: the validator that is used in the extractor
  • forcebuild: (no value required) used to force the build of the rule project before ruleset extraction

See the supplied build.xml file for a full list of parameters.

The application flow is as follows:

  1. Check the input parameters.
  2. Check to see whether the rule project exists in the workspace, and then use it for the next steps.
  3. If the forcebuild parameter is supplied, build the rule project.
  4. If an extractor name is input as a parameter for the application, verify its existence in the rule project.
  5. Use the extractor found in the previous step or create a new one.
  6. If a query name is entered as a parameter, try to find it in the rule project. If found, associate this query with the extractor.
  7. If a validator name is entered as a parameter, try to find if it is the name of an element (extractorValidator) of an extension that extends ilog.rules.studio.model.extractorValidator. If found, associate this validator with the extractor. It must be defined in the plug-in description file.
  8. Finally, generate the ruleset archive.
    Note: The execution object model classes must be defined in the active workspace.

A custom validator is provided as an example in ilog.rules.studio.samples.rulesetextraction.extractor.MyExtractorValidator. This class extends the extension point ilog.rules.studio.model.extractorValidator, and implements the class ilog.rules.commonbrm.extractor.IlrExtractorValidator.

Source files

To display the source code of the rulesetextraction Eclipse plug-in:

  1. Click File > Import.
  2. In the Import wizard, select Plug-in Development > Plug-ins and Fragments, and then click Next.
  3. In the Import As section, select the Projects with source folders option, and then click Next.
  4. In the Plug-ins and Fragments Found list, scroll down and select the ilog.rules.studio.samples.rulesetextraction plug-in.
  5. Click Add, and then click Finish.

    Rule Explorer displays the imported plug-in source code.

  6. Switch to the Plug-in Development perspective.
  7. In the Package Explorer, navigate to the Java™ source files in the folder ilog.rules.studio.samples.rulesetextraction/src-rulesetextraction.

    Review the following source files:

    ilog.rules.studio.samples.rulesetextraction.RulesetExtractor

    ilog.rules.studio.samples.rulesetextraction.extractor.MyExtractorValidator