<?xml version="1.0" encoding="UTF-8"?>
<!-- Leave Request (template leave-request).

     Started with: employee, startDate, endDate, leaveType.

     Leave requested
       -> Check the team calendar    user task; complete with available = true if the
                                     team is covered over these dates
       -> Team covered?              no -> Tell the employee -> Declined
       -> Manager approval           user task; complete with approved = true
       -> Approved?                  no -> Tell the employee -> Declined
       -> Record the leave with HR   user task
       -> Leave booked

     The calendar check is a person's step. To read a shared calendar instead,
     replace it with a service task whose worker sets available.

     The answers are variables their steps are completed with: available, approved. The
     template's sample variables start each of them as null, so a step closed
     without its answer takes the safe branch. A run started without them stops with
     an incident at the first gateway whose variable was never set, because the
     engine never reads a missing variable as a no, and the hosted API cannot resume
     a run in INCIDENT. -->
<definitions
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  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:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:zeebe="http://camunda.org/schema/zeebe/1.0"
  targetNamespace="http://priostack.com/templates"
  id="def_leave_request">

  <process id="leave_request" name="Leave Request" isExecutable="true">
    <documentation>An employee's leave request: the team calendar is checked, the manager approves, and HR records the leave; otherwise the employee is told why.</documentation>

    <startEvent id="leave_requested" name="Leave requested"/>

    <userTask id="check_calendar" name="Check the team calendar">
      <documentation>Is the team covered from startDate to endDate? Complete with available = true or false.</documentation>
    </userTask>

    <exclusiveGateway id="gw_available" name="Team covered?" default="f_not_covered"/>

    <userTask id="manager_approval" name="Manager approval">
      <documentation>Complete with approved = true to approve the leave, or false to decline it.</documentation>
    </userTask>

    <exclusiveGateway id="gw_approved" name="Approved?" default="f_not_approved"/>

    <userTask id="record_with_hr" name="Record the leave with HR">
      <documentation>HR takes the days off the leave balance and tells payroll.</documentation>
    </userTask>

    <endEvent id="leave_booked" name="Leave booked"/>

    <userTask id="tell_employee" name="Tell the employee">
      <documentation>Tell the employee the leave was declined and why, and suggest other dates if the team was not covered.</documentation>
    </userTask>

    <endEvent id="declined" name="Declined"/>

    <sequenceFlow id="f_requested" sourceRef="leave_requested" targetRef="check_calendar"/>
    <sequenceFlow id="f_checked" sourceRef="check_calendar" targetRef="gw_available"/>
    <sequenceFlow id="f_covered" name="yes" sourceRef="gw_available" targetRef="manager_approval">
      <conditionExpression xsi:type="tFormalExpression">available = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_not_covered" name="no" sourceRef="gw_available" targetRef="tell_employee"/>
    <sequenceFlow id="f_decided" sourceRef="manager_approval" targetRef="gw_approved"/>
    <sequenceFlow id="f_approved" name="yes" sourceRef="gw_approved" targetRef="record_with_hr">
      <conditionExpression xsi:type="tFormalExpression">approved = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_not_approved" name="no" sourceRef="gw_approved" targetRef="tell_employee"/>
    <sequenceFlow id="f_recorded" sourceRef="record_with_hr" targetRef="leave_booked"/>
    <sequenceFlow id="f_told" sourceRef="tell_employee" targetRef="declined"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_leave_request">
    <bpmndi:BPMNPlane id="plane_leave_request" bpmnElement="leave_request">
      <bpmndi:BPMNShape id="shape_leave_requested" bpmnElement="leave_requested">
        <dc:Bounds x="82" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_check_calendar" bpmnElement="check_calendar">
        <dc:Bounds x="215" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_available" bpmnElement="gw_available" isMarkerVisible="true">
        <dc:Bounds x="415" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_manager_approval" bpmnElement="manager_approval">
        <dc:Bounds x="555" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_approved" bpmnElement="gw_approved" isMarkerVisible="true">
        <dc:Bounds x="755" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_record_with_hr" bpmnElement="record_with_hr">
        <dc:Bounds x="895" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_leave_booked" bpmnElement="leave_booked">
        <dc:Bounds x="1102" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_tell_employee" bpmnElement="tell_employee">
        <dc:Bounds x="895" y="220" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_declined" bpmnElement="declined">
        <dc:Bounds x="1102" y="242" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_requested" bpmnElement="f_requested">
        <di:waypoint x="118" y="120"/>
        <di:waypoint x="215" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_checked" bpmnElement="f_checked">
        <di:waypoint x="325" y="120"/>
        <di:waypoint x="415" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_covered" bpmnElement="f_covered">
        <di:waypoint x="465" y="120"/>
        <di:waypoint x="555" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_not_covered" bpmnElement="f_not_covered">
        <di:waypoint x="440" y="145"/>
        <di:waypoint x="440" y="260"/>
        <di:waypoint x="895" y="260"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_decided" bpmnElement="f_decided">
        <di:waypoint x="665" y="120"/>
        <di:waypoint x="755" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_approved" bpmnElement="f_approved">
        <di:waypoint x="805" y="120"/>
        <di:waypoint x="895" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_not_approved" bpmnElement="f_not_approved">
        <di:waypoint x="780" y="145"/>
        <di:waypoint x="780" y="260"/>
        <di:waypoint x="895" y="260"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_recorded" bpmnElement="f_recorded">
        <di:waypoint x="1005" y="120"/>
        <di:waypoint x="1102" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_told" bpmnElement="f_told">
        <di:waypoint x="1005" y="260"/>
        <di:waypoint x="1102" y="260"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
