I have create a business process flow using fluent API. I have few questions:
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory
.name("HelloWorldProcess")
.version("1.0")
.packageName("org.jbpm")
.startNode(1).name("Start").done()
.endNode(2).name("End").done()
// Connections
.connection(1, 2)
.build();
Where HelloWorld.bpmn file will be created?
For executing a process, you should create a Resource
, which is used to create a KieBase
. Using that KieBase
, you can create a KieSession
to execute the process.
Using ProcessBuilderFactory.toBytes
for that process definition will create a ByteArrayResource resource.
// Build resource from Process
KieResources resources = ServiceRegistry.getInstance().get(KieResources.class);
Resource res = resources
.newByteArrayResource(factory.toBytes(process))
Or, in your case, from the RuleFlowProcess
process:
Resource res = ResourceFactory
.newByteArrayResource(
XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
kieModule
is automatically deployed to KieRepository
if successfully built with buildAll()
.
Take a look at the following example:
// source path or target path must be set to be added into kbase
res.setSourcePath("/tmp/processFactory.bpmn2");
// Build kie base from this resource using KIE API
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(res);
KieBuilder kb = ks.newKieBuilder(kfs);
// kieModule is automatically deployed to KieRepository if successfully built.
kb.buildAll();
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieBase kbase = kContainer.getKieBase();
// Create kie session using KieBase
KieSessionConfiguration conf = ...;
Environment env = ....;
KieSession ksession = kbase.newKieSession(conf,env);
// execute process using same process Id that is used to obtain ProcessBuilder instance
ksession.startProcess("org.jbpm.HelloWorld")