<?xml version="1.0" encoding="UTF-8"?>
<!-- Document Review & Sign-off (template document-review).

     Started with: documentTitle, author, reviewers (a list of names, up to 16).

     Draft ready for review
       -> Review the document       one user task per name in reviewers, all at the
                                    same time; each task carries its reviewer
       -> Consolidate the feedback  user task for the author, once every review is in
       -> Final sign-off            user task; complete with signedOff = true
       -> Signed off?               no -> back to Consolidate the feedback
       -> Signed off

     Reviewers comment in the document itself. The engine keeps one value per
     variable, so a reviewer's answer would be overwritten by the next one's: the
     decision belongs to the author and the signer. A list of more than 16
     reviewers stops the run rather than skipping anyone.

     The answers are variables their steps are completed with: 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_document_review">

  <process id="document_review" name="Document Review &amp; Sign-off" isExecutable="true">
    <documentation>A document reviewed by every reviewer at the same time, the feedback consolidated by its author, and a final sign-off that can send it back for another pass.</documentation>

    <startEvent id="draft_ready" name="Draft ready for review"/>

    <userTask id="review" name="Review the document">
      <documentation>One task per reviewer, all at the same time. Read the draft and comment in the document itself.</documentation>
      <multiInstanceLoopCharacteristics>
        <extensionElements>
          <zeebe:loopCharacteristics inputCollection="=reviewers" inputElement="reviewer"/>
        </extensionElements>
      </multiInstanceLoopCharacteristics>
    </userTask>

    <userTask id="consolidate" name="Consolidate the feedback">
      <documentation>The author applies or answers every comment, then sends the document for sign-off.</documentation>
    </userTask>

    <userTask id="sign_off" name="Final sign-off">
      <documentation>Complete with signedOff = true to sign, or false to send it back to the author with your comments.</documentation>
    </userTask>

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

    <endEvent id="signed" name="Signed off"/>

    <sequenceFlow id="f_ready" sourceRef="draft_ready" targetRef="review"/>
    <sequenceFlow id="f_reviewed" sourceRef="review" targetRef="consolidate"/>
    <sequenceFlow id="f_consolidated" sourceRef="consolidate" targetRef="sign_off"/>
    <sequenceFlow id="f_sign_off_done" sourceRef="sign_off" targetRef="gw_signed"/>
    <sequenceFlow id="f_signed" name="yes" sourceRef="gw_signed" targetRef="signed">
      <conditionExpression xsi:type="tFormalExpression">signedOff = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_send_back" name="no, back to the author" sourceRef="gw_signed" targetRef="consolidate"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_document_review">
    <bpmndi:BPMNPlane id="plane_document_review" bpmnElement="document_review">
      <bpmndi:BPMNShape id="shape_draft_ready" bpmnElement="draft_ready">
        <dc:Bounds x="82" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_review" bpmnElement="review">
        <dc:Bounds x="215" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_consolidate" bpmnElement="consolidate">
        <dc:Bounds x="385" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_sign_off" bpmnElement="sign_off">
        <dc:Bounds x="555" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_signed" bpmnElement="gw_signed" isMarkerVisible="true">
        <dc:Bounds x="755" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_signed" bpmnElement="signed">
        <dc:Bounds x="932" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_ready" bpmnElement="f_ready">
        <di:waypoint x="118" y="120"/>
        <di:waypoint x="215" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_reviewed" bpmnElement="f_reviewed">
        <di:waypoint x="325" y="120"/>
        <di:waypoint x="385" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_consolidated" bpmnElement="f_consolidated">
        <di:waypoint x="495" y="120"/>
        <di:waypoint x="555" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_sign_off_done" bpmnElement="f_sign_off_done">
        <di:waypoint x="665" y="120"/>
        <di:waypoint x="755" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_signed" bpmnElement="f_signed">
        <di:waypoint x="805" y="120"/>
        <di:waypoint x="932" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_send_back" bpmnElement="f_send_back">
        <di:waypoint x="780" y="145"/>
        <di:waypoint x="780" y="205"/>
        <di:waypoint x="440" y="205"/>
        <di:waypoint x="440" y="160"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
