<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="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" id="definitions" name="Book purchase: choreography" targetNamespace="http://bpmn.io/schema/bpmn" exporter="tok" exporterVersion="1.0">
  <bpmn:message id="Message_Order" name="Order" />
  <bpmn:message id="Message_Order_confirmation" name="Order confirmation" />
  <bpmn:message id="Message_Parcel_and_invoice" name="Parcel and invoice" />
  <bpmn:message id="Message_Out_of_stock_notice" name="Out of stock notice" />
  <bpmn:collaboration id="collaboration">
    <bpmn:participant id="library" name="Library" />
    <bpmn:participant id="supplier" name="Book supplier" />
  </bpmn:collaboration>
  <bpmn:choreography id="purchase" name="Book purchase">
    <bpmn:participant id="purchase-library" name="Library" />
    <bpmn:participant id="purchase-supplier" name="Book supplier" />
    <bpmn:messageFlow id="order-message" sourceRef="purchase-library" targetRef="purchase-supplier" messageRef="Message_Order" />
    <bpmn:messageFlow id="order-reply" sourceRef="purchase-supplier" targetRef="purchase-library" messageRef="Message_Order_confirmation" />
    <bpmn:messageFlow id="ship-message" sourceRef="purchase-supplier" targetRef="purchase-library" messageRef="Message_Parcel_and_invoice" />
    <bpmn:messageFlow id="decline-message" sourceRef="purchase-supplier" targetRef="purchase-library" messageRef="Message_Out_of_stock_notice" />
    <bpmn:startEvent id="need" name="Purchase approved" />
    <bpmn:choreographyTask id="order" name="Place the order" initiatingParticipantRef="purchase-library">
      <bpmn:participantRef>purchase-library</bpmn:participantRef>
      <bpmn:participantRef>purchase-supplier</bpmn:participantRef>
      <bpmn:messageFlowRef>order-message</bpmn:messageFlowRef>
      <bpmn:messageFlowRef>order-reply</bpmn:messageFlowRef>
    </bpmn:choreographyTask>
    <bpmn:exclusiveGateway id="stock" name="Is the book in stock?" default="f-stock-ship" />
    <bpmn:choreographyTask id="ship" name="Ship the book" initiatingParticipantRef="purchase-supplier">
      <bpmn:participantRef>purchase-supplier</bpmn:participantRef>
      <bpmn:participantRef>purchase-library</bpmn:participantRef>
      <bpmn:messageFlowRef>ship-message</bpmn:messageFlowRef>
    </bpmn:choreographyTask>
    <bpmn:choreographyTask id="decline" name="Decline the order" initiatingParticipantRef="purchase-supplier">
      <bpmn:participantRef>purchase-supplier</bpmn:participantRef>
      <bpmn:participantRef>purchase-library</bpmn:participantRef>
      <bpmn:messageFlowRef>decline-message</bpmn:messageFlowRef>
    </bpmn:choreographyTask>
    <bpmn:endEvent id="delivered" name="Book delivered" />
    <bpmn:endEvent id="declined" name="Order declined" />
    <bpmn:sequenceFlow id="f-need-order" sourceRef="need" targetRef="order" />
    <bpmn:sequenceFlow id="f-order-stock" sourceRef="order" targetRef="stock" />
    <bpmn:sequenceFlow id="f-stock-ship" name="yes" sourceRef="stock" targetRef="ship" />
    <bpmn:sequenceFlow id="f-stock-decline" name="no" sourceRef="stock" targetRef="decline">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">in_stock = false</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="f-ship-delivered" sourceRef="ship" targetRef="delivered" />
    <bpmn:sequenceFlow id="f-decline-declined" sourceRef="decline" targetRef="declined" />
  </bpmn:choreography>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="collaboration">
      <bpmndi:BPMNShape id="library_di" bpmnElement="library" isHorizontal="true">
        <dc:Bounds x="0" y="0" width="600" height="70" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="supplier_di" bpmnElement="supplier" isHorizontal="true">
        <dc:Bounds x="0" y="110" width="600" height="70" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
  <bpmndi:BPMNDiagram id="BPMNDiagram_purchase">
    <bpmndi:BPMNPlane id="BPMNPlane_purchase" bpmnElement="purchase">
      <bpmndi:BPMNShape id="need_di" bpmnElement="need">
        <dc:Bounds x="30" y="322" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="0" y="363" width="96" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="order_di" bpmnElement="order">
        <dc:Bounds x="116" y="290" width="110" height="100" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="stock_di" bpmnElement="stock">
        <dc:Bounds x="276" y="315" width="50" height="50" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="306" y="368" width="62" height="23" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ship_di" bpmnElement="ship">
        <dc:Bounds x="376" y="290" width="110" height="100" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="decline_di" bpmnElement="decline">
        <dc:Bounds x="376" y="480" width="110" height="100" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="delivered_di" bpmnElement="delivered">
        <dc:Bounds x="536" y="322" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="514" y="363" width="80" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="declined_di" bpmnElement="declined">
        <dc:Bounds x="536" y="512" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="514" y="553" width="80" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="f-need-order_di" bpmnElement="f-need-order">
        <di:waypoint x="66" y="340" />
        <di:waypoint x="116" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-order-stock_di" bpmnElement="f-order-stock">
        <di:waypoint x="226" y="340" />
        <di:waypoint x="276" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-stock-ship_di" bpmnElement="f-stock-ship">
        <di:waypoint x="326" y="340" />
        <di:waypoint x="376" y="340" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="333" y="325" width="18" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-stock-decline_di" bpmnElement="f-stock-decline">
        <di:waypoint x="301" y="365" />
        <di:waypoint x="301" y="530" />
        <di:waypoint x="376" y="530" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="309" y="515" width="12" height="11" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-ship-delivered_di" bpmnElement="f-ship-delivered">
        <di:waypoint x="486" y="340" />
        <di:waypoint x="536" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="f-decline-declined_di" bpmnElement="f-decline-declined">
        <di:waypoint x="486" y="530" />
        <di:waypoint x="536" y="530" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="order-purchase-library_di" bpmnElement="purchase-library" isMessageVisible="true" participantBandKind="top_initiating" choreographyActivityShape="order_di">
        <dc:Bounds x="116" y="290" width="110" height="20" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="order-purchase-supplier_di" bpmnElement="purchase-supplier" isMessageVisible="true" participantBandKind="bottom_non_initiating" choreographyActivityShape="order_di">
        <dc:Bounds x="116" y="370" width="110" height="20" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ship-purchase-supplier_di" bpmnElement="purchase-supplier" isMessageVisible="true" participantBandKind="top_initiating" choreographyActivityShape="ship_di">
        <dc:Bounds x="376" y="290" width="110" height="20" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ship-purchase-library_di" bpmnElement="purchase-library" isMessageVisible="false" participantBandKind="bottom_non_initiating" choreographyActivityShape="ship_di">
        <dc:Bounds x="376" y="370" width="110" height="20" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="decline-purchase-supplier_di" bpmnElement="purchase-supplier" isMessageVisible="true" participantBandKind="top_initiating" choreographyActivityShape="decline_di">
        <dc:Bounds x="376" y="480" width="110" height="20" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="decline-purchase-library_di" bpmnElement="purchase-library" isMessageVisible="false" participantBandKind="bottom_non_initiating" choreographyActivityShape="decline_di">
        <dc:Bounds x="376" y="560" width="110" height="20" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
