Creating query extensions

To create business-specific query predicates that process customized rule project items and properties, you extend the query BOM files.

About this task

Queries are based on a specific business object model: the query BOM. This internal business object model defines the classes and methods you can use in queries. It has an associated vocabulary that you can use to write queries in natural language. You can extend the query BOM to add phrases to standard query constructs.

You extend the query BOM with a BOM file. You then do the following tasks:
  • Define extender classes that define the code associated with the new BOM elements

  • Add a mapping file to associate BOM elements with extender classes

  • Add a vocabulary file that associates BOM elements with natural language phrases

Note: You can define only one query extension.

To create business-specific query predicates that process customized rule project items and properties, you extend the query BOM files.

Procedure

To extend the query BOM:

  1. Create a BOM file (a file with the extension .bom). In this file, define only new elements.

    For example, you can define a BOM file named ext.bom and then add a query predicate to do queries on rules that are ready for review:

    
    package bql;
    public class RuleArtifact extends bql.PackageElement
    {
    public boolean isReadyForReview()
       property categories “teamserver,rulestudio”;
    }
    

    The categories teamserver and rulestudio indicate that this query predicate can be used in both Decision Center and Rule Designer.

    Note: If your query predicate applies to extended rule model elements, set the package to bqlExtension in the BOM file.
  2. Create a vocabulary file corresponding to your query BOM extensions.

    For example, you can define a vocabulary file named ext.voc as follows:

    
    bql.RuleArtifact.isReadyForReview()#sentence.navigation =
                                                    {this} is ready for review
    

    You can have several vocabulary elements for a single BOM element, and you can create a vocabulary file per locale.

  3. Create an extender class. Pass an instance of IlrQueryableElementWrapper as an argument for the methods you define.

    With the interface IlrQueryableElementWrapper, you can use the methods getModelElement, setPropertyValue, and getPropertyValue on rule model elements.

    As long as you use the common interface of the rule model API to define your new methods, you can use the same code for both Rule Designer and Decision Center. You can use the Rule Designer or Decision Center model APIs for more advanced cases, but in this case your code is different for Rule Designer and Decision Center.

    For example, to write code to identify that a rule that is ready for review when its documentation field contains some content, you define the extender class as follows:

    
    public class MyExtensionClass {
       public static boolean isReadyForReview(IlrQueryableElementWrapper projectElement) {
        IlrElement modelElement = projectElement.getModelElement();
        System.out.println("isReadyForReview method called on element"+
                   modelElement.getPropertyValue("name"));
        String documentation = (String)modelElement.getPropertyValue("documentation");
        return documentation.length() > 0;
      }
    } 
  4. Specify a mapping from your new BOM elements to your extender classes in a property file.

    For example, you can specify the mapping for your new BOM elements in a file named ext.properties, as follows:

    
    bql.RuleArtifact=ilog.rules.studio.samples.queryextension.MyExtensionClass
    

    In this example, MyExtensionClass refers to the fully qualified name of the extender class.

Results

You now have all the files necessary to integrate the query extension into Rule Designer or Decision Center.

Integration into Rule Designer

Integration into Decision Center

Create a Rule Designer plug-in with a query model extension point.

Integrating query extensions into Rule Designer

Repackage the Decision Center archive to integrate and declare the extended query BOM files.