<?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:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="@bpmnkit/core" exporterVersion="0.0.23" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.9.0">
  <bpmn:process id="scheduled-report" name="Scheduled KPI Report" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="every-day" name="Every day">
      <bpmn:outgoing>Flow_every-day_query-kpis</bpmn:outgoing>
      <bpmn:timerEventDefinition>
        <bpmn:timeCycle>R/P1D</bpmn:timeCycle>
      </bpmn:timerEventDefinition>
    </bpmn:startEvent>
    <bpmn:serviceTask id="query-kpis" name="Query KPIs">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="warehouse-query"/>
        <zeebe:ioMapping>
          <zeebe:output source="=rows" target="kpiRows"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="query" value="daily_kpis"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_every-day_query-kpis</bpmn:incoming>
      <bpmn:outgoing>Flow_query-kpis_has-data</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:exclusiveGateway id="has-data" name="Any rows?" default="Flow_has-data_alert-data-team">
      <bpmn:incoming>Flow_query-kpis_has-data</bpmn:incoming>
      <bpmn:outgoing>Flow_has-data_render-report</bpmn:outgoing>
      <bpmn:outgoing>Flow_has-data_alert-data-team</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="render-report" name="Render report">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="report-render"/>
        <zeebe:ioMapping>
          <zeebe:output source="=url" target="reportUrl"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_has-data_render-report</bpmn:incoming>
      <bpmn:outgoing>Flow_render-report_distribute-report</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="distribute-report" name="Mail to distribution list">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="email-send"/>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="daily-kpis"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_render-report_distribute-report</bpmn:incoming>
      <bpmn:outgoing>Flow_distribute-report_report-sent</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="report-sent" name="Report sent">
      <bpmn:incoming>Flow_distribute-report_report-sent</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:serviceTask id="alert-data-team" name="Alert data team">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="chat-post"/>
        <zeebe:taskHeaders>
          <zeebe:header key="channel" value="#data-alerts"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_has-data_alert-data-team</bpmn:incoming>
      <bpmn:outgoing>Flow_alert-data-team_no-data</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="no-data" name="No data">
      <bpmn:incoming>Flow_alert-data-team_no-data</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_every-day_query-kpis" sourceRef="every-day" targetRef="query-kpis"/>
    <bpmn:sequenceFlow id="Flow_query-kpis_has-data" sourceRef="query-kpis" targetRef="has-data"/>
    <bpmn:sequenceFlow id="Flow_has-data_render-report" sourceRef="has-data" targetRef="render-report" name="report">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=count(kpiRows) &gt; 0</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_render-report_distribute-report" sourceRef="render-report" targetRef="distribute-report"/>
    <bpmn:sequenceFlow id="Flow_distribute-report_report-sent" sourceRef="distribute-report" targetRef="report-sent"/>
    <bpmn:sequenceFlow id="Flow_has-data_alert-data-team" sourceRef="has-data" targetRef="alert-data-team" name="empty"/>
    <bpmn:sequenceFlow id="Flow_alert-data-team_no-data" sourceRef="alert-data-team" targetRef="no-data"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="scheduled-report_di">
    <bpmndi:BPMNPlane id="scheduled-report_di_plane" bpmnElement="scheduled-report">
      <bpmndi:BPMNShape id="every-day_di" bpmnElement="every-day">
        <dc:Bounds x="34" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="query-kpis_di" bpmnElement="query-kpis">
        <dc:Bounds x="170" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="has-data_di" bpmnElement="has-data">
        <dc:Bounds x="370" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="363" y="89" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="render-report_di" bpmnElement="render-report">
        <dc:Bounds x="520" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="distribute-report_di" bpmnElement="distribute-report">
        <dc:Bounds x="720" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="report-sent_di" bpmnElement="report-sent">
        <dc:Bounds x="920" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="899" y="242" width="77" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="alert-data-team_di" bpmnElement="alert-data-team">
        <dc:Bounds x="520" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="no-data_di" bpmnElement="no-data">
        <dc:Bounds x="752" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="745" y="82" width="49" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_every-day_query-kpis_di" bpmnElement="Flow_every-day_query-kpis">
        <di:waypoint x="70" y="60"/>
        <di:waypoint x="170" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_query-kpis_has-data_di" bpmnElement="Flow_query-kpis_has-data">
        <di:waypoint x="270" y="60"/>
        <di:waypoint x="370" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_has-data_render-report_di" bpmnElement="Flow_has-data_render-report">
        <di:waypoint x="395" y="85"/>
        <di:waypoint x="395" y="220"/>
        <di:waypoint x="520" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="371" y="146" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_render-report_distribute-report_di" bpmnElement="Flow_render-report_distribute-report">
        <di:waypoint x="620" y="220"/>
        <di:waypoint x="720" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_distribute-report_report-sent_di" bpmnElement="Flow_distribute-report_report-sent">
        <di:waypoint x="820" y="220"/>
        <di:waypoint x="920" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_has-data_alert-data-team_di" bpmnElement="Flow_has-data_alert-data-team">
        <di:waypoint x="420" y="60"/>
        <di:waypoint x="520" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="450" y="36" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_alert-data-team_no-data_di" bpmnElement="Flow_alert-data-team_no-data">
        <di:waypoint x="620" y="60"/>
        <di:waypoint x="752" y="60"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

