info:
  name: Elenco Partecipanti - Array CF docenti
  type: http
  seq: 5

http:
  method: POST
  url: "{{elixFormsApiUrl}}/eftl/process/v1"
  headers:
    - name: x-requested-with
      value: XMLHttpRequest
    - name: x-api-key
      value: "{{elixFormsWsAuthenticationToken}}"
    - name: x-ef-request-id
      value: "22085"
  body:
    type: json
    data: |-
      {
        "userDocument": "{{elixBase64EftlDocument}}", // see the pre-request script
        "userContext": {
          "lang": "IT",
          "crlf": "\r\n",
          "qualificheDocenti": ";Docente;Ricercatore;"
        }
      }
  auth: inherit

runtime:
  scripts:
    - type: before-request
      code: |-
        const { prepareEftlDocument } = require("./elixFormsJs.js")
        // Copy-pasta your EFTL document below inside the template literals (`)
        prepareEftlDocument(String.raw`
        [EFTL][HEADER name="trimDocument" value="true" type="boolean" /]
        [!-- Must be defined in EftlSolver attribute! --]
        [VAR name="newLine" type="string"][VALUE_OF varname="crlf" /][/VAR]
        [VAR name="qualificheDocentiIterable" type="iterable"][SPLIT regex=";"][VALUE_OF varname="qualificheDocenti" /][/SPLIT][/VAR]

        [VAR name="responsabiliScientifici" type="string"][TAG]GETVALUEBYTAG,CONTRATTO_RESPONSABILI,REQUEST,IUQOID[/TAG][/VAR]
        [VAR name="partecipanti" type="string"][TAG]GETVALUEBYTAG,CONTRATTO_PARTECIPANTI,REQUEST,IUQOID[/TAG][/VAR]

        [VAR name="soggettiIterable" type="iterable"][SPLIT regex="\n"][% responsabiliScientifici + newLine + partecipanti %][/SPLIT][/VAR]

        [VAR name="elencoCodFisPersonaleDocente" type="string"][% elencoCodFisPersonaleDocente = ";"; %]][/VAR]
        [VAR name="elencoCodFisPersonaleAltro" type="string"][% elencoCodFisPersonaleAltro = ";"; %]][/VAR]

        [VAR name="firstItem" type="number"][% firstItem = 0; %][/VAR]
        [VAR name="secondItem" type="number"][% secondItem = 1; %][/VAR]

        [FOR varname="persona" iterable="soggettiIterable"]
          [!-- Estraggo il Codice Fiscale --]
          [VAR name="personaIterable" type="iterable"][SPLIT regex=", CF: "][TRIM][VALUE_OF varname="persona" /][/TRIM][/SPLIT][/VAR]
          [VAR name="personaRight" type="string"][VALUE_OF varname="personaIterable" index="secondItem" /][/VAR]
          [VAR name="personaIterable" type="iterable"][SPLIT regex=", Qualifica: "][TRIM][VALUE_OF varname="personaRight" /][/TRIM][/SPLIT][/VAR]
          [VAR name="codiceFiscale" type="string"][VALUE_OF varname="personaIterable" index="firstItem" /][/VAR]
          [!-- Estraggo la Qualifica --]
          [VAR name="personaRight" type="string"][VALUE_OF varname="personaIterable" index="secondItem" /][/VAR]
          [VAR name="personaIterable" type="iterable"][SPLIT regex=", Struttura di afferenza: "][TRIM][VALUE_OF varname="personaRight" /][/TRIM][/SPLIT][/VAR]
          [VAR name="qualifica" type="string"][VALUE_OF varname="personaIterable" index="firstItem" /][/VAR]

          [IF]
            [CONDITION][CONTAINS varname="qualificheDocentiIterable" value="qualifica" /][/CONDITION]
            [THEN][% elencoCodFisPersonaleDocente = elencoCodFisPersonaleDocente + codiceFiscale + ";"; %][/THEN]
            [ELSE][% elencoCodFisPersonaleAltro = elencoCodFisPersonaleAltro + codiceFiscale + ";"; %][/ELSE]
          [/IF]
        [/FOR]

        [%= elencoCodFisPersonaleDocente %]
        [/EFTL]
        `);

settings:
  encodeUrl: true
  timeout: 0
  followRedirects: true
  maxRedirects: 5
  forwardAuthorizationHeader: true
