# Process

A business process is a graph that describes the order in which a series of steps need to be executed, using a flow chart. A process consists of a collection of nodes that are linked to each other using connections. Each of the nodes represents one step in the overall process while the connections specify how to transition from one node to the other. A large selection of predefined node types have been defined. This chapter describes how to define such processes and use them in your application.

## Creating a process

Processes can be created by using one of the following three methods:

1. Using the graphical process editor such as jBPM web designer or Eclipse BPMN2 modeler

2. As an XML file, according to the XML process format as defined in the XML Schema Definition in the BPMN 2.0 specification.

3. By directly creating a process using the Process API.

### Using the graphical BPMN2 Editor

The graphical BPMN2 editor is an editor that allows you to create a process by dragging and dropping different nodes on a canvas and editing the properties of these nodes. The graphical BPMN2 modeler is an Eclipse plugin hosted on eclipse.org that provides number of contributors where one of them is jBPM project. Once you have set up a jBPM project (see the installer for creating a working Eclipse environment where you can start), you can start adding processes. When in a project, launch the "New" wizard (use Ctrl+N) or right-click the directory you would like to put your process in and select "New", then "File". Give the file a name and the extension bpmn (e.g. MyProcess.bpmn). This will open up the process editor (you can safely ignore the warning that the file could not be read, this is just because the file is still empty).

First, ensure that you can see the Properties View down the bottom of the Eclipse window, as it will be necessary to fill in the different properties of the elements in your process. If you cannot see the properties view, open it using the menu "Window", then "Show View" and "Other…​", and under the "General" folder select the Properties View.

Figure 1. New process

The process editor consists of a palette, a canvas and an outline view. To add new elements to the canvas, select the element you would like to create in the palette and then add them to the canvas by clicking on the preferred location. For example, click the "End Event" icon in the palette of the GUI. Clicking on an element in your process allows you to set the properties of that element. You can connect the nodes (as long as it is permitted by the different types of nodes) by using "Sequence Flow" from the palette.

You can keep adding nodes and connections to your process until it represents the business logic that you want to specify.

### Defining processes using XML

It is also possible to specify processes using the underlying BPMN 2.0 XML directly. The syntax of these XML processes is defined using the BPMN 2.0 XML Schema Definition. For example, the following XML fragment shows a simple process that contains a sequence of a Start Event, a Script Task that prints "Hello World" to the console, and an End Event.

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions id="Definition"
                 targetNamespace="http://www.jboss.org/drools"
                 typeLanguage="http://www.java.com/javaTypes"
                 expressionLanguage="http://www.mvel.org/2.0"
                 xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"Rule Task
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
                 xmlns:g="http://www.jboss.org/drools/flow/gpd"
                 xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
                 xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
                 xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
                 xmlns:tns="http://www.jboss.org/drools">

      <process processType="Private" isExecutable="true" id="com.sample.hello" name="Hello Process" >

        <!-- nodes -->
        <startEvent id="_1" name="Start" />
        <scriptTask id="_2" name="Hello" >
          <script>System.out.println("Hello World");</script>
        </scriptTask>
        <endEvent id="_3" name="End" >
            <terminateEventDefinition/>
        </endEvent>

        <!-- connections -->
        <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
        <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />

      </process>

      <bpmndi:BPMNDiagram>
        <bpmndi:BPMNPlane bpmnElement="com.sample.hello" >
          <bpmndi:BPMNShape bpmnElement="_1" >
            <dc:Bounds x="16" y="16" width="48" height="48" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="_2" >
            <dc:Bounds x="96" y="16" width="80" height="48" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="_3" >
            <dc:Bounds x="208" y="16" width="48" height="48" />
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="_1-_2" >
            <di:waypoint x="40" y="40" />
            <di:waypoint x="136" y="40" />
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="_2-_3" >
            <di:waypoint x="136" y="40" />
            <di:waypoint x="232" y="40" />
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>

    </definitions>

The process XML file consists of two parts, the top part (the "process" element) contains the definition of the different nodes and their properties, the lower part (the "BPMNDiagram" element) contains all graphical information, like the location of the nodes. The process XML consist of exactly one <process> element. This element contains parameters related to the process (its type, name, id and package name), and consists of three subsections: a header section (where process-level information like variables, globals, imports and lanes can be defined), a nodes section that defines each of the nodes in the process, and a connections section that contains the connections between all the nodes in the process. In the nodes section, there is a specific element for each node, defining the various parameters and, possibly, sub-elements for that node type.

Table 1. jBPM BPMN2 constructs
.The different types of BPMN2 events image::BPMN2/events1.png[] | .The different types of BPMN2 activities and gateways image::BPMN2/ActivitiesGateways.png[]

### Details: Process properties

A BPMN2 process is a flow chart where different types of nodes are linked using connections. The process itself exposes the following properties:

- Id: The unique id of the process.

- Name: The display name of the process.

- Version: The version number of the process.

- Package: The package (namespace) the process is defined in.

Figure 2. BPMN2 process properties

In addition to that following can be defined as well:

- Variables: Variables can be defined to store data during the execution of your process. See section “[_variables]” for details.

- Swimlanes: Specify the swimlanes used in this process for assigning human tasks. See chapter “[_ch.human_tasks]” for details.

Figure 3. BPMN2 process variables