<?xml version="1.0" encoding="UTF-8"?>
<!-- Audit Workflow (template audit-workflow).

     Started with: auditType, period, auditor.
     Deploy audit_investigation.cmmn with it: the evidence is gathered in that case.

     Audit planned
       -> Define the scope            user task; complete with scope
       -> Collect the evidence        user task: start the audit_investigation case with
                                      the same auditType and period, and complete this
                                      step when the case is complete, with caseKey
       -> Review the findings         user task; complete with findingsSeverity =
                                      "none", "minor" or "major"
       -> Major findings?             yes -> Agree a remediation plan
       -> Write the audit report      user task
       -> Sign off the report         user task; complete with signedOff = true
       -> Signed off?                 no -> back to Write the audit report
       -> Report issued

     A process does not start a case on this engine (a CMMN process task is a job
     too), so the evidence step is where a person runs the case.

     The answers are variables their steps are completed with: findingsSeverity, signedOff. 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_audit_workflow">

  <process id="audit_workflow" name="Audit Workflow" isExecutable="true">
    <documentation>An internal audit: the scope, the evidence gathered in the audit_investigation case, the findings reviewed, a remediation plan for major findings, and the report signed off.</documentation>

    <startEvent id="audit_planned" name="Audit planned"/>

    <userTask id="define_scope" name="Define the scope">
      <documentation>The processes, accounts and risks in scope for the period. Complete with scope.</documentation>
    </userTask>

    <userTask id="collect_evidence" name="Collect the evidence">
      <documentation>Start the audit_investigation case with the same auditType and period. Complete this step when the case is complete, with caseKey = the case's key.</documentation>
    </userTask>

    <userTask id="review_findings" name="Review the findings">
      <documentation>Go through each finding with its process owner. Complete with findingsSeverity = "none", "minor" or "major".</documentation>
    </userTask>

    <exclusiveGateway id="gw_major" name="Major findings?" default="f_no_major"/>

    <userTask id="agree_remediation" name="Agree a remediation plan">
      <documentation>Management commits to an action, an owner and a date for each major finding.</documentation>
    </userTask>

    <userTask id="write_report" name="Write the audit report">
      <documentation>Scope, work done, findings with their severity, and the remediation agreed.</documentation>
    </userTask>

    <userTask id="sign_off_report" name="Sign off the report">
      <documentation>The audit committee signs. Complete with signedOff = true, or false to send the report back for changes.</documentation>
    </userTask>

    <exclusiveGateway id="gw_signed" name="Signed off?" default="f_send_back"/>

    <endEvent id="report_issued" name="Report issued"/>

    <sequenceFlow id="f_planned" sourceRef="audit_planned" targetRef="define_scope"/>
    <sequenceFlow id="f_scoped" sourceRef="define_scope" targetRef="collect_evidence"/>
    <sequenceFlow id="f_evidence_in" sourceRef="collect_evidence" targetRef="review_findings"/>
    <sequenceFlow id="f_reviewed" sourceRef="review_findings" targetRef="gw_major"/>
    <sequenceFlow id="f_major" name="major" sourceRef="gw_major" targetRef="agree_remediation">
      <conditionExpression xsi:type="tFormalExpression">findingsSeverity = "major"</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_no_major" name="none or minor" sourceRef="gw_major" targetRef="write_report"/>
    <sequenceFlow id="f_remediation_agreed" sourceRef="agree_remediation" targetRef="write_report"/>
    <sequenceFlow id="f_report_written" sourceRef="write_report" targetRef="sign_off_report"/>
    <sequenceFlow id="f_sign_off_done" sourceRef="sign_off_report" targetRef="gw_signed"/>
    <sequenceFlow id="f_signed" name="yes" sourceRef="gw_signed" targetRef="report_issued">
      <conditionExpression xsi:type="tFormalExpression">signedOff = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_send_back" name="no, back for changes" sourceRef="gw_signed" targetRef="write_report"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_audit_workflow">
    <bpmndi:BPMNPlane id="plane_audit_workflow" bpmnElement="audit_workflow">
      <bpmndi:BPMNShape id="shape_audit_planned" bpmnElement="audit_planned">
        <dc:Bounds x="82" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_define_scope" bpmnElement="define_scope">
        <dc:Bounds x="215" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_collect_evidence" bpmnElement="collect_evidence">
        <dc:Bounds x="385" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_review_findings" bpmnElement="review_findings">
        <dc:Bounds x="555" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_major" bpmnElement="gw_major" isMarkerVisible="true">
        <dc:Bounds x="755" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_agree_remediation" bpmnElement="agree_remediation">
        <dc:Bounds x="895" y="220" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_write_report" bpmnElement="write_report">
        <dc:Bounds x="1065" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_sign_off_report" bpmnElement="sign_off_report">
        <dc:Bounds x="1235" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_signed" bpmnElement="gw_signed" isMarkerVisible="true">
        <dc:Bounds x="1435" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_report_issued" bpmnElement="report_issued">
        <dc:Bounds x="1612" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_planned" bpmnElement="f_planned">
        <di:waypoint x="118" y="120"/>
        <di:waypoint x="215" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_scoped" bpmnElement="f_scoped">
        <di:waypoint x="325" y="120"/>
        <di:waypoint x="385" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_evidence_in" bpmnElement="f_evidence_in">
        <di:waypoint x="495" y="120"/>
        <di:waypoint x="555" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_reviewed" bpmnElement="f_reviewed">
        <di:waypoint x="665" y="120"/>
        <di:waypoint x="755" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_major" bpmnElement="f_major">
        <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_no_major" bpmnElement="f_no_major">
        <di:waypoint x="805" y="120"/>
        <di:waypoint x="1065" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_remediation_agreed" bpmnElement="f_remediation_agreed">
        <di:waypoint x="1005" y="260"/>
        <di:waypoint x="1035" y="260"/>
        <di:waypoint x="1035" y="120"/>
        <di:waypoint x="1065" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_report_written" bpmnElement="f_report_written">
        <di:waypoint x="1175" y="120"/>
        <di:waypoint x="1235" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_sign_off_done" bpmnElement="f_sign_off_done">
        <di:waypoint x="1345" y="120"/>
        <di:waypoint x="1435" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_signed" bpmnElement="f_signed">
        <di:waypoint x="1485" y="120"/>
        <di:waypoint x="1612" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_send_back" bpmnElement="f_send_back">
        <di:waypoint x="1460" y="145"/>
        <di:waypoint x="1460" y="205"/>
        <di:waypoint x="1120" y="205"/>
        <di:waypoint x="1120" y="160"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
