Thursday, 1 September 2016

Step By Step Guide For Creating Drools Rules in Kie Workbench And Integrating It In External Java Application

Kie Workbench Side

Creating an organization, repository and project

    • Login to Kie workbench with an ‘admin’ account.
    • Create a new organization:
      • Authoring -> Administration -> Organizational Units -> Manage organizational Units -> Add
      • Give a name and group id to the organization.
    • Create a new repository in the organization.
      • Authoring -> Administration -> Repositories -> New Repositories.
      • Give a name and select the organization
    • Create a new project.
      • Authoring -> Project Authoring -> New Item -> New Project
      • Add a Project name and description.
      • Add Group ID (default value is organization id), Artifact id (default value is project name) and initial version number.

Creating a Rule

    • Select the Organization, Repository and Project in the Project explorer.
    • New Item -> Guided Rule
    • Enter a name for the rule and select the package.
    • Create the rule.

Adding external POJO model to the rules

The POJO model class that is needed by the workbench project need to be exported as a maven jar and uploaded to the workbench.

Uploading the POJO model class jar

  • Authoring -> Artifact Repository -> Upload -> Browse to the Jar and upload
  • If Jar does not contain a pom.xml file, you will be asked to manually enter a group and artifact id.

Adding model to the Project

  • Navigate to the project -> Open Project Editor
  • In project editor, from the dropdown, select Dependencies.
  • Add from repository -> Select the model class jar file.

Adding and using model class in Rules.

  • Open guided rule editor -> Navigate to the ‘Data Object’ tab.
  • New item -> Choose a type.
  • The type can be then used in rule editor.

Java Side

Accessing Workbench rule from external Java Application

  • Setup drool runtime. Add following dependencies to the application pom.xml
  • Add a new Repository to your maven. This is done by adding following line to settings.xml file residing in MAVEN_HOME folder. If there is no xml file, create one. Url tag must contain the link to the maven repository of kie workbench. The id of the repository must be ‘guvnor-m2-repo’.
  • Add the authentication details for the above repository in settings.xml file.
  • Java code to access the repositories and run the rules. In the release id, we need to pass the Group ID, Artifact ID and version number of the workbench project.

KieScanner and Repository Updation

KieServices tend to download the remote repository only once in a day and store it in local repository. We can however use the KieScanner and force the container to scan for any update in the remote repository. A scan will only update the local repository if we are using ‘LATEST’ as the version number and a new version of the repository is available in remote directory or the remote repository is in development stage (denoted by ‘-SNAPSHOT’ appended to the version number).

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi NAved ,
    i have quick question on drools workbench,
    The rules introduced on next day or same day , can they work on the production environment .

    I want rules to be changed dynamically and see the output and then changing the rules again and see the output .

    ReplyDelete
    Replies
    1. sathish Natarajan5 July 2017 at 02:20

      Also if iwant to change the rules dyanamically very often and see the results ,IS Drools workbench the right tools

      Delete
  3. I followed the same process as mentioned by u but still I am getting error of
    Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: demo:salerules:1.0.0-SNAPSHOT
    at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:117)
    at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:111)

    Kindly help and tell full steps of integration with external application.

    ReplyDelete
  4. Thank You and I have a keen proposal: What Is In House Renovation Loan house renovation advice

    ReplyDelete