# 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
                    factory.processBuilder(processId)
                           // package and name
                           .packageName("org.jbpm")
                           .name("My process")
                           // start node
                           .startNode(1).name("Start").done()
                           // 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"
                           .actionNode(2).name("Action")
                           .action(Dialect.JAVA,
                                   "System.out.println(\"Action\");").done()
                           // end node
                           .endNode(3).name("End").done()
                           // connections
                           .connection(1,
                                       2)
                           .connection(2,
                                       3)
                           .build();

- 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
                                    .newByteArrayResource(factory.toBytes(process))
                                    .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();
            kfs.write(res);
            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
            ksession.startProcess(processId);

- Interface Summary
  Interface | Description
  --- | ---
  ActionNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  BoundaryEventNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  CompositeNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  CompositeNodeOperations<T extends NodeContainerBuilder<T,​P>,​P extends NodeContainerBuilder<P,​?>> |
  DynamicNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  EndNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  EventNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  FaultNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  ForEachNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  HumanTaskNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  JoinNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  MilestoneNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  NodeBuilder<T extends NodeBuilder<T,​P>,​P extends NodeContainerBuilder<P,​?>> | Contains common operations for all nodes, basically naming, metadata and definition completion.
  NodeContainerBuilder<T extends NodeContainerBuilder<T,​P>,​P extends NodeContainerBuilder<P,​?>> | Include operations to define a container node. As it name indicates, a container node contains nodes (a process is also a container node), so this class defines all methods to create children nodes. A container node also holds variables, exception handlers and establish connections between nodes.
  ProcessBuilder | Builder that contains methods to create a process definition.
  ProcessBuilderFactory | Factory to create process builder instance. It is also a convenient place holder for additional utility methods
  RuleSetNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  SplitNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  StartNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  SubProcessNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  TimerNodeBuilder<T extends NodeContainerBuilder<T,​?>> |
  WorkItemNodeBuilder<T extends NodeContainerBuilder<T,​?>> |

- Class Summary
  Class | Description
  --- | ---
  ProcessBuilderFactories | Holds an utility method to retrieve `ProcessBuilderFactory` default instance. Default instance returned by `get` method can be modified by setting property "org.jbpm.processBuilder.factoryClass" Value should be full class name of a `ProcessBuilderFactory` implementation that contains a default public constructor
  Variable<T> | Builder pattern like class used to build a variable. A variable requires a name and a data type. Value and metadata are optional. Usage:

- Enum Summary
  Enum | Description
  --- | ---
  Dialect | Supported programming languages for action scripts