<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" xmlns:color="http://www.omg.org/spec/BPMN/non-normative/color/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1hr7u3z" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
  <bpmn:process id="appliquer_gabarit_conditionne" name="Appliquer gabarit conditionné" isExecutable="true" camunda:historyTimeToLive="180">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1nk6j93</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="BUDGET" name="Find value from attribute &#34;BUDGET&#34;">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="headers">
              <camunda:map>
                <camunda:entry key="Accept">application/json</camunda:entry>
                <camunda:entry key="Content-type">application/json</camunda:entry>
                <camunda:entry key="X-PM-API-LOGIN">camunda</camunda:entry>
              </camunda:map>
            </camunda:inputParameter>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:inputParameter name="url">http://localhost:8080/MonitorMakerWeb/api/projects/#{execution.getVariable('projectId')}/attributes/ATT_BUDGET</camunda:inputParameter>
            <camunda:outputParameter name="budget_value">
              <camunda:script scriptFormat="JavaScript">var response = JSON.parse(connector.getVariable('response'));
response;</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1d5mema</bpmn:incoming>
      <bpmn:outgoing>Flow_15dl9h9</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_15dl9h9" sourceRef="BUDGET" targetRef="Gateway_0gpfkxa" />
    <bpmn:sequenceFlow id="Flow_1nk6j93" sourceRef="StartEvent_1" targetRef="Gateway_1xhr9sf" />
    <bpmn:parallelGateway id="Gateway_1xhr9sf">
      <bpmn:incoming>Flow_1nk6j93</bpmn:incoming>
      <bpmn:outgoing>Flow_1d5mema</bpmn:outgoing>
      <bpmn:outgoing>Flow_1ih4zb7</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="Flow_1d5mema" sourceRef="Gateway_1xhr9sf" targetRef="BUDGET" />
    <bpmn:sequenceFlow id="Flow_1ih4zb7" sourceRef="Gateway_1xhr9sf" targetRef="RESSOURCE" />
    <bpmn:sequenceFlow id="Flow_1id4dn4" sourceRef="Gateway_0gpfkxa" targetRef="Activity_0r9e9yi" />
    <bpmn:businessRuleTask id="Activity_0r9e9yi" name="Determine project template" camunda:resultVariable="result" camunda:decisionRef="decision_" camunda:mapDecisionResult="singleResult">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:outputParameter name="errorCode">#{execution.getVariable('result')==null?'ERR_WORKFLOW_NO_DECISION':null}</camunda:outputParameter>
        </camunda:inputOutput>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1id4dn4</bpmn:incoming>
      <bpmn:outgoing>Flow_0opfxdk</bpmn:outgoing>
      <bpmn:outgoing>Flow_0f1yp0y</bpmn:outgoing>
    </bpmn:businessRuleTask>
    <bpmn:sequenceFlow id="Flow_0opfxdk" sourceRef="Activity_0r9e9yi" targetRef="Activity_1dnwama">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{execution.getVariable('result')!=null}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:serviceTask id="Activity_1dnwama" name="Apply template">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="headers">
              <camunda:map>
                <camunda:entry key="Accept">application/json</camunda:entry>
                <camunda:entry key="Content-type">application/json</camunda:entry>
                <camunda:entry key="X-PM-API-LOGIN">camunda</camunda:entry>
              </camunda:map>
            </camunda:inputParameter>
            <camunda:inputParameter name="method">POST</camunda:inputParameter>
            <camunda:inputParameter name="payload">{
"project": { "id": #{execution.getVariable('projectId')}},
"template": {"code": "#{execution.getVariable('result').get('apply_template')}"},
"insert": false
}</camunda:inputParameter>
            <camunda:inputParameter name="url">http://localhost:8080/monitorupgrade/projects/template/update</camunda:inputParameter>
            <camunda:outputParameter name="errorLabel">
              <camunda:script scriptFormat="JavaScript">var statusCode = connector.getVariable('statusCode');
if (statusCode &lt; 400) {
  connector.getVariable('errorLabel');
} else {
 var response = JSON.parse(connector.getVariable('response'));
 var newError = '';
 if (response.message) {
  newError = response.message;
 } else if (response.error) {
  newError = response.error;
 } else if (response[0] &amp;&amp; response[0].beanWsErreur &amp;&amp; response[0].beanWsErreur.message) {
  newError = response[0].beanWsErreur.message;
 }
 var existingErrors = connector.getVariable('errorLabel');
 if (existingErrors==null) {
 newError;
 } else {
 existingErrors + ' + ' + newError;
 }
}</camunda:script>
            </camunda:outputParameter>
            <camunda:outputParameter name="infosLabel">
              <camunda:script scriptFormat="JavaScript">var headers = connector.getVariable('headers');
if (headers.get('X-Context-Info')) {
  headers.get('X-Context-Info');
}</camunda:script>
            </camunda:outputParameter>
            <camunda:outputParameter name="warningsLabel">
              <camunda:script scriptFormat="JavaScript">var headers = connector.getVariable('headers');
if (headers.get('X-Context-Warning')) {
  headers.get('X-Context-Warning');
}</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_0opfxdk</bpmn:incoming>
      <bpmn:outgoing>Flow_1cwv7pa</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="RESSOURCE" name="Find value from attribute &#34;RESSOURCE&#34;">
      <bpmn:extensionElements>
        <camunda:connector>
          <camunda:inputOutput>
            <camunda:inputParameter name="headers">
              <camunda:map>
                <camunda:entry key="Accept">application/json</camunda:entry>
                <camunda:entry key="Content-type">application/json</camunda:entry>
                <camunda:entry key="X-PM-API-LOGIN">camunda</camunda:entry>
              </camunda:map>
            </camunda:inputParameter>
            <camunda:inputParameter name="method">GET</camunda:inputParameter>
            <camunda:inputParameter name="url">http://localhost:8080/MonitorMakerWeb/api/projects/#{execution.getVariable('projectId')}/attributes/ATT_RESSOURCE</camunda:inputParameter>
            <camunda:outputParameter name="ressource_value">
              <camunda:script scriptFormat="JavaScript">var response = JSON.parse(connector.getVariable('response'));
response;</camunda:script>
            </camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1ih4zb7</bpmn:incoming>
      <bpmn:outgoing>Flow_1izk2w6</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_1izk2w6" sourceRef="RESSOURCE" targetRef="Gateway_0gpfkxa" />
    <bpmn:endEvent id="Event_0bcdj2a">
      <bpmn:incoming>Flow_0f1yp0y</bpmn:incoming>
      <bpmn:incoming>Flow_1cwv7pa</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1cwv7pa" sourceRef="Activity_1dnwama" targetRef="Event_0bcdj2a" />
    <bpmn:parallelGateway id="Gateway_0gpfkxa">
      <bpmn:incoming>Flow_15dl9h9</bpmn:incoming>
      <bpmn:incoming>Flow_1izk2w6</bpmn:incoming>
      <bpmn:outgoing>Flow_1id4dn4</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="Flow_0f1yp0y" sourceRef="Activity_0r9e9yi" targetRef="Event_0bcdj2a">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{execution.getVariable('result')==null}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="appliquer_gabarit_conditionne">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="179" y="162" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0wcjfu7_di" bpmnElement="BUDGET" bioc:stroke="#6b3c00" bioc:fill="#ffe0b2" color:background-color="#ffe0b2" color:border-color="#6b3c00">
        <dc:Bounds x="380" y="77" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_13qm3kq_di" bpmnElement="Gateway_1xhr9sf">
        <dc:Bounds x="265" y="155" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_16vcnz7_di" bpmnElement="Activity_0r9e9yi">
        <dc:Bounds x="640" y="140" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1uh15ad_di" bpmnElement="Activity_1dnwama">
        <dc:Bounds x="810" y="140" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="BPMNShape_0l3flt2" bpmnElement="RESSOURCE" bioc:stroke="#6b3c00" bioc:fill="#ffe0b2" color:background-color="#ffe0b2" color:border-color="#6b3c00">
        <dc:Bounds x="380" y="200" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_093ylrs_di" bpmnElement="Gateway_0gpfkxa">
        <dc:Bounds x="535" y="155" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0bcdj2a_di" bpmnElement="Event_0bcdj2a">
        <dc:Bounds x="952" y="162" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_15dl9h9_di" bpmnElement="Flow_15dl9h9">
        <di:waypoint x="480" y="117" />
        <di:waypoint x="560" y="117" />
        <di:waypoint x="560" y="155" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1nk6j93_di" bpmnElement="Flow_1nk6j93">
        <di:waypoint x="215" y="180" />
        <di:waypoint x="265" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1d5mema_di" bpmnElement="Flow_1d5mema">
        <di:waypoint x="290" y="155" />
        <di:waypoint x="290" y="117" />
        <di:waypoint x="380" y="117" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1ih4zb7_di" bpmnElement="Flow_1ih4zb7">
        <di:waypoint x="290" y="205" />
        <di:waypoint x="290" y="240" />
        <di:waypoint x="380" y="240" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1id4dn4_di" bpmnElement="Flow_1id4dn4">
        <di:waypoint x="585" y="180" />
        <di:waypoint x="640" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0opfxdk_di" bpmnElement="Flow_0opfxdk">
        <di:waypoint x="740" y="180" />
        <di:waypoint x="810" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1izk2w6_di" bpmnElement="Flow_1izk2w6">
        <di:waypoint x="480" y="240" />
        <di:waypoint x="560" y="240" />
        <di:waypoint x="560" y="205" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1cwv7pa_di" bpmnElement="Flow_1cwv7pa">
        <di:waypoint x="910" y="180" />
        <di:waypoint x="952" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0f1yp0y_di" bpmnElement="Flow_0f1yp0y">
        <di:waypoint x="690" y="220" />
        <di:waypoint x="690" y="280" />
        <di:waypoint x="970" y="280" />
        <di:waypoint x="970" y="198" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
