Matus Majchrak [
http://community.jboss.org/people/dekadence] created the discussion
"Re: jbpm, process definitions, jboss - looking for knowledge"
To view the discussion, visit:
http://community.jboss.org/message/596844#596844
--------------------------------------------------------------
Hi Piotr,
First things first, In order to access process definitions you have to have access to the
guvnor repository(or fake it as Jbpm5 demo does using -Djbpm.console.directory)
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("Guvnor
default");
kagent.applyChangeSet(ResourceFactory.newClassPathResource("ChangeSet.xml"));
kagent.monitorResourceChangeEvents(false);
KnowledgeBase kbase = kagent.getKnowledgeBase();
ChangeSet.xml file will direct the knowledge agent to resources it should care about. For
example:
<change-set
xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...
>
<add>
<resource
source='http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/defaultPackage/LATEST'
type='PKG' basicAuthentication="enabled" username="admin"
password="admin" />
</add>
</change-set>
This will tell your agent to look for your localhost's repository default package.
Try to deploy some processes into default package so that you have something to work with:
http://people.redhat.com/kverlaen/jBPM5-guvnor-integration.swf
http://people.redhat.com/kverlaen/jBPM5-guvnor-integration.swf
You can now test it by listing deployed processes:
for (Process process : kbase.getProcesses()) {
System.out.println("I found process in Guvnor: " + process.getId());
}
Now for the knowledgeSession.Depending on where does your application run, you have to
obtain an EntityManagerFactory for drools persistence.
See the persistence.xml in jbpm5-installers/db folder.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory","org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory","org.jbpm.persistence.processinstance.JPASignalManagerFactory");
KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
kSession = JPAKnowledgeService.loadStatefulKnowledgeSession(1, kbase, config, env);
The above code will try to load an existing Statefull knowledge session. If this does not
exsit you will receive an error and you have to create a fresh kSession like this:
env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
kSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
And thats basicaly it. You can now get a list of processes:
knowledgeSession.getKnowledgeBase().getProcesses()
register a ProcessEventListener to intercept process lifecycle events:
knowledgeSession.addEventListener(... your class implementing ProcessEventListener)
or get list of process instances:
knowledgeSession.getProcessInstances();
So basicaly you have to hook up your application to guvnor to access process related
resources and obtain JPA entity management factory to be able to construct or obtain
knowledge session. After that, you should have all the thigs you need to fulfill your
tasks.
regards
matus
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/596844#596844]
Start a new discussion in jBPM at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]