Jan Uhlir [https://community.jboss.org/people/espinosa_cz] created the 
discussion

"How to actually run process defined by Process API?"

To view the discussion, visit: https://community.jboss.org/message/719649#719649

--------------------------------------------------------------
Manual chapter  http://docs.jboss.org/jbpm/v5.2/userguide/ch05.html#d0e783 
5.1.3. Defining Processes Using the Process API is an exciting reading cut 
short. There is no hint how to run just defined process, how to add the process 
to Knowledge API.
I rummaged forums and mail list I found this two approaches, both works me, but 
both have issues.

*Way 1 – casting to inner implementations*
Casting KnowledgeBase and RulesBase to their particular implementations. This 
does no good to design. What is the point to have all nice and tidy interfaces 
like KnowledgeBuilder, KnowledgeBase, KnowledgeSession, when you have to cast 
to their particular impelementations in one crucial step.

Code snipplet:

RuleFlowProcessFactory factory = 
RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").packageName("org.jbpm").startNode(1).... 
//finish definition
// add process definition to KnowledgeBase
RuleFlowProcess processDef1 = factory.validate().getProcess();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
((AbstractRuleBase)((InternalKnowledgeBase)kbase).getRuleBase()).addProcess(processDef1);
// run the process
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.startProcess("org.jbpm.HelloWorld");



*Way 2 -  XmlBPMNProcessDumper*
Using XmlBPMNProcessDumper is better on design side but (unnecessary) 
subsequent marshalling and unmarshalling making it not very effective variant.

Code snipplet:

RuleFlowProcessFactory factory = 
RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory.name("My process").packageName("org.jbpm").startNode(1).... //finish 
definition
// add process definition to KnowledgeBuilder
RuleFlowProcess process = factory.validate().getProcess();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(
 ResourceFactory.newByteArrayResource(
 XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes()),
 ResourceType.BPMN2);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
// run the process
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.startProcess("org.jbpm.process");

Source:  https://community.jboss.org/message/644606#644606 
https://community.jboss.org/message/644606

Is there another, official, better way?
Whatever way, please amend the documentation and include some.

*Underline notes*

I also checked original Drools Flow documentation -  
http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-flow/html/ch04.html#d0e381
 4.1.3. Defining Processes Using the Process API. It contains 3 examples how to 
define process, an abundance compared to jBPM manual, but any hint how to add 
it to KnowledgeBase and run it.

In the jBPM chapter – 5.1.3. - RuleFlowProcessFactory, creating 
RuleFlowProcess. All of sudden, from jBPM API back to Drools Flow API. Is this 
area of jBPM under development? Is this going to change? Covered by jBPM only 
APIs?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/719649#719649]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to