Automated query execution sample details

You use Rule Designer to run this sample.

Running this sample

To run the query execution:

  1. In Rule Designer, switch to the Rule perspective.
  2. Click Run  > External Tools  > External Tools Configurations.
  3. In the External Tools Configurations dialog, in the Configurations list, click Ant Build > queryexecution-application.
  4. Click Run.

    The console displays the results of the query execution. Three queries are run: one query that is contained in a compressed file, one that is accessed through the query path, and one with a query that is a string. For each query, the console displays a report that contains the text of each rule that matches the query criterion, and the number of rules.

How this sample works

The execution uses the class ilog.rules.studio.samples.queryexecution.Query to run the query. 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. It is run from within the build.xml file as an Eclipse headless application by using:

ilog.rules.studio.samples.queryexecution.headless.application

Notice that the real query execution is delegated to the ilog.rules.studio.samples.queryexecution.helper.Model class.

You must supply the following mandatory parameters (see the supplied build.xml file for a full list of parameters):

  • Execution when the query is a Query object:

    • targetproject = The name of the decision service (for example: Loan Validation Service).
    • query = "path:path/to/a/query/object/in/the/eclipse/workspace"
    • scope = true if the scope of the query is local to the project of the query project, or false if it encompasses the project dependencies.
  • Execution when the query is a simple text:

    • targetproject = The name of the rule project. For example: loanvalidation-rules.
    • query = a BQL query. For example: “text:Find all business rules such that the documentation of each business rule is empty”.
    • scope = true if the scope of the query is local to the project of the query, or false if it encompasses the project dependencies.
  • Execution when the query is included in a compressed file:

    • targetproject = The name of the rule project (for example: loanvalidation-rules).
    • query = "zip:path_to_the_zip_file/path_in_the_zip_file_to_the_query".
    • scope = true if the scope of the query is local to the project of the query, or false if it encompasses the project dependencies.

To define the application flow in Query.java:

  1. Check the input parameters.
  2. Check whether the decision service exists in the workspace, and then use it for the next steps.
  3. If the path: mode is used, check whether the query exists in the workspace, and initialize a query service from it.
  4. If the text: or zip: mode is used, initialize a query service from the query string.
  5. Run the query from the query service.
  6. Process the results that are returned by the query.

The command output is visible in the Console view of Rule Designer. For each query, console displays the text of the rule artifacts (rules and decision tables) that match the query conditions, the execution status, and the number of rule artifacts that match the conditions.

Source files

To display the source code of the queryexecution Eclipse plug-in, do the following steps:

  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, select the ilog.rules.studio.samples.queryexecution plug-in, and then click Add.
  5. Click Finish.
    Rule Designer imports the plug-in source code and displays it in Rule Explorer.
    Note: You can ignore the warning that the build path specifies execution environment Java™SE-1.7. You can also remove it by either installing Java 7 on your Rule Designer instance, or setting the execution environment of the sample plug-in to 1.7.
  6. Switch to the Plug-in Development perspective.

    Click Window  > Open Perspective  > Other. Select the Plug-in Development perspective and then click OK.

  7. In the Package Explorer, navigate to the Java source files in the ilog.rules.studio.samples.queryexecution/queryexecutionsrc folder.

    The following source file is of interest:

    ilog.rules.studio.samples.queryexecution.helper.Model.java