Time for action – implementing a parallel gateway

We will implement a process with a parallel gateway by performing the following steps:

  1. We will use an example of a leave process. When an employee applies for leave, the request is sent to the project manager and team leader in parallel and then sent to Human Resources:
    Time for action – implementing a parallel gateway
  2. You can populate the form properties for accepting values from the employee on the start event, as shown in the following code:
    <startEvent id="sid-2BB933AE-E0AE-48D2-9ACC-B5EC35AD3687">
          <extensionElements>
            <activiti:formProperty id="empName" name="Employee Name" type="string" required="true"></activiti:formProperty>
            <activiti:formProperty id="empDesignation" name="Employee Designation" type="string" required="true"></activiti:formProperty>
            <activiti:formProperty id="empLeaveReason" name="Leave Reason" type="string" required="true"></activiti:formProperty>
            <activiti:formProperty id="empLeaveDays" name="No of Days Leave " type="long" required="true"></activiti:formProperty>
          </extensionElements>
        </startEvent>
  3. Create a user task for the team leader and project manager, who will be able to view the details filled by the employee. Then, based on the details, they can either accept or reject the leave, as shown in the following code:
    <userTask id="sid-03BC7128-4496-4027-88A9-E67D3DA63734" name="Project Manager" activiti:assignee="gonzo">
          <extensionElements>
            <activiti:formProperty id="eName" name="Employee Name" type="string" expression="${empName}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eDesig" name="Employee Designation" type="string" expression="${empDesignation}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveReason" name="Leave Reason" type="string" expression="${empLeaveReason}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveDays" name="Leave Days" type="long" expression="${empLeaveDays}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="pmDecision" name="Do You Approve ?" type="enum" required="true">
              <activiti:value id="true" name="Yes"></activiti:value>
              <activiti:value id="false" name="No"></activiti:value>
            </activiti:formProperty>
            <activiti:formProperty id="pmComment" name="Your Comment" type="string" required="true"></activiti:formProperty>
          </extensionElements>
        </userTask>
        <userTask id="sid-7581049C-894E-4FF9-B861-7DF44B7229E3" name="Team Leader" activiti:assignee="fozzie">
          <extensionElements>
            <activiti:formProperty id="eName" name="Employee Name" type="string" expression="${empName}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eDesig" name="Employee Designation" type="string" expression="${empDesignation}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveReason" name="Leave Reason" type="string" expression="${empLeaveReason}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveDays" name="Leave Days" type="long" expression="${empLeaveDays}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="tlDecision" name="Do You Approve ?" type="enum" required="true">
              <activiti:value id="true" name="Yes"></activiti:value>
              <activiti:value id="false" name="No"></activiti:value>
            </activiti:formProperty>
            <activiti:formProperty id="tlComment" name="Your Comment" type="string" required="true"></activiti:formProperty>
          </extensionElements>
        </userTask>
  4. Now, create a parallel gateway to connect to the Team Leader and Project Manager tasks that are to be executed in parallel, as shown in the following code:
     <sequenceFlow id="flow1" sourceRef="sid-2BB933AE-E0AE-48D2-9ACC-B5EC35AD3687" targetRef="parallelgateway1"></sequenceFlow>
        <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway>
        <sequenceFlow id="flow2" sourceRef="parallelgateway1" targetRef="sid-03BC7128-4496-4027-88A9-E67D3DA63734"></sequenceFlow>
        <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="sid-7581049C-894E-4FF9-B861-7DF44B7229E3"></sequenceFlow>
  5. Create a Human Resource user task where all the details from the employee, project manager, and team leader will be viewed, and based on the results of the Project Manager and Team Leader tasks, HR will either approve or reject the leave, as shown in the following code:
    <userTask id="usertask1" name="Human Resource">
          <extensionElements>
            <activiti:formProperty id="eName" name="Employee Name" type="string" expression="${empName}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eDesig" name="Employee Designation" type="string" expression="${empDesignation}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveReason" name="Leave Reason" type="string" expression="${empLeaveReason}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="eLeaveDays" name="Leave Days" type="long" expression="${empLeaveDays}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="hrDecision" name="Do You Approve ?" type="enum" required="true">
              <activiti:value id="true" name="Yes"></activiti:value>
              <activiti:value id="false" name="No"></activiti:value>
            </activiti:formProperty>
            <activiti:formProperty id="hrComment" name="Your Comment" type="string" required="true"></activiti:formProperty>
            <activiti:formProperty id="tlComments" name="TL Comments" type="string" expression="${tlComment}" writable="false"></activiti:formProperty>
            <activiti:formProperty id="pmComments" name="Project Manager Comments" type="string" expression="${pmComment}" writable="false"></activiti:formProperty>
          </extensionElements>
        </userTask>
  6. We need to join the parallel gateways so that we can get the appropriate results, as shown in the following code:
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="sid-65043A85-6BAD-4616-AD1E-FF3FA8D64D4B"></sequenceFlow>
        <sequenceFlow id="flow6" sourceRef="sid-03BC7128-4496-4027-88A9-E67D3DA63734" targetRef="parallelgateway2"></sequenceFlow>
        <sequenceFlow id="flow7" sourceRef="sid-7581049C-894E-4FF9-B861-7DF44B7229E3" targetRef="parallelgateway2"></sequenceFlow>
        <sequenceFlow id="flow8" sourceRef="parallelgateway2" targetRef="usertask1"></sequenceFlow>
        <parallelGateway id="parallelgateway2" name="Exclusive Gateway"></parallelGateway>
  7. Now, to execute the process, deploy it into the Activiti Explorer, start it, and fill in the details for the leave, as shown in the following screenshot:
    Time for action – implementing a parallel gateway
  8. To view the state of your process, navigate to the My Instances tab. As seen in the following screenshot, the Project Manager and Team Leader process are in execution:
    Time for action – implementing a parallel gateway
  9. Log in with gonzo as the user, as we have assigned the Project Manager task to him. The values added by the employee will be visible to him; now, the PM can accept or reject the leave and provide comments as shown in the following screenshot:
    Time for action – implementing a parallel gateway
  10. Now log in with fozzie, as the Team Leader task is assigned to him. Here, too, the details added by the employee will be available, as you can view in the following screenshot:
    Time for action – implementing a parallel gateway
  11. Now log in with kermit, as he is assigned the Human Resource task. In this task, the details provided by the employee as well as the comments provided by the PM and TL will be available, as shown in the following screenshot:
    Time for action – implementing a parallel gateway

What just happened?

We went through a process that had a certain task to be completed in parallel, and we used a parallel gateway to achieve this functionality. Now you must be aware of when to use a parallel gateway.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset