<?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: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">${response}</camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_1nk6j93</bpmn:incoming>
      <bpmn:outgoing>Flow_15dl9h9</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_15dl9h9" sourceRef="BUDGET" targetRef="RESSOURCE" />
    <bpmn:businessRuleTask id="Activity_0r9e9yi" name="Determine project template" camunda:resultVariable="result" camunda:decisionRef="decision_" camunda:mapDecisionResult="singleResult">
      <bpmn:extensionElements />
      <bpmn:incoming>Flow_1oj0ibg</bpmn:incoming>
      <bpmn:outgoing>Flow_0opfxdk</bpmn:outgoing>
    </bpmn:businessRuleTask>
    <bpmn:sequenceFlow id="Flow_0opfxdk" sourceRef="Activity_0r9e9yi" targetRef="Activity_1dnwama" />
    <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">${response}</camunda:outputParameter>
          </camunda:inputOutput>
          <camunda:connectorId>http-connector</camunda:connectorId>
        </camunda:connector>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_15dl9h9</bpmn:incoming>
      <bpmn:outgoing>Flow_1oj0ibg</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="Event_0bcdj2a">
      <bpmn:incoming>Flow_1cwv7pa</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1cwv7pa" sourceRef="Activity_1dnwama" targetRef="Event_0bcdj2a" />
    <bpmn:sequenceFlow id="Flow_1nk6j93" sourceRef="StartEvent_1" targetRef="BUDGET" />
    <bpmn:sequenceFlow id="Flow_1oj0ibg" sourceRef="RESSOURCE" targetRef="Activity_0r9e9yi" />
  </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="102" 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="260" y="80" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_16vcnz7_di" bpmnElement="Activity_0r9e9yi">
        <dc:Bounds x="640" y="80" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1uh15ad_di" bpmnElement="Activity_1dnwama">
        <dc:Bounds x="810" y="80" 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="410" y="80" width="100" height="80" />
        <bpmndi:BPMNLabel />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0bcdj2a_di" bpmnElement="Event_0bcdj2a">
        <dc:Bounds x="1008" y="102" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_15dl9h9_di" bpmnElement="Flow_15dl9h9">
        <di:waypoint x="360" y="120" />
        <di:waypoint x="410" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0opfxdk_di" bpmnElement="Flow_0opfxdk">
        <di:waypoint x="740" y="120" />
        <di:waypoint x="810" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1cwv7pa_di" bpmnElement="Flow_1cwv7pa">
        <di:waypoint x="910" y="120" />
        <di:waypoint x="1008" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1nk6j93_di" bpmnElement="Flow_1nk6j93">
        <di:waypoint x="215" y="120" />
        <di:waypoint x="260" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1oj0ibg_di" bpmnElement="Flow_1oj0ibg">
        <di:waypoint x="510" y="120" />
        <di:waypoint x="640" y="120" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>
