<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
    xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
    typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
    targetNamespace="http://www.activiti.org/processdef">
    <process id="acmDocumentWorkflow" name="ACM Document Approval Process - Review" isExecutable="true">
        <startEvent id="startDocumentApproval" name="Document Author Submits Request to Approve Document"></startEvent>
        <userTask id="approverReviewsDocument" name="Review ${taskName}"
            activiti:candidateGroups="${execution.getVariable('candidateGroups') == null ? '' : candidateGroups}"
            activiti:assignee="${currentReviewer}" activiti:dueDate="P3D" activiti:priority="50">
            <extensionElements>
                <activiti:formProperty id="reviewOutcome" name="Review Outcome" type="enum" required="true">
                    <activiti:value id="APPROVE" name="Approve Document"></activiti:value>
                    <activiti:value id="SEND_FOR_REWORK" name="Send for Rework"></activiti:value>
                </activiti:formProperty>
            </extensionElements>
            <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="reviewers"
                activiti:elementVariable="currentReviewer">
                <completionCondition>${ (nrOfCompletedInstances == nrOfInstances) || reviewOutcome == 'SEND_FOR_REWORK'}
                </completionCondition>
            </multiInstanceLoopCharacteristics>
        </userTask>
        <endEvent id="endDocumentApprovalWorkflow"></endEvent>
        <userTask id="authorReworksDocument" name="Rework ${taskName}"
            activiti:candidateGroups="${execution.getVariable('candidateGroups') == null ? '' : candidateGroups}"
            activiti:assignee="${documentAuthor}" activiti:dueDate="P3D" activiti:priority="75">
            <extensionElements>
                <activiti:formProperty id="reworkOutcome" name="Rework Outcome" type="enum" required="true">
                    <activiti:value id="RESUBMIT" name="Resubmit"></activiti:value>
                    <activiti:value id="CANCEL_DOCUMENT" name="Cancel Document (Ends Approval Workflow)"></activiti:value>
                </activiti:formProperty>
            </extensionElements>
        </userTask>
        <manualTask id="systemSetsDocStateToApproved" name="System Sets Document State to Approved"></manualTask>
        <sequenceFlow id="approvedToEnd" sourceRef="systemSetsDocStateToApproved" targetRef="setObjectApprovedStatus"></sequenceFlow>
        <exclusiveGateway id="reviewDecision"></exclusiveGateway>
        <exclusiveGateway id="reworkOutcome"></exclusiveGateway>
        <sequenceFlow id="reworkToCancel" name="Cancel" sourceRef="reworkOutcome" targetRef="setObjectDraftStatus">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reworkOutcome == 'CANCEL_DOCUMENT'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="startToReview" sourceRef="startDocumentApproval" targetRef="approverReviewsDocument"></sequenceFlow>
        <sequenceFlow id="reworkToGateway" sourceRef="authorReworksDocument" targetRef="reworkOutcome"></sequenceFlow>
        <sequenceFlow id="documentReviewedToRework" name="Send for Rework" sourceRef="reviewDecision" targetRef="authorReworksDocument">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reviewOutcome == 'SEND_FOR_REWORK'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="documentApprovedToSetDocState" name="Approve" sourceRef="reviewDecision" targetRef="systemSetsDocStateToApproved">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reviewOutcome == 'APPROVE'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="reviewToGateway" sourceRef="approverReviewsDocument" targetRef="reviewDecision"></sequenceFlow>
        <sequenceFlow id="reworkToReview" name="Submit Rework" sourceRef="reworkOutcome" targetRef="approverReviewsDocument">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reworkOutcome == 'RESUBMIT'}]]></conditionExpression>
        </sequenceFlow>
        <serviceTask id="setObjectApprovedStatus" name="Set Object Approved Status"
            activiti:expression="#{changeObjectStatusService.change(OBJECT_ID, OBJECT_TYPE, 'APPROVED')}"></serviceTask>
        <sequenceFlow id="flow1" sourceRef="setObjectApprovedStatus" targetRef="endDocumentApprovalWorkflow"></sequenceFlow>
        <serviceTask id="setObjectDraftStatus" name="Set Object Draft Status"
            activiti:expression="#{changeObjectStatusService.change(OBJECT_ID, OBJECT_TYPE, 'DRAFT')}"></serviceTask>
        <sequenceFlow id="flow2" sourceRef="setObjectDraftStatus" targetRef="endDocumentApprovalWorkflow"></sequenceFlow>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_acmDocumentWorkflow">
        <bpmndi:BPMNPlane bpmnElement="acmDocumentWorkflow" id="BPMNPlane_acmDocumentWorkflow">
            <bpmndi:BPMNShape bpmnElement="startDocumentApproval" id="BPMNShape_startDocumentApproval">
                <omgdc:Bounds height="35.0" width="35.0" x="135.0" y="106.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="approverReviewsDocument" id="BPMNShape_approverReviewsDocument">
                <omgdc:Bounds height="82.0" width="144.0" x="315.0" y="80.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endDocumentApprovalWorkflow" id="BPMNShape_endDocumentApprovalWorkflow">
                <omgdc:Bounds height="35.0" width="35.0" x="950.0" y="103.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="authorReworksDocument" id="BPMNShape_authorReworksDocument">
                <omgdc:Bounds height="82.0" width="144.0" x="638.0" y="150.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="systemSetsDocStateToApproved" id="BPMNShape_systemSetsDocStateToApproved">
                <omgdc:Bounds height="80.0" width="100.0" x="660.0" y="15.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="reviewDecision" id="BPMNShape_reviewDecision">
                <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="101.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="reworkOutcome" id="BPMNShape_reworkOutcome">
                <omgdc:Bounds height="40.0" width="40.0" x="690.0" y="345.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="setObjectApprovedStatus" id="BPMNShape_setObjectApprovedStatus">
                <omgdc:Bounds height="61.0" width="105.0" x="800.0" y="90.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="setObjectDraftStatus" id="BPMNShape_setObjectDraftStatus">
                <omgdc:Bounds height="62.0" width="105.0" x="800.0" y="179.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="approvedToEnd" id="BPMNEdge_approvedToEnd">
                <omgdi:waypoint x="760.0" y="55.0"></omgdi:waypoint>
                <omgdi:waypoint x="854.0" y="55.0"></omgdi:waypoint>
                <omgdi:waypoint x="852.0" y="90.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="reworkToCancel" id="BPMNEdge_reworkToCancel">
                <omgdi:waypoint x="730.0" y="365.0"></omgdi:waypoint>
                <omgdi:waypoint x="854.0" y="365.0"></omgdi:waypoint>
                <omgdi:waypoint x="852.0" y="241.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="33.0" x="740.0" y="365.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="startToReview" id="BPMNEdge_startToReview">
                <omgdi:waypoint x="170.0" y="123.0"></omgdi:waypoint>
                <omgdi:waypoint x="315.0" y="121.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="reworkToGateway" id="BPMNEdge_reworkToGateway">
                <omgdi:waypoint x="710.0" y="232.0"></omgdi:waypoint>
                <omgdi:waypoint x="710.0" y="288.0"></omgdi:waypoint>
                <omgdi:waypoint x="711.0" y="288.0"></omgdi:waypoint>
                <omgdi:waypoint x="710.0" y="345.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="documentReviewedToRework" id="BPMNEdge_documentReviewedToRework">
                <omgdi:waypoint x="545.0" y="141.0"></omgdi:waypoint>
                <omgdi:waypoint x="545.0" y="191.0"></omgdi:waypoint>
                <omgdi:waypoint x="638.0" y="191.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="83.0" x="555.0" y="141.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="documentApprovedToSetDocState" id="BPMNEdge_documentApprovedToSetDocState">
                <omgdi:waypoint x="545.0" y="101.0"></omgdi:waypoint>
                <omgdi:waypoint x="547.0" y="55.0"></omgdi:waypoint>
                <omgdi:waypoint x="660.0" y="55.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="42.0" x="555.0" y="101.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="reviewToGateway" id="BPMNEdge_reviewToGateway">
                <omgdi:waypoint x="459.0" y="121.0"></omgdi:waypoint>
                <omgdi:waypoint x="525.0" y="121.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="reworkToReview" id="BPMNEdge_reworkToReview">
                <omgdi:waypoint x="710.0" y="345.0"></omgdi:waypoint>
                <omgdi:waypoint x="387.0" y="162.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds height="14.0" width="73.0" x="720.0" y="345.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="905.0" y="120.0"></omgdi:waypoint>
                <omgdi:waypoint x="950.0" y="120.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
                <omgdi:waypoint x="905.0" y="210.0"></omgdi:waypoint>
                <omgdi:waypoint x="967.0" y="206.0"></omgdi:waypoint>
                <omgdi:waypoint x="967.0" y="138.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>
