Drools GORM

  • Tags : rules engine, workflow
  • Latest : 0.5.6
  • Last Updated: 06 February 2012
  • Grails version : 1.3.4 > *
  • Authors : baun, diega, martins
5 votes
Dependency :
compile ":drools-gorm:0.5.6"
Custom repositories :
mavenRepo "http://repository.jboss.org/nexus/content/groups/public/"
mavenRepo "http://people.apache.org/repo/m2-snapshot-repository/"

Documentation Source Issues

Summary

Installation

grails install-plugin drools-gorm

Description

This plugin integrates Drools 5.2 and jBPM 5 in a Grails application. It provides persistent storage for Drools and jBPM 5 using GORM.

For Grails version before 1.2 use plugin version 0.3.

Usage

Currently, the plugin provides direct access to the Drools API. (see Drools Documentation Library and jBPM 5 Documentation Library)

For Grails usage examples you see the integration tests on Github) or you can clone the example application.

Custom work item handler

You can use your Grails service artefact as work item handler if they implement the interface WorkItemHandler.

There are two possibilities to refer to your work item from workflow:

  • Convention: If you name your service class for example "HelloWorldWorkItemService" then the work item will be called "Hello World".
  • Configuration: In your service class you can define a static variable called "workItemName".

Drools Flow Example

Create a KnowledgeBase:

class JbpmService {
        static transactional = true

/** The kstore is automatically declared by the drools-gorm plugin */ def kstore

/** * Returns a SessionConfiguration containing Drools services * implementations for Grails. * * @return a SessionConfiguration containing Drools services * implementations for Grails. */ def getGORMSessionConfig() { Properties properties = new Properties();

properties.setProperty("drools.commandService", SingleSessionCommandService.class.getName()); properties.setProperty("drools.processInstanceManagerFactory", GormProcessInstanceManagerFactory.class.getName()); properties.setProperty("drools.workItemManagerFactory", GormWorkItemManagerFactory.class.getName()); properties.setProperty("drools.processSignalManagerFactory", GormSignalManagerFactory.class.getName());

return new SessionConfiguration(properties); }

/** * Construct a kbase with an example flow. * * @return a KnowledgeBase containing an example flow. */ def KnowledgeBase createKbase() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

kbuilder.add(ResourceFactory.newClassPathResource("helloWord.rf"), ResourceType.BPMN2);

if (kbuilder.hasErrors()) { throw new IllegalStateException("error compiling 'helloWord.rf':n" + kbuilder.errors); }

return kbuilder.newKnowledgeBase(); }

/** * Start the a process. * * @param processId the process id to start. * @return the id of the process instance. */ def startProcess(String processId) {

Environment env = KnowledgeBaseFactory.newEnvironment()

StatefulKnowledgeSession ksession = kstore.newStatefulKnowledgeSession(createKbase(), getGORMSessionConfig(), env)

ProcessInstance pi = ksession.startProcess(processId)

def pid = pi.id ksession.dispose() return pid } }

Version History

  • 08/Mar/2012
    • Update to jBPM 5.2.0 and Drools 5.3.1.Final
  • 16/Nov/2011
    • Update Drools version for Java 1.7 compatibility.
  • 12/Sept/2011
    • Remove MySql JDBC driver dependency.
    • Remove DroolsTest domain class from release.
  • 7/Sept/2011
    • Add Janino as depedency.
  • 7/Aug/2011
  • 17/May/11 - version 0.5.1
    • Fix WorkItem serialization unmarshalling.
  • 30/Mar/11 - version 0.5.0
    • NEW: Update plugin to work with latest versions of Drools 5.2 and jBPM 5.
    • Tested on Grails 1.3.5
  • 02/Sep/10 - Version 0.4.1
  • 08/Feb/10 - Version 0.4
    • Grails 1.2 support
  • 25/Sep/09 - Version 0.3
    • NEW: Grails service artefacts are automatically registered as work item handlers if they implement WorkItemHandler
    • FIXED: some errors related to multithreading
    • NEW: some integration tests added
  • 03/Sep/09 - Version 0.2
  • 14/Jul/09 - Version 0.1
    • Initial release

Development

  • For issues, improvements or new features use JIRA