Package org.kie.api.fluent

Process Fluent API allows programmer to build an in memory representation of a bpmn file.
This information can later be used to build a KIE resource and execute the process . Typical use of fluent API will be:
  • Build a process definition that prints action string in console using ProcessBuilder several methods
  •         // Obtain default ProcessBuilderFactory
            ProcessBuilderFactory factory = ProcessBuilderFactories.get();
                    ProcessBuilderFactory factory = ProcessBuilderFactories.get();
            Process process =
                    // Create process builder
                           // package and name 
                           .name("My process")
                           // start node
                           // Add variable of type string
                           .variable(var("pepe", String.class))
                           // Add exception handler
                           .exceptionHandler(IllegalArgumentException.class, Dialect.JAVA, "System.out.println(\"Exception\");")
                           // script node in Java language that prints "action"
                           // end node
                           // connections
  • Create a resource from the process definition (process needs to be converted to byte[] using ProcessBuilderFactory)
  •         // Build resource from ProcessBuilder
            KieResources resources = ServiceRegistry.getInstance().get(KieResources.class);
            Resource res = resources
                                    .setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase
  • Build kie base from this resource using KIE API
  •         KieServices ks = KieServices.Factory.get();
            KieRepository kr = ks.getRepository();
            KieFileSystem kfs = ks.newKieFileSystem();
            KieBuilder kb = ks.newKieBuilder(kfs);
            kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built.
            KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
            KieBase kbase = kContainer.getKieBase();
  • Create kie session using this kie base and execute the process
  •         // Create kie session
            KieSessionConfiguration conf = ...;
            Environment env = ....; 
            KieSession ksession = kbase.newKieSession(conf,env);
            // execute process using same process id that was used to obtain ProcessBuilder instance