--------------------------------------------------------
--  DDL for Package Body PKG_STANDARD_EXECUTORS
--------------------------------------------------------

  CREATE OR REPLACE EDITIONABLE PACKAGE BODY "ENVX_OPER"."PKG_STANDARD_EXECUTORS" IS
    -------------------------------------------------------------

    FUNCTION fnc_sicd_var (
        pi_id_control_deploy IN INTEGER
    ) RETURN CLOB AS
        v_variables CLOB;
    BEGIN

       -- Obtiene el registro de control ejecutado para una solicitud 
       /* SELECT
            '"varname":"ID_REQUEST","value":'
             || rd.id_request
             || ','
             ||
               --------------------------------------------------------------- ID_REQUEST CHR(13)
             || '"varname":"ID_REQUEST_DETAIL","value":'
             || rd.id_dep_req_object
             || ','
             ||
               --------------------------------------------------------------- ID_REQUEST_DETAIL CHR(13)
             || '"varname":"ID_DEPLOYING_TECH","value":'
             || rd.id_deploying_tech
             || ','
             ||
               --------------------------------------------------------------- ID_DEPLOYING_TECH               CHR(13)
             || '"varname":"ID_ENVIROMENT_GROUP","value":'
             || rd.id_env_hgroup
             || ','
             ||
               --------------------------------------------------------------- ID_ENVIROMENT_GROUP               CHR(13)
             || '"varname":"ID_ENVIROMENT","value":'
             || rd.id_enviroment
             || ','
             ||
               --------------------------------------------------------------- ID_ENVIROMENT                                          CHR(13)
             || '"varname":"ID_OBJECT_GROUP","value":'
             || rd.id_obj_hgroup
             || ','
             ||
               --------------------------------------------------------------- ID_OBJECT_GROUP               CHR(13)
             || '"varname":"ID_OBJECT_REPO","value":"'
             || rd.id_object_repo
             || '"'
                ---------------------------------------------------------------  ID_OBJECT_REPO  
        INTO
            v_variables
        FROM
            request_exec_deploy rd
        WHERE
            rd.id_control_deploy = pi_id_control_deploy;

        v_variables := '{ ' || v_variables || '}';
        RETURN v_variables;*/
        RETURN NULL;
    END;

------------- FUNCTIONS ------------------
/*--------------- FNC01-------------------*/

    FUNCTION fnc_var_value (
        pi_var_name           VARCHAR2,
        pi_request            NUMBER,
        pi_id_control_deploy  NUMBER
    ) RETURN VARCHAR2 AS
        v_value             VARCHAR2(100);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.fnc_var_value';
    BEGIN
        SELECT (
            CASE pi_var_name
                WHEN 'ID_REQUEST'               THEN
                    to_char(rd.id_request)
                WHEN 'ID_REQUEST_DETAIL'        THEN
                    to_char(rd.id_control_deploy)
                WHEN 'ID_DEPLOYING_TECH'        THEN
                    to_char(rd.id_deploying_tech)
                WHEN 'ID_ENVIROMENT_GROUP'      THEN
                    to_char(rd.id_env_hgroup)
                WHEN 'ENVIROMENT_ALIAS'         THEN
                    (
                        SELECT e.enviroment_alias
                          FROM enviroment e
                         WHERE e.id_enviroment = rd.id_enviroment
                    )
                WHEN 'ENVIROMENT_CLASS'         THEN
                    (
                        SELECT to_char(et.enviroment_type_class)
                          FROM enviroment         e,
                               enviroment_type    et
                         WHERE e.id_enviroment = rd.id_enviroment
                           AND e.id_enviroment_type = et.id_enviroment_type
                    )
                WHEN 'PARENT_ENVIROMENT_ALIAS'  THEN
                    (
                        SELECT pe.enviroment_alias
                          FROM enviroment    e,
                               enviroment    pe
                         WHERE e.id_parent_enviroment = pe.id_enviroment
                           AND e.id_enviroment = rd.id_enviroment
                    )
                WHEN 'ID_OBJECT_GROUP'          THEN
                    to_char(rd.id_obj_hgroup)
                WHEN 'OBJECT_PATH'              THEN
                    to_char(rd.object_source_path)
                WHEN 'ID_OBJECT'                THEN
                    to_char(rd.id_object_repo)
                WHEN 'OBJECT_NAME'              THEN
                    to_char(rd.object_name)
                WHEN 'OBJECT_VERSION'           THEN
                    to_char(rd.object_version)
                WHEN 'BUILD_TIMEOUT'            THEN
                    nvl((
                        SELECT to_char((nvl(ds.minutes_timeout, 0) * 60) + nvl(ds.seconds_timeout, 0))
                          FROM deployment_pattern_step ds
                         WHERE ds.id_pattern_step = rd.id_pattern_step
                           AND ds.id_pattern = rd.id_pattern
                    ), '0')
                ELSE
                    NULL
            END
        ) AS val
          INTO v_value
          FROM request_exec_deploy rd
         WHERE rd.id_control_deploy = pi_id_control_deploy;

        apex_debug.info('pkg_standard_executors.fnc_var_value - v_value: %s', v_value);
        RETURN v_value;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.fnc_var_value - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            RETURN NULL;
    END;

/*--------------- FNC02-------------------*/

    FUNCTION fnc_soap_call (
        pi_body               IN   CLOB,
        pi_soap_header        IN   VARCHAR2,
        pi_soap_action        IN   VARCHAR2,
        pi_target_url         IN   VARCHAR2,
        pi_http_version       IN   VARCHAR2,
        pi_http_content_type  IN   VARCHAR2,
        po_response_code      OUT  VARCHAR2,
        po_error_message      OUT  VARCHAR2
    ) RETURN XMLTYPE AS
        v_soap_envelope     VARCHAR2(4000) := '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                                       <soap:Header>**pi_soap_header**</soap:Header>
                                        <soap:Body>**pi_body**</soap:Body>
                                    </soap:Envelope>';
        v_soap_request      VARCHAR2(32767);
        v_soap_response     VARCHAR2(32767);
        v_clob              CLOB;
        v_request_xmltype   XMLTYPE;
        v_response_xmltype  XMLTYPE;
        v_http_req          utl_http.req;
        v_http_resp         utl_http.resp;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.fnc_soap_call';
    BEGIN

        ------------------------------------------------------------------ 

        po_response_code    := 'OK';
        v_soap_envelope     := replace(v_soap_envelope, '**pi_soap_header**', pi_soap_header);
        v_soap_request      := replace(v_soap_envelope, '**pi_body**', pi_body);
        apex_debug.info('pkg_standard_executors.fnc_soap_call - v_soap_request: %s', v_soap_request);

    --Configuramos la invocacion
    --utl_http.set_transfer_timeout(60);
        dbms_output.put_line('URL = ' || pi_target_url);
        v_http_req          := utl_http.begin_request(pi_target_url, 'POST', pi_http_version);
        utl_http.set_header(v_http_req, 'Content-Type', pi_http_content_type);
        utl_http.set_header(v_http_req, 'Content-Length', length(v_soap_request));
        utl_http.set_header(v_http_req, 'SOAPAction', pi_soap_action);
        utl_http.write_text(v_http_req, v_soap_request);
        utl_http.set_response_error_check(false);
     --Ver como hacer

    ------------------------------------------------------------------        
      /*  log_collector(
            pi_program_name  => log_program_name,
            pi_log_level     => 4, --- DEBUG
            pi_log_message   => 'VARIABLES: 
            - v_http_req: SOLICITUD
            - fecha: '||sysdate
        );*/
        ------------------------------------------------------------------ 

    --Invocamos el WS
        v_http_resp         := utl_http.get_response(v_http_req);

    --Leemos la respuesta
        dbms_lob.createtemporary(v_clob, false);
        apex_debug.info('pkg_standard_executors.fnc_soap_call - v_soap_response: %s', v_soap_response);
        BEGIN
            LOOP
                utl_http.read_text(v_http_resp, v_soap_response, 32766);
                dbms_lob.writeappend(v_clob, length(v_soap_response), v_soap_response);
            END LOOP;
      -- Cerramos la comunicacion request/response

            utl_http.end_response(v_http_resp);
        EXCEPTION
            WHEN utl_http.end_of_body THEN
                apex_debug.error('pkg_standard_executors.fnc_soap_call - %s', sqlerrm);
                utl_http.end_response(v_http_resp);
        END;

    --Creamos el XML de respuesta (con el envelope retornado)

        v_response_xmltype  := xmltype.createxml(v_clob);
        dbms_lob.freetemporary(v_clob);

      --Devolvemos el XML
        RETURN v_response_xmltype;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.fnc_soap_call - %s', sqlerrm);
            utl_http.end_response(v_http_resp);
            po_response_code  := 'ERROR';
            po_error_message  := substr(sqlerrm, 1, 4000);
            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            ------------------------------------------------------------------ 

    END fnc_soap_call;

/*--------------- FNC03-------------------*/

    FUNCTION fnc_send_profile_email (
        pi_id_sys_profile NUMBER
    ) RETURN VARCHAR2 AS
        v_mail              VARCHAR2(4000);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.fnc_send_profile_email';
    BEGIN
    -- consulto los mails asociados a dicho perfil --
        FOR i IN (
            SELECT user_mail
              FROM user_roles
             WHERE id_sys_profile = pi_id_sys_profile
        ) LOOP
            v_mail := v_mail
                      || ','
                      || i.user_mail;
        END LOOP;
    -- averiguo si la consulta trajo resultados --

        IF length4(v_mail) > 0 THEN
    -- remuevo la primer ',' en caso de que haya resultado --
            v_mail := substr(v_mail, 2);
            apex_debug.info('pkg_standard_executors.fnc_send_profile_email v_mail: %s', v_mail);
        ELSE 
    -- si no hay ningun perfil con mail, debo traer todos los mails hijos de ese perfil --
            FOR i IN (
                SELECT u.user_mail,
                       u.id_sys_profile
                  FROM user_roles u
                 WHERE u.id_sys_profile IN (
                           SELECT p.id_sys_profile
                             FROM system_profile p START WITH
                               id_sup_sys_profile = pi_id_sys_profile
                           CONNECT BY
                               PRIOR id_sys_profile = id_sup_sys_profile
                       )
            ) LOOP
                v_mail := v_mail
                          || ','
                          || i.user_mail;
            END LOOP;

            v_mail := substr(v_mail, 2);
            apex_debug.info('pkg_standard_executors.fnc_send_profile_email v_mails: %s', v_mail);
        END IF;

        RETURN v_mail;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.fnc_send_profile_email - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            RETURN NULL;
    END;

/*--------------- FNC04-------------------*/

    FUNCTION fnc_get_status_request (
        pi_id_request NUMBER
    ) RETURN BOOLEAN AS
        v_status_request    VARCHAR2(50);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.fnc_get_status_request';
    BEGIN
        SELECT level_status
          INTO v_status_request
          FROM hierarchical_request_vew
         WHERE group_id = pi_id_request
           AND parent_id IS NULL;

        IF v_status_request != 'Creada' THEN
            RETURN false;
        ELSE
            RETURN true;
        END IF;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.fnc_get_status_request - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            RETURN false;
    END;

/*--------------- FNC05-------------------*/

    FUNCTION fnc_get_jenkins_node (
        pi_environment_class NUMBER
    ) RETURN VARCHAR2 AS
    BEGIN
        IF ( pi_environment_class = 1 ) THEN
            RETURN 'PRIMARY';
        ELSE
            RETURN 'SECONDARY';
        END IF;
    END;

------------------------------------------
------------ PROCEDURES ------------------

/*--------------- SEP1-------------------*/

    PROCEDURE prc_dynamic_param (
        pi_id_request         IN      NUMBER,
        pi_id_control_deploy  IN      NUMBER,
        pi_id_executor        IN      NUMBER,
        po_exec_program       OUT     CLOB,
        po_parameters_rep     IN OUT  CLOB
    ) AS
        v_prg               VARCHAR2(1000);
        v_exec              VARCHAR2(4000);
        v_execution         VARCHAR2(4000);
        v_aux_param         CLOB;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_dynamic_param';
    BEGIN
        FOR r IN (
            SELECT upper(ep.parameter)       AS sys_variable,
                   a.argument_name           AS prc_parameter,
                   ep.default_value,
                   a.position,
                   a.data_type,
                   ep.param_source_val       AS param_type,
                   (
                       CASE executor_type
                           WHEN 0  THEN
                               NULL
                           WHEN 1  THEN
                               NULL
                           WHEN 2  THEN
                               substr(e.executor_program, 1, instr(e.executor_program, '.') - 1)
                           ELSE
                               substr(e.executor_program, 1, instr(e.executor_program, '.') - 1)
                       END
                   )                         AS pakage_name_exec,
                   (
                       CASE executor_type
                           WHEN 0  THEN
                               NULL
                           WHEN 1  THEN
                               NULL
                           WHEN 2  THEN
                               substr(e.executor_program, instr(e.executor_program, '.') + 1)
                           ELSE
                               substr(e.executor_program, instr(e.executor_program, '.') + 1)
                       END
                   )                         AS program_name_exec,
                   e.executor_program
              FROM executor_parameter  ep,
                   user_arguments      a,
                   executor            e
             WHERE ep.id_executor = pi_id_executor
               AND ep.id_executor    = e.id_executor
               AND a.position        = ep.order_number
               AND a.package_name    = upper((
                                     CASE executor_type
                                         WHEN 0  THEN
                                             NULL
                                         WHEN 1  THEN
                                             NULL
                                         WHEN 2  THEN
                                             substr(e.executor_program, 1, instr(e.executor_program, '.') - 1)
                                         ELSE
                                             substr(e.executor_program, 1, instr(e.executor_program, '.') - 1)
                                     END
                                 ))
               AND a.object_name     = upper((
                                    CASE executor_type
                                        WHEN 0  THEN
                                            NULL
                                        WHEN 1  THEN
                                            NULL
                                        WHEN 2  THEN
                                            substr(e.executor_program, instr(e.executor_program, '.') + 1)
                                        ELSE
                                            substr(e.executor_program, instr(e.executor_program, '.') + 1)
                                    END
                                ))
             ORDER BY a.position
        ) LOOP
            CASE
            --- Reemplaza los valores de las constantes
                WHEN r.param_type = 1 THEN
                    v_exec := v_exec
                              || (
                        CASE
                            WHEN r.position = 1 THEN
                                r.executor_program || '('
                            ELSE ','
                        END
                    )
                              || r.prc_parameter
                              || ' => '
                              || (
                        CASE
                            WHEN r.data_type IN (
                                       'NUMBER', 'INTEGER'
                                   ) THEN
                                r.default_value
                            ELSE ''''
                                 || r.default_value
                                 || ''''
                        END
                    );
                WHEN r.param_type = 2 THEN
               --- Reemplaza los valores con las variables disponibles
                    v_exec := v_exec
                              || (
                        CASE
                            WHEN r.position = 1 THEN
                                r.executor_program || '('
                            ELSE ','
                        END
                    )
                              || r.prc_parameter
                              || ' => '
                              || (
                        CASE
                            WHEN r.data_type IN (
                                       'NUMBER', 'INTEGER'
                                   ) THEN
                                fnc_var_value(
                                    pi_var_name           => r.sys_variable,
                                    pi_request            => pi_id_request,
                                    pi_id_control_deploy  => pi_id_control_deploy
                                )
                            ELSE ''''
                                 || fnc_var_value(
                                pi_var_name           => r.sys_variable,
                                pi_request            => pi_id_request,
                                pi_id_control_deploy  => pi_id_control_deploy
                            )
                                 || ''''
                        END
                    );
            END CASE;
        END LOOP;

        v_exec           := v_exec || ');';
        po_exec_program  := v_exec;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_dynamic_param - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*--------------- SEP2-------------------*/

    PROCEDURE prc_jenkins_check_queue_status (
        pi_id_request           INTEGER,
        pi_id_req_det           INTEGER,
        pi_id_prc_queue         VARCHAR2,
        pi_category_action      VARCHAR2,
        pi_environment_alias    VARCHAR2,
        pi_enviroment_class     NUMBER
    ) AS
        PRAGMA autonomous_transaction;
        v_queue_timeout     INTEGER := pkg_sicd_commons.get_parameter_value(param_name => 'JENKINS_QUEUE_ADD_TIMEOUT');
        name_job            VARCHAR2(100);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_check_queue_status';
    BEGIN
        ---
        apex_debug.warn('pkg_standard_executors.prc_jenkins_check_queue_status - pi_id_prc_queue: %s', pi_id_prc_queue);
        apex_debug.warn('pkg_standard_executors.prc_jenkins_check_queue_status - pi_id_req_det: %s', pi_id_req_det);
        apex_debug.warn('pkg_standard_executors.prc_jenkins_check_queue_status - pi_id_request: %s', pi_id_request);
        UPDATE request_exec_deploy dc
           SET dc.id_prc_queue = pi_id_prc_queue
         WHERE dc.id_control_deploy = pi_id_req_det
           AND dc.id_request = pi_id_request;

        COMMIT;

        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'despues del update - ' || 'valor de timeout' ||v_queue_timeout);

        -- HABILITA EL JOB DE TIMEOUT PARA LA COLA 
        IF nvl(v_queue_timeout, 0) > 0 THEN

            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 4, --- DEBUG
                            pi_log_message => 'Entra dentro de nvl(v_queue_timeout, 0) > 0 ');

            name_job := '"'||pi_id_req_det  
                           || lpad(pi_id_prc_queue, 5, 0)
                           || '_QUEUE_TIMEOUT"';  

            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 4, --- DEBUG
                            pi_log_message => 'PKG_STANDARD_EXECUTORS.prc_jenkins_check_build_status(' || pi_id_request || ',' || pi_id_req_det || ','''
                                || pi_id_prc_queue || ''',' || pi_enviroment_class || ',''' || pi_category_action || ''')');

            sys.dbms_scheduler.create_job(job_name => name_job, job_type => 'PLSQL_BLOCK', start_date => sysdate +(v_queue_timeout
                                                      / 86400), repeat_interval => NULL, end_date => sysdate +((v_queue_timeout +
                                                      5) / 86400),
                               auto_drop => true, job_action => 'BEGIN PKG_STANDARD_EXECUTORS.prc_jenkins_check_build_status('||pi_id_request||','||pi_id_req_det||','''||pi_id_prc_queue||''','||pi_enviroment_class||','''||pi_category_action||''','''||pi_environment_alias||'''); END;', 
                               comments => NULL);

            sys.dbms_scheduler.enable(name_job);

        ELSE
            --- SI NO POSEE TIEMPO DE ESPERA SOLICITA LA INTERVENCION DEL USUARIO
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 4, --- DEBUG
                            pi_log_message => 'entro en el else del nvl(v_queue_timeout, 0) > 0');
        END IF;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_check_queue_status - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*--------------- SEP3-------------------*/

    PROCEDURE prc_dynamic_exec (
        pi_id_request         IN  INTEGER,
        pi_id_control_deploy  IN  INTEGER,
        pi_id_executor        IN  NUMBER
    ) AS
        v_prg_executor      CLOB;
        v_execution         CLOB;
        v_aux_param         CLOB;
        v_id_executor       NUMBER := 0;
        v_exec_type         NUMBER := 0;
        v_exec_scope        NUMBER := 0;
        v_enviroment_alias  VARCHAR2(100);
        v_sqlerrm           VARCHAR2(500);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_dynamic_exec';
    BEGIN
        ---
        SELECT ps.id_executor,
               ps.id_step_type,
               ps.id_scope,
               (
                          SELECT e.enviroment_alias
                            FROM enviroment e
                           WHERE e.id_enviroment = red.id_enviroment
                      ) AS env_alias
          INTO v_id_executor,
               v_exec_type,
               v_exec_scope,
               v_enviroment_alias
          FROM request_exec_deploy        red,
               deployment_pattern_step    ps
         WHERE red.id_pattern = ps.id_pattern
           AND red.id_pattern_step      = ps.id_pattern_step
           AND red.id_control_deploy    = pi_id_control_deploy;

        IF v_exec_type = 2 THEN
     -- REALIZAR LA LLAMADA AL JENKINS

            ---
            prc_dynamic_param(
                pi_id_request         => pi_id_request,
                pi_id_control_deploy  => pi_id_control_deploy,
                pi_id_executor        => pi_id_executor,
                po_exec_program       => v_prg_executor,
                po_parameters_rep     => v_aux_param
            );        
            ---
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'v_prg_executor: ' || v_prg_executor
            );
            ------------------------------------------------------------------ 

            v_execution := 'BEGIN '
                           || v_prg_executor
                           || ' 
                           EXCEPTION 
                                WHEN OTHERS then
                               ------------------------------------------------------------------        
                                log_collector(
                                    pi_program_name  => ''' || log_program_name || ''',
                                    pi_log_level     => 2, --- 
                                    pi_log_message   => substr(''Error EXCEPTION WHEN OTHERS - Detalle del error: '' || sqlerrm
                                        ||  '' - Ubicación: '' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
                                ------------------------------------------------------------------ 
                           END;';
            ---
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'v_execution: ' || v_execution
            );
            ------------------------------------------------------------------ 
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'EJECUCION AUTOMATICA pi_id_request, pi_id_control_deploy, execution: '
                                  || pi_id_request
                                  || ', '
                                  || pi_id_control_deploy
                                  || ', '
                                  || v_execution
            );
            ------------------------------------------------------------------                           
            ---
            EXECUTE IMMEDIATE v_execution;
        ELSIF v_exec_type = 1 THEN
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2,
     --- WARNING
                pi_log_message   => 'EJECUCION ASISTIDA pi_id_request, pi_id_control_deploy, pi_id_executor: '
                                  || pi_id_request
                                  || ', '
                                  || pi_id_control_deploy
                                  || ', '
                                  || pi_id_executor
            );
            ------------------------------------------------------------------         

            NULL;
     -- ENVIAR SOLICITUD DE ACCION AL PERFIL RESPONSABLE
        ELSE
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2,
     --- WARNING
                pi_log_message   => 'EJECUCION MANUAL pi_id_request, pi_id_control_deploy, pi_id_executor: '
                                  || pi_id_request
                                  || ', '
                                  || pi_id_control_deploy
                                  || ', '
                                  || pi_id_executor
            );
            ------------------------------------------------------------------          

            NULL;
     -- NINGUNA ACCION ADICIONAL
        END IF;

    EXCEPTION
        WHEN no_data_found THEN
            apex_debug.error('pkg_standard_executors.prc_dynamic_exec - %s', sqlerrm);
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2,
     --- WARNING
                pi_log_message   => 'No_Data_Found - prc_dynamic_exec - pi_id_request, pi_id_control_deploy, pi_id_executor: '
                                  || pi_id_request
                                  || ', '
                                  || pi_id_control_deploy
                                  || ', '
                                  || pi_id_executor
            );
            ------------------------------------------------------------------      

        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_dynamic_exec - %s', sqlerrm);
            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            ------------------------------------------------------------------  
    END;

/*--------------- SEP4-------------------*/

    PROCEDURE prc_jkins_job_oracle_db (
        pi_category_action       VARCHAR2,
         -- BACKUP | CHECKOUT | DEPLOY
        pi_id_request            NUMBER,
        pi_id_req_det            NUMBER,
        pi_database_alias        VARCHAR2,
        pi_environment_alias     VARCHAR2,
        pi_scm_alias             VARCHAR2,
        pi_repository_path       VARCHAR2,
        pi_object_repository_id  VARCHAR2,
        pi_object_path           VARCHAR2,
        pi_object                VARCHAR2,
        pi_enviroment_class      NUMBER,
           -- 0: NO PRODUCTIVO | 1: PRODUCTIVO
        pi_build_timeout         NUMBER
    ) AS

        v_jenkins_node      VARCHAR2(50);
        v_auth_basic        VARCHAR2(200);
        vi_http_headers     http_headers_tab := http_headers_tab();
        vo_http_headers     http_headers_tab := http_headers_tab();
        v_jenkins_url       VARCHAR2(4000);
        vo_http_status      VARCHAR(20);
        vo_body             CLOB;
        po_response         CLOB;
        vo_response_code    VARCHAR(15);
        vo_error_message    VARCHAR(4000);
        exc_category_action EXCEPTION;
        exc_response_code   EXCEPTION;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jkins_job_oracle_db';
    BEGIN
        -- Defino el nodo de Jenkins a utilizar
        v_jenkins_node := fnc_get_jenkins_node(pi_enviroment_class);
        apex_debug.info('pkg_standard_executors.prc_jkins_job_oracle_db - v_jenkins_node: %s', v_jenkins_node);       

      log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 3,--- DEBUG
                pi_log_message   => 'jenkins_node: '
                                  || v_jenkins_node
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );

        -- Busco y armo la URL del Jenkins
        v_jenkins_url := pkg_sicd_commons.get_parameter_value('JENKINS_'
                                                                || v_jenkins_node
                                                                || '_URL')
                                                                || '/job';

        apex_debug.info('pkg_standard_executors.prc_jkins_job_oracle_db - v_jenkins_url: %s', v_jenkins_url);
       
             log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 3,--- DEBUG
                pi_log_message   => 'jenkins_url: '
                                  || v_jenkins_url
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );
       
        -- Dependiendo de la acción enviada, invoco al Jenkins con los parámetros correspondientes
        CASE pi_category_action
            WHEN 'BACKUP' THEN
                pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'pipBackupOracleDB'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'databaseAlias='
                    || pi_database_alias
                    || '&'
                    || 'environmentAlias='
                    || pi_environment_alias
                    || '&'
                    || 'objectPath='
                    || pi_object_path
                    || '&'
                    || 'object='
                    || substr(pi_object, 1, instr(pi_object, '.', 1) - 1),
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                 );
           WHEN 'CHECKOUT' THEN
                pkg_sicd_commons.p_rest_call_apim(v_jenkins_url
                    || '/'
                    || 'pipCheckoutOracleDB'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'databaseAlias='
                    || pi_database_alias
                    || '&'
                    || 'environmentAlias='
                    || pi_environment_alias
                    || '&'
                    || 'scmAlias='
                    || pi_scm_alias
                    || '&'
                    || 'repositoryPath='
                    || pi_repository_path
                    || '&'
                    || 'objectRepositoryID='
                    || pi_object_repository_id
                    || '&'
                    || 'objectPath='
                    || pi_object_path
                    || '&'
                    || 'object='
                    || pi_object,--url
                    'POST', --method
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                    );
                    dbms_output.put_line('vo_response_code'|| vo_response_code);
                    dbms_output.put_line('vo_error_message'|| vo_error_message);
            WHEN 'DEPLOY' THEN
                pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'pipDeployOracleDB'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'databaseAlias='
                    || pi_database_alias
                    || '&'
                    || 'environmentAlias='
                    || pi_environment_alias
                    || '&'
                    || 'objectPath='
                    || pi_object_path
                    || '&'
                    || 'object='
                    || pi_object,
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );                
            WHEN 'ROLLBACK' THEN
                ------------------------------------------------------------------        
                log_collector(
                    pi_program_name  => log_program_name,
                    pi_log_level     => 3, --- DEBUG
                    pi_log_message   => 'ROLLBACK: '
                );
                ------------------------------------------------------------------  
            ELSE
                RAISE exc_category_action;
        END CASE;

         log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 3,--- DEBUG
                pi_log_message   => 'LOG next -case - Code: '
                                  || vo_response_code
                                  || CHR(13)
                                  || ' - vo_error_message: '
                                  || vo_error_message
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );

            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 3, --- DEBUG
                pi_log_message   => 'Body : '
                                  || vo_body
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            ); 

        -- Analizo el response_code
        apex_debug.info('pkg_standard_executors.prc_jkins_job_oracle_db - vo_response_code: %s', vo_response_code);
        IF ( vo_response_code = 'OK' ) THEN
            -- Si es OK,invoco al procedimiento de out
            apex_debug.warn('pkg_standard_executors.prc_jkins_job_oracle_db - pi_id_request: %s', pi_id_request);
            apex_debug.warn('pkg_standard_executors.prc_jkins_job_oracle_db - pi_id_req_det: %s', pi_id_req_det);
            prc_jenkins_process_job_out(
                pi_id_request,
                pi_id_req_det,
                pi_category_action,
                pi_environment_alias,
                pi_enviroment_class,
                vo_http_status,
                vo_http_headers,
                vo_body
            );
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4, --- DEBUG
                pi_log_message   => 'Ingreso dentro de response_code: OK'
            );
        ELSE
            -- Si no es OK
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4, --- DEBUG
                pi_log_message   => 'Ingreso dentro de response_code: NO OK - RAISE exc_response_code'
            );
            RAISE exc_response_code;
        END IF;

    EXCEPTION
        WHEN exc_category_action THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_oracle_db (CATEGORY ACTION NO EXISTENTE) - %s', sqlerrm);
            dbms_output.put_line('ERROR - CATEGORY ACTION NO EXISTENTE: '
                                 || pi_category_action
                                 || chr(13)
                                 || 'PLSQL_LINE: '
                                 || $$plsql_line);
            ------------------------------------------------------------------  
            --Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE =>' Error - Category action NO EXISTENTE: '|| pi_category_action,
                                            PI_EXEC_DATE => sysdate) ; 
        ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'Error - Category action NO EXISTENTE: '
                                  || pi_category_action
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );
        ------------------------------------------------------------------  
        WHEN exc_response_code THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_oracle_db (CATEGORY ACTION NO EXISTENTE) - %s', sqlerrm);
            dbms_output.put_line('ERROR -ERROR - RESPONSE_CODE-JENKINS: NO OK '
                                 || chr(13)
                                 || 'PLSQL_LINE: '
                                 || $$plsql_line);
            -- 
            ------------------------------------------------------------------  
            --Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE => ' Error en la invocación REST al Jenkins - Detalle: '|| vo_error_message,
                                            PI_EXEC_DATE => sysdate) ; 
        ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 1, --- ERROR
                pi_log_message   => 'Error en la invocación REST al Jenkins - Detalle: '
                                  || CHR(13)
                                  || vo_error_message
                                  || ' -PLSQL_LINE: '
                                  || $$plsql_line
            );
        ------------------------------------------------------------------  
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_oracle_db - %s', sqlerrm);
            --------------------------------------------------------------------  
            -- Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE => 'Error when others - prc_jkins_job_oracle_db - Detalle: '|| sqlerrm,
                                            PI_EXEC_DATE => sysdate) ; 

            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            ------------------------------------------------------------------  
    END;

/*--------------- SEP5-------------------*/

    PROCEDURE prc_jenkins_process_job_out (
        pi_id_request           NUMBER,
        pi_id_req_det           NUMBER,
        pi_category_action      VARCHAR2,
        pi_environment_alias    VARCHAR2,
        pi_enviroment_class     NUMBER,
        pi_http_status          VARCHAR2,
        pi_http_headers         http_headers_tab,
        pi_body                 CLOB
    ) AS
        v_id_prc_queue      VARCHAR2(100);
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_process_job_out';
    BEGIN
        -- Recorro los HTTP headers y busco el Location,para luego obtener el Queue ID de Jenkins
        FOR i IN 1..pi_http_headers.count LOOP
            IF ( pi_http_headers(i).campo = 'Location' ) THEN
                v_id_prc_queue := replace(substr(pi_http_headers(i).valor, instr(pi_http_headers(i).valor, '/', -2)), '/', '');
                EXIT;
            END IF;
        END LOOP;

        IF ( pi_http_status like '201%' ) THEN
            -- Envío el queueID al pkg_standard_executors.prc_jenkins_check_queue_status
            apex_debug.warn('pkg_standard_executors.prc_jenkins_process_job_out - v_id_prc_queue: %s', v_id_prc_queue);
            pkg_standard_executors.prc_jenkins_check_queue_status(
                    pi_id_request    => pi_id_request,
                    pi_id_req_det    => pi_id_req_det,
                    pi_id_prc_queue  => v_id_prc_queue,
                    pi_category_action => pi_category_action,
                    pi_environment_alias => pi_environment_alias,
                    pi_enviroment_class  =>  pi_enviroment_class
                );
        ELSE
            ------------------------------------------------------------------  
            --Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                                PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                                PI_ID_DET_REQ => pi_id_req_det,
                                                PI_ID_PRC_EXEC => NULL,
                                                PI_STATUS => -4,
                                                PI_EXEC_MESSAGE =>' Error - Se obtuvo un código http distinto a "201" - HTTP_STATUS recibido: '|| pi_http_status,
                                                PI_EXEC_DATE => sysdate) ; 
            ------------------------------------------------------------------    
        END IF;
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_process_job_out - %s', sqlerrm);

            -- Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE => 'EXCEPTION WHEN OTHERS - pkg_standard_executors.prc_jenkins_process_job_out - Detalle: ' || sqlerrm,
                                            PI_EXEC_DATE => sysdate) ; 
            ------------------------------------------------------------------
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            ------------------------------------------------------------------
    END;

/*--------------- SEP6-------------------*/

    PROCEDURE prc_jenkins_get_build_id (
        pi_environment_class  NUMBER,
        pi_id_queue           NUMBER,
        pi_category_action    VARCHAR2, -- BACKUP | CHECKOUT | DEPLOY
        po_id_build           OUT NUMBER
    ) AS
        v_jenkins_url       VARCHAR2(4000);
        v_jenkins_node      VARCHAR2(50);
        v_auth_basic        VARCHAR2(200);
        vi_http_headers     http_headers_tab := http_headers_tab();
        vo_http_headers     http_headers_tab := http_headers_tab();
        vo_http_status      VARCHAR(5);
        vo_body             CLOB;
        vo_response_code    VARCHAR(15);
        vo_error_message    VARCHAR(4000);
        exc_category_action EXCEPTION;
        v_id_build          NUMBER;
        po_response         CLOB;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_get_build_id';
    BEGIN
         -- Defino el nodo de Jenkins a utilizar
        v_jenkins_node                 := fnc_get_jenkins_node(pi_environment_class);     

        -- Busco y armo la URL del Jenkins
        v_jenkins_url := pkg_sicd_commons.get_parameter_value('JENKINS_'
                                                                || fnc_get_jenkins_node(pi_environment_class)
                                                                || '_URL')
                                                                || '/queue';

        pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'item'
                    || '/'
                    || pi_id_queue --queue_ID
                    || '/'
                    || 'api'
                    || '/'
                    || 'json?pretty=true',
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );

        SELECT JSON_VALUE(vo_body, '$.executable.number')
          INTO v_id_build
          FROM dual;

        po_id_build := v_id_build;

        dbms_output.put_line(po_id_build);
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_check_build_status - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*--------------- SEP7-------------------*/

    PROCEDURE prc_jenkins_get_build_status (
        pi_environment_class  NUMBER,       --1-PRIMARY o 0-SECONDARY
        pi_id_build           NUMBER,
        pi_category_action    VARCHAR2,     -- BACKUP | CHECKOUT | DEPLOY
        po_v_result           OUT VARCHAR2,
        po_pipeline_accion    OUT VARCHAR2   --pipBackupOracleDB  |  pipCheckoutOracleDB   | pipDeployOracleDB
    ) AS
        v_jenkins_url       VARCHAR2(4000);
        v_jenkins_node      VARCHAR2(50);
        v_auth_basic        VARCHAR2(200);
        vi_http_headers     http_headers_tab := http_headers_tab();
        vo_http_headers     http_headers_tab := http_headers_tab();
        vo_http_status      VARCHAR(5);
        vo_body             CLOB;
        vo_response_code    VARCHAR(15);
        vo_error_message    VARCHAR(4000);
        exc_category_action EXCEPTION;
        v_result            VARCHAR2(50);
        v_building          VARCHAR2(50);
        v_pipeline_accion   VARCHAR2(50);
        po_response         CLOB;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_get_build_status';
    BEGIN
         -- Defino el nodo de Jenkins a utilizar
        v_jenkins_node := fnc_get_jenkins_node(pi_environment_class);     

         -- Busco y armo la URL del Jenkins
        v_jenkins_url := pkg_sicd_commons.get_parameter_value('JENKINS_'
                                                                || fnc_get_jenkins_node(pi_environment_class)
                                                                || '_URL')
                                                                || '/job';

        CASE pi_category_action
            WHEN 'BACKUP' THEN
                v_pipeline_accion := 'pipBackupOracleDB';
            WHEN 'CHECKOUT' THEN
                v_pipeline_accion := 'pipCheckoutOracleDB';
            WHEN 'DEPLOY' THEN
                v_pipeline_accion := 'pipDeployOracleDB';
        END CASE;
        --Crea la variable de salida po_po_pipeline_accion  
        po_pipeline_accion := v_pipeline_accion;

        ---------------------------------------------
        pkg_sicd_commons.p_rest_call_apim(v_jenkins_url
                    || '/'
                    || v_pipeline_accion
                    || '/'
                    || pi_id_build
              --build_ID
                    || '/'
                    || 'api'
                    || '/'
                    || 'json?pretty=true',--url
                    'POST', --method
                    vo_body, --body
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                    );

        SELECT JSON_VALUE(vo_body, '$.result'),
               JSON_VALUE(vo_body, '$.building')
        INTO v_result,
             v_building
        FROM dual;

        po_v_result := v_result;

        IF v_result = 'null' THEN
      --si  v_result ='null'se encuentra  ejecutandose o en cola
            IF v_building = 'true' THEN
     --si v_building='true' esta esperando

                po_v_result := 'BUILDING';
            ELSE
                po_v_result := v_result;
            END IF;
        ELSE
            po_v_result := v_result;
        END IF;

        dbms_output.put_line(v_result);
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_check_build_status - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*--------------- SEP8-------------------*/

/*--------------- SEP9-------------------*/

    PROCEDURE prc_send_mail (
        pi_notification    IN   CLOB,
        pi_id_sys_profile  IN   NUMBER,
        pi_id_user         IN   NUMBER,
        pi_subject         IN   VARCHAR2,
        po_response_code   OUT  VARCHAR2,
        po_error_message   OUT  VARCHAR2
    ) AS
        v_to                VARCHAR2(4000) := NULL;
        v_payload           CLOB;
        v_header            VARCHAR2(2000) := NULL;
        v_action            VARCHAR2(500) := NULL;
        v_url               VARCHAR2(2000) := NULL;
        v_from              VARCHAR2(2000) := NULL;
        return_value        XMLTYPE;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_send_mail';
    BEGIN
        v_header      := '<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'||chr(10)||'</soap:Header>';
        v_from        := pkg_sicd_commons.get_parameter_value('SICD_EMAIL_MESSAGE_FROM');

        IF nvl(pi_id_user, 0) = 0 THEN
            v_to := pkg_standard_executors.fnc_send_profile_email(pi_id_sys_profile);

            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4,--- DEBUG
                pi_log_message   => 'Se da aviso al correo: ' || v_to || ' perteneciente al id_sys_profile: ' || pi_id_sys_profile
            );

        ELSE
            SELECT unique user_mail
              INTO v_to
              FROM user_roles
             WHERE id_user = pi_id_user;
          -- DBMS_OUTPUT.PUT_LINE('user_mail al cual se envio el correo:  '+v_to);

            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4, --- DEBUG
                pi_log_message   => 'Se da aviso al correo: ' || v_to
            );

        END IF;

        v_payload     := '<v1:mailRequest xmlns:v1="http://www.vatrox.com/servicios/EnviarMail/V1">
    <v1:subject>'
                     || pi_subject
                     || '</v1:subject>
    <v1:to>'
                     || v_to
                     || '</v1:to>
    <v1:cc></v1:cc>
    <v1:bcc></v1:bcc>
    <v1:date></v1:date>
    <v1:from>'
                     || v_from
                     || '</v1:from>
    <v1:payload>'
                     || pi_notification
                     || '</v1:payload>

    <v1:attachment href="string"/>
    </v1:mailRequest>';

        log_collector(
            pi_program_name  => log_program_name,
            pi_log_level     => 4, --- DEBUG
            pi_log_message   => 'v_payload: ' || v_payload
        );

        apex_debug.info('pkg_standard_executors.prc_send_mail - v_payload: %s', v_payload);
        v_url         := pkg_sicd_commons.get_parameter_value('MAILER_URL');
        apex_debug.info('pkg_standard_executors.prc_send_mail - v_url: %s', v_url);
        v_action      := 'EnviarMail';
        return_value  :=
            pkg_standard_executors.fnc_soap_call(
                v_payload,
                v_header,
                v_action,
                v_url,
                'HTTP/1.1',
                'text/xml',
                po_response_code,
                po_error_message
            );

    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_send_mail - %s', sqlerrm);
            po_response_code  := 'ERROR';
            po_error_message  := substr(sqlerrm, 1, 4000);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END prc_send_mail;

/*----------------SEPT10--------------------------------------------------------*/

    PROCEDURE prc_jenkins_get_queue_status (
        pi_id_request         NUMBER,
        pi_id_req_det         NUMBER,
        pi_environment_class  NUMBER,
        pi_id_queue           NUMBER,
        pi_category_action    VARCHAR2,
    -- BACKUP | CHECKOUT | DEPLOY
        po_v_result           OUT  VARCHAR2,
        po_v_building         OUT  VARCHAR2
        --v_pipeline_accion   VARCHAR2;   --pipBackupOracleDB  |  pipCheckoutOracleDB   | pipDeployOracleDB
    ) AS
        v_jenkins_url       VARCHAR2(4000);
        v_jenkins_node      VARCHAR2(50);
        v_auth_basic        VARCHAR2(200);
        vi_http_headers     http_headers_tab := http_headers_tab();
        vo_http_headers     http_headers_tab := http_headers_tab();
        vo_http_status      VARCHAR(5);
        vo_body             CLOB;
        vo_response_code    VARCHAR(15);
        vo_error_message    VARCHAR(4000);
        exc_category_action EXCEPTION;
        v_result            VARCHAR2(50);
        v_building          VARCHAR2(50);
        v_pipeline_accion   VARCHAR2(50);
        po_id_build         NUMBER;
        v_id_build          NUMBER;
        po_response         CLOB;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_get_queue_status';
    BEGIN

        -- Defino el nodo de Jenkins a utilizar
        v_jenkins_node := fnc_get_jenkins_node(pi_environment_class);     

        -- Busco y armo la URL del Jenkins
        v_jenkins_url := pkg_sicd_commons.get_parameter_value('JENKINS_'
                                                                || fnc_get_jenkins_node(pi_environment_class)
                                                                || '_URL')
                                                                || '/job'; 

        --Busco el id_build
        prc_jenkins_get_build_id(
            pi_environment_class, pi_id_queue, pi_category_action, -- BACKUP | CHECKOUT | DEPLOY
            po_id_build);

        v_id_build                     := po_id_build;
        CASE pi_category_action
            WHEN 'BACKUP' THEN
                v_pipeline_accion := 'pipBackupOracleDB';
            WHEN 'CHECKOUT' THEN
                v_pipeline_accion := 'pipCheckoutOracleDB';
            WHEN 'DEPLOY' THEN
                v_pipeline_accion := 'pipDeployOracleDB';
        END CASE;

        pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || v_pipeline_accion
                    || '/'
                    || v_id_build
                    --build_ID
                    || '/'
                    || 'api'
                    || '/'
                    || 'json?pretty=true',
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );

        SELECT JSON_VALUE(vo_body, '$.result'),
               JSON_VALUE(vo_body, '$.building')
          INTO v_result,
               v_building
          FROM dual;

        po_v_result                    := v_result;
              --po_v_building:=v_building;

        dbms_output.put_line(v_result);
        IF v_result = 'null' THEN
      --si  v_result ='null'se encuentra  ejecutandose o en cola
            IF v_building = 'true' THEN
     --si v_building='true' esta esperando

                po_v_result := 'BUILDING';
            ELSE
                po_v_result := v_result;
            END IF;
        ELSE
            po_v_result := v_result;
        END IF;

    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_queue_status - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*----------------SEPT11--------------------------------------------------------*/

    PROCEDURE prc_jenkins_check_build_status (
        pi_id_request         INTEGER,
        pi_id_req_det         INTEGER,
        pi_id_prc_queue       VARCHAR2, --id_queue
        pi_environment_class  NUMBER,
        pi_category_action    VARCHAR2,
        pi_environment_alias  VARCHAR2
    ) AS

        po_id_build         VARCHAR2(50);
        v_id_build          VARCHAR2(50);
        v_queue_timeout     INTEGER := pkg_sicd_commons.get_parameter_value(param_name => 'JENKINS_QUEUE_ADD_TIMEOUT');
        po_v_result         VARCHAR2(50);
        v_status            NUMBER;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jenkins_check_build_status';
        id_status_build     NUMBER;
        po_pipeline_accion  VARCHAR2(50);
        name_job            VARCHAR2(100);
        v_exec_message      VARCHAR2(100);
    BEGIN
        -- Primero busco el build_id con el queue_id, y luego consulto el estado del build_id.
        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4,  --- DEBUG
                        pi_log_message => 'Inicio - ' || log_program_name);  

        ----------------------------------------------------------------
        --Busca el estado del build segun el id_request y el id_control_deploy .
        SELECT
            red.id_deployment_status
        INTO id_status_build
        FROM
            request_exec_deploy red
        WHERE
                id_request = pi_id_request
            AND id_control_deploy = pi_id_req_det;

        -- id_status_build:= nvl(id_status_build,99);
        -------------------------------------------------------------------------
        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4,  --- DEBUG
                        pi_log_message => 'id_status_build: ' || id_status_build);  
        --------------------------------------------------------------------------
        -- Consulto si el estado del build se actualizo o no.
        IF ( id_status_build = 0 ) THEN
            -- No se actualizo, Actualiza el estado del build
            -- Si el build_id esta en ABORTED, FAILED o SUCCESS, actualizo el estado del 'pi_id_req_det'.

            -- Ejecuto prc_jenkins_get_build_id y extraigo el id_build
            prc_jenkins_get_build_id(pi_environment_class, --1-PRIMARY o 0-SECONDARY
                                    pi_id_prc_queue, --=id_queue
                                    pi_category_action,  -- BACKUP | CHECKOUT | DEPLOY
                                    po_id_build);

--        po_id_build := v_id_build;
            v_id_build := po_id_build;

            --ejecuto prc_jenkins_check_build_status extraigo es status del build_id  

            prc_jenkins_get_build_status(pi_environment_class, --1-PRIMARY o 0-SECONDARY
                                        v_id_build,--=pi_id_build
                                        pi_category_action,-- BACKUP | CHECKOUT | DEPLOY
                                        po_v_result, --BUILDING,ABORTED, FAILED o SUCCESS,
                                        po_pipeline_accion);
            log_collector(pi_program_name => log_program_name, pi_log_level => 4,  --- DEBUG
                         pi_log_message => 'id_build   - '
                                           || v_id_build
                                           || 'po_result'
                                           || po_v_result
                                           || 'po_pipeline_accion'
                                           || po_pipeline_accion);

            IF ( po_v_result <> 'BUILDING' ) THEN
                IF ( po_v_result = 'SUCCESS' ) THEN
                    v_status := 1;
                    v_exec_message := 'Warning: Jenkins no informó el estado final del Build - Resultado final = Success';
                ELSE
                    v_status := -1;
                    v_exec_message := 'Error en ejecución de Jenkins - Verifique el log.';
                END IF;

                pkg_deploy_coordinator.execution_status(pi_id_request => pi_id_request,
                                                       pi_environment_alias => pi_environment_alias,
                                                       pi_id_det_req => pi_id_req_det,
                                                       pi_id_prc_exec => 'jenkins-'
                                                                         || po_pipeline_accion
                                                                         || '-'
                                                                         || po_id_build,
                                                       pi_status => v_status,
                                                       pi_exec_message => v_exec_message,
                                                       pi_exec_date => sysdate);
            ------------------------------------------------------
                -- Actualizo el id_dep_proc en la tabla request_exec_deploy
                UPDATE request_exec_deploy ed
                SET
                    ed.id_dep_proc = 'jenkins-'
                                     || po_pipeline_accion
                                     || '-'
                                     || po_id_build
                WHERE
                        ed.id_request = pi_id_request
                    AND ed.id_control_deploy = pi_id_req_det;

                log_collector(pi_program_name => log_program_name, 
                                pi_log_level => 4,  --- DEBUG
                                pi_log_message => 'Salió del procedimiento execution_status ');
            ELSE    
                --po_v_result = 'BUILDING' 
                -- Actualizo el estado del id_control_deploy 
                log_collector(pi_program_name => log_program_name, 
                                pi_log_level => 4,  --- DEBUG
                                pi_log_message => 'Entro en el else por que po_v_result = BUILDING');
                pkg_deploy_coordinator.execution_status(pi_id_request => pi_id_request,
                                                       pi_environment_alias => pi_environment_alias,
                                                       pi_id_det_req => pi_id_req_det,
                                                       pi_id_prc_exec => 'jenkins-'
                                                                         || po_pipeline_accion
                                                                         || '-'
                                                                         || po_id_build,
                                                       pi_status => - 1,
                                                       pi_exec_message => 'Error en ejecucion de Jenkins - Verifique el log.',
                                                       pi_exec_date => sysdate);

                UPDATE request_exec_deploy ed
                SET
                    ed.id_dep_proc = 'jenkins-'
                                     || po_pipeline_accion
                                     || '-'
                                     || po_id_build
                WHERE
                        ed.id_request = pi_id_request
                    AND ed.id_control_deploy = pi_id_req_det;

            END IF;

        ELSE
            IF ( id_status_build IS NULL ) THEN
                log_collector(pi_program_name => log_program_name, pi_log_level => 4,  --- DEBUG
                             pi_log_message => 'entro dentro del id_status_build = (null)   ');
                prc_jenkins_get_build_id(pi_environment_class, --1-PRIMARY o 0-SECONDARY
                                        pi_id_prc_queue, --=id_queue
                                        pi_category_action,  -- BACKUP | CHECKOUT | DEPLOY
                                        po_id_build);


                v_id_build := po_id_build;

                -- Ejecuto prc_jenkins_check_build_status extraigo es status del build_id  

                prc_jenkins_get_build_status(pi_environment_class, --1-PRIMARY o 0-SECONDARY
                                            v_id_build,--=pi_id_build
                                            pi_category_action,-- BACKUP | CHECKOUT | DEPLOY
                                            po_v_result, --BUILDING,ABORTED, FAILED o SUCCESS,
                                            po_pipeline_accion);
                IF ( po_v_result = 'SUCCESS' ) THEN
                    v_status := 1;
                    v_exec_message := 'Warning: Jenkins no informó el estado final del Build - Resultado final = Success';
                ELSE
                    v_status := -1;
                    v_exec_message := 'Error en ejecución de Jenkins - Verifique el log.';
                END IF;

                pkg_deploy_coordinator.execution_status(pi_id_request => pi_id_request,
                                                       pi_environment_alias => pi_environment_alias,
                                                       pi_id_det_req => pi_id_req_det,
                                                       pi_id_prc_exec => 'jenkins-'
                                                                         || po_pipeline_accion
                                                                         || '-'
                                                                         || po_id_build,
                                                       pi_status => v_status,
                                                       pi_exec_message => v_exec_message,
                                                       pi_exec_date => sysdate);
            ------------------------------------------------------
            -- Actualizo el id_dep_proc en la tabla request_exec_deploy
                UPDATE request_exec_deploy ed
                SET ed.id_dep_proc = 'jenkins-' || po_pipeline_accion || '-' || po_id_build
                WHERE ed.id_request = pi_id_request
                AND ed.id_control_deploy = pi_id_req_det;

            ELSE
                NULL;
            END IF;
        END IF;

        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4,  --- DEBUG
                        pi_log_message => 'Fin Procedimiento  - ' || log_program_name || ' - Estado del Build en Jenkins: '
                           || po_v_result || ' - ' || sysdate);

    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jenkins_check_build_status - %s', sqlerrm);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;


/*----------------SEPT12--------------------------------------------------------*/ 

    PROCEDURE prc_configure_message (
        pi_id_action       IN   NUMBER,
        pi_id_request      IN   NUMBER,
        pi_observation     IN   VARCHAR2,
        pi_request_status  IN   VARCHAR2,
        pi_request_flow_message   IN   VARCHAR2,
        pi_enviroment_type  IN  VARCHAR2,  ---Ambiente testing / Ambiente productivo
        pi_deployment_type IN   VARCHAR2,  -- Estandar 
        pi_enviroment_alias      IN  VARCHAR2,
        po_subject         OUT  VARCHAR2,
        po_message         OUT  CLOB,
        po_message_type    OUT  NUMBER
    ) IS
        ---action_message_conf
        v_response_code   VARCHAR2(4000);
        v_error_message   VARCHAR2(4000);
        r_drh             deployment_req_hgroup%rowtype;
        v_step_flow       NUMBER(38, 0);
        log_program_name  VARCHAR2(100) := 'pkg_standard_executors.prc_configure_message';
        r_ref_message_type Number(2);
        r_ref_subject     VARCHAR2(200);
        r_ref_body        VARCHAR2(4000);
        v_err_msg         VARCHAR2(2000);
        v_err_code        VARCHAR2(50);
    BEGIN
        log_collector(pi_program_name => log_program_name, pi_log_level => 4,
        --- DEBUG
                     pi_log_message => 'Inicio Procedimiento prc_configure_message - '
                                       || log_program_name
                                       || ': '
                                       || sysdate);

        ------------------------------------------
        -- Busco el cuerpo,asunto,tipo de mensensaja,etc segun la accion realizada
        BEGIN
            IF pi_request_flow_message='REQUEST_WORKFLOW' THEN

                SELECT
                    am.action_message_type,am.action_message_subject,am.action_message_body 
                INTO r_ref_message_type,r_ref_subject,r_ref_body
                FROM
                    action_message am 
                WHERE
                    am.id_action = pi_id_action
                    AND am.action_message_status= 1;

            ELSE IF pi_request_flow_message='REQUEST_DEPLOYMENT' THEN


               SELECT
                  am.deploy_status_message_type,am.deploy_status_message_subject,am.deploy_status_message_body
                INTO r_ref_message_type,r_ref_subject,r_ref_body
                FROM
                    deploy_status_message am 
                WHERE
                    am.id_deploy_status_message= pi_id_action
                AND am.deploy_status_message_status= 1;


                END IF;
            END IF;
        EXCEPTION
            WHEN OTHERS THEN
                v_err_code := sqlcode;
                v_err_msg := substr(sqlerrm, 1, 1000);
                log_collector(pi_program_name => log_program_name, 
                                pi_log_level => 1, --- ERROR
                                pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                                ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
        END;
        --
        ------------------------------------------
        -- Busco el Nº completo de la request (REQ_HGROUP_NAME)  
        BEGIN
            SELECT
                r_drh.*
            INTO r_drh
            FROM
                deployment_req_hgroup r_drh
            WHERE
                    r_drh.id_request = pi_id_request
                AND r_drh.id_req_hgroup_level = 'R';

        EXCEPTION
            WHEN OTHERS THEN
                v_err_code := sqlcode;
                v_err_msg := substr(sqlerrm, 1, 1000);
                log_collector(pi_program_name => log_program_name, 
                                pi_log_level => 1, --- ERROR
                                pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                                ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
        END;   
        ------------------------------------------    
        ----------  --Crea y extrae  el Cuerpo del mensage
        IF pi_enviroment_alias IS NULL THEN
            IF pi_observation IS NULL THEN
                po_message := 'Solicitud Nº '
                                  || r_drh.req_hgroup_name
                                  || chr(10) || chr(10)
                                  || 'Estado de la solicitud: '
                                  || pi_request_status
                                  || chr(10) || chr(10)
                                  || 'Tipo de Ambiente: '
                                  || pi_enviroment_type
                                  || chr(10) || chr(10)
                                  || 'Tipo de Solicitud: '
                                  || pi_deployment_type
                                  || chr(10) || chr(10)
                                  || 'Detalle: '
                                  || r_ref_body
                                  || chr(10) || chr(10)
                                  || 'Observaciones: sin observaciones' 
                                  || chr(10) || chr(10)
                                  || 'Fecha: '
                                  || sysdate ;
            ELSE
                po_message := 'Solicitud Nº '
                                  || r_drh.req_hgroup_name
                                  || chr(10) || chr(10)
                                  || 'Estado de la solicitud: '
                                  || pi_request_status
                                  || chr(10) || chr(10)
                                  || 'Tipo de Ambiente: '
                                  || pi_enviroment_type
                                  || chr(10) || chr(10)
                                  || 'Tipo de Solicitud: '
                                  || pi_deployment_type
                                  || chr(10) || chr(10)
                                  || 'Detalle: '
                                  || r_ref_body
                                  || chr(10) || chr(10)
                                  || 'Observaciones: '
                                  || utl_url.unescape(replace(pi_observation, '+', ' '), 'UTF-8')
                                  || chr(10) || chr(10)
                                  || 'Fecha: '
                                  || sysdate;


            END IF;
        -- Creo y extraigo el cuerpo del mensage
        ELSE
            IF pi_observation IS NULL THEN
                po_message := 'Solicitud Nº '
                                  || r_drh.req_hgroup_name
                                  || chr(10) || chr(10)
                                  || 'Estado de la solicitud: '
                                  || pi_request_status
                                  || chr(10) || chr(10)
                                  || 'Tipo de Ambiente: '
                                  || pi_enviroment_type
                                  || chr(10) || chr(10)
                                  || 'Ambiente Destino: '
                                  || pi_enviroment_alias
                                  || chr(10) || chr(10)
                                  || 'Tipo de Solicitud: '
                                  || pi_deployment_type
                                  || chr(10) || chr(10)
                                  || 'Detalle: '
                                  || r_ref_body
                                  || chr(10) || chr(10)
                                  || 'Observaciones: sin observaciones' 
                                  || chr(10) || chr(10)
                                  || 'Fecha: '
                                  || sysdate ;
            ELSE
                po_message := 'Solicitud Nº '
                                  || r_drh.req_hgroup_name
                                  || chr(10) || chr(10)
                                  || 'Estado de la solicitud: '
                                  || pi_request_status
                                  || chr(10) || chr(10)
                                  || 'Tipo de Ambiente: '
                                  || pi_enviroment_type
                                  || chr(10) || chr(10)
                                  || 'Ambiente Destino: '
                                  || pi_enviroment_alias
                                  || chr(10) || chr(10)
                                  || 'Tipo de Solicitud: '
                                  || pi_deployment_type
                                  || chr(10) || chr(10)
                                  || 'Detalle: '
                                  || r_ref_body
                                  || chr(10) || chr(10)
                                  || 'Observaciones: '
                                  || utl_url.unescape(replace(pi_observation, '+', ' '), 'UTF-8')
                                  || chr(10) || chr(10)
                                  || 'Fecha: '
                                  || sysdate;


            END IF;
        END IF;
        --
        ------------------------------------------      
        -- Creo y extraago el asunto del mensage a enviar
        po_subject := r_ref_subject
                      || ' - Nº '
                      || r_drh.req_hgroup_name
                      || ' - '
                      || to_char(sysdate, 'DD/MM/YYYY - HH24:MI:SS');

        -- Extraigo el tipo de mensage
        po_message_type := r_ref_message_type;
        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'El asunto del mensaje es: ' || po_subject);

        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'La notificación es: ' || po_message);

        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'Fin Procedimiento - ' || log_program_name);

    EXCEPTION
        WHEN no_data_found THEN
            dbms_output.put_line('No datos');
            v_err_code := sqlcode;
            v_err_msg := substr(sqlerrm, 1, 1000);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 4, --- DEBUG
                            pi_log_message => 'Error tipo: No data found - ' || v_err_msg);

        WHEN OTHERS THEN
            v_err_code := sqlcode;
            v_err_msg := substr(sqlerrm, 1, 1000);
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*----------------SEPT13--------------------------------------------------------*/
    PROCEDURE prc_send_deploy_status_message (
        pi_id_request            IN  NUMBER,
        pi_id_control_deploy     IN  NUMBER,
        pi_observation           IN  VARCHAR2,
        pi_request_flow_message  IN  VARCHAR2,  --'REQUEST_WORKFLOW' /  REQUEST_DEPLOYMENT
        pi_id_prc_exec           IN  VARCHAR2
    ) IS

        po_subject                  VARCHAR2(200);
        po_message                  VARCHAR2(4000);
        po_message_type             NUMBER(2);
        v_notification              CLOB;
        po_response_code            VARCHAR2(4000);
        po_error_message            VARCHAR2(4000);
        v_nn_id_sys_profile         NUMBER := 0;
        v_request_status            VARCHAR2(100);
        v_id_deploy_status_message  NUMBER := 0;
        v_deploy_status_message     NUMBER := 0;
        v_enviroment_type           VARCHAR2(100);
        v_deployment_type           VARCHAR2(100);
        v_enviroment_type_class     NUMBER := 0;
        v_enviroment_alias          VARCHAR2(100);
        v_id_dep_req_object         NUMBER := 0;
        v_id_dep_req_object_max     NUMBER := 0;
        v_bandera                   NUMBER := 0; 
        v_id_pattern                NUMBER := 0;
        v_id_pattern_step           NUMBER := 0;
        v_id_deployment_status      NUMBER := 0;
        v_retry_number              NUMBER := 0;
        v_retries_error             NUMBER := 0;
        v_retries_timeout           NUMBER := 0;
        log_program_name            VARCHAR2(100) := 'pkg_standard_executors.prc_send_deploy_status_message';
    BEGIN
        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'COMIENZO procedimiento prc_send_deploy_status_message ');

       ---------------------------------------------  
       ---Busca el estado de la solicitud (En proceso,Con Errores,Abortada ó Finalizada)
        SELECT
            dr.request_status
        INTO v_request_status
        FROM
            deployment_request dr
        WHERE
            dr.id_request = pi_id_request;

       ---------------------------------------------------------------
       --- Busca si el estado de la solicitud tiene habilitado la notificacion ( =1 )
        SELECT
            dsm.deploy_status_message_status
        INTO v_deploy_status_message
        FROM
            deploy_status_message dsm
        WHERE
            dsm.dep_request_status = v_request_status;


        IF v_deploy_status_message = 1 THEN

             CASE v_request_status

                     WHEN 'Finalizada' THEN

                        SELECT id_dep_req_object 
                        INTO v_id_dep_req_object 
                        FROM request_exec_deploy
                        where id_request=pi_id_request
                        AND id_control_deploy=pi_id_control_deploy;

                        SELECT max(id_dep_req_object) 
                        INTO v_id_dep_req_object_max 
                        FROM request_exec_deploy
                        where id_request=pi_id_request;

                        --- comparo el id_dep_req_object  es igual al maxino el maximo id_dep_req_object de la tabla deployment_req_object
                        IF  v_id_dep_req_object=v_id_dep_req_object_max THEN

                            v_bandera:=1;
                            log_collector(pi_program_name => log_program_name, 
                                            pi_log_level => 4, --- DEBUG
                                            pi_log_message => 'Ingreso dentro de Finalizada v_bandera: ' || v_bandera);
                        ELSE
                            v_bandera:=0;

                        END IF;

                      WHEN 'Con Errores' THEN  

                        SELECT id_pattern, id_pattern_step,retry_numer,id_deployment_status
                        into v_id_pattern, v_id_pattern_step,v_retry_number,v_id_deployment_status
                        from request_exec_deploy
                        where id_request=pi_id_request
                        AND id_control_deploy=pi_id_control_deploy;


                        SELECT retries_error, retries_timeout
                        into  v_retries_error, v_retries_timeout
                        From deployment_pattern_step
                        where id_pattern_step = v_id_pattern_step
                        AND id_pattern = v_id_pattern;


                        IF (v_id_deployment_status=-3 AND v_retry_number=v_retries_timeout) OR 
                           (v_id_deployment_status=-1 AND v_retry_number=v_retries_error) THEN

                                 v_bandera:=1;

                                 log_collector(pi_program_name => log_program_name, 
                                                pi_log_level => 4, --- DEBUG
                                                pi_log_message => 'Ingreso dentro de Con error v_bandera: ' || v_bandera);
                         ELSE
                                 v_bandera:=0;

                         END IF;       

                     WHEN 'Abortada' THEN  --para futuros usos
                        v_bandera:=1;

                     WHEN 'En Proceso' THEN --para futuros usos
                        v_bandera:=0 ; 
                     ELSE
                        NULL;

                 END CASE;   

             IF v_bandera=1 THEN
                ---Busca el tipo de ambiente de la solicitud (Ambiente productivo / Ambiento no productivo)

                log_collector(pi_program_name => log_program_name, 
                                pi_log_level => 4, --- DEBUG
                                pi_log_message => 'Ingreso dentro de v_bandera: 1 - va a enviar email.');
                SELECT
                    enviroment_type_name
                INTO v_enviroment_type
                FROM
                    enviroment_type
                WHERE
                    id_enviroment_type = (
                        SELECT
                            dr.id_enviroment_type
                        FROM
                            deployment_request dr
                        WHERE
                            dr.id_request = pi_id_request
                    );
                ---------------------------------------------
                ---Busca el tipo de solicitud (ESTANDAR / OTROS)
                SELECT
                    deployment_type
                INTO v_deployment_type
                FROM
                    deployment_type
                WHERE
                    id_deployment_type = (
                        SELECT
                            dr.id_deployment_type
                        FROM
                            deployment_request dr
                        WHERE
                            dr.id_request = pi_id_request
                    );
                --------------------------------------------------

                ----Busca el alias del ambiente de la solicitud 
                SELECT ENVIROMENT_ALIAS
                    INTO v_enviroment_alias
                    FROM ENVIROMENT
                    WHERE ID_ENVIROMENT=(SELECT red.id_enviroment
                                        FROM REQUEST_EXEC_DEPLOY red
                                        WHERE red.id_request= pi_id_request
                                        AND red.id_control_deploy=(select max(id_control_deploy)
                                              from request_exec_deploy
                                              where id_request=pi_id_request ));
                ---------------------------------------------------

                CASE v_request_status
                    WHEN 'En Proceso' THEN
                        v_id_deploy_status_message := 1;
                    WHEN 'Con Errores' THEN
                        v_id_deploy_status_message := 2;
                    WHEN 'Abortada' THEN
                        v_id_deploy_status_message := 3;
                    WHEN 'Finalizada' THEN
                        v_id_deploy_status_message := 4;
                    ELSE
                        NULL;
                END CASE;

                ---- Crea el subject y body del email a enviar
                pkg_standard_executors.prc_configure_message(pi_id_action => v_id_deploy_status_message, pi_id_request => pi_id_request,
                                                   pi_observation => pi_observation,
                                                   pi_request_status => v_request_status,
                                                   pi_request_flow_message => pi_request_flow_message,
                                                   pi_enviroment_type => v_enviroment_type,  ---Ambiente testing / Ambiente productivo
                                                   pi_deployment_type => v_deployment_type,  --Estandar
                                                   pi_enviroment_alias =>  v_enviroment_alias,
                                                   po_subject => po_subject,
                                                   po_message => v_notification,
                                                   po_message_type => po_message_type);

                --------------
                ---Se reemplaza las variables particulares de cada mensaje

                CASE v_request_status
                    WHEN 'En Proceso' THEN
                        v_notification := replace(v_notification, '|link|', pkg_sicd_commons.get_parameter_value('SICD_URL'));
                    WHEN 'Con Errores' THEN
                        v_notification := replace(v_notification, '|link|', fnc_get_jenkins_log_url(pi_id_prc_exec));
                    WHEN 'Abortada' THEN
                        v_notification := replace(v_notification, '|link|', pkg_sicd_commons.get_parameter_value('SICD_URL'));
                    WHEN 'Finalizada' THEN
                        v_notification := replace(v_notification, '|link|', pkg_sicd_commons.get_parameter_value('SICD_URL'));
                    ELSE
                        v_notification := replace(v_notification, '|link|', pkg_sicd_commons.get_parameter_value('SICD_URL'));
                END CASE;

                ----Analiza el Subject 
                SELECT
                    enviroment_type_class
                INTO v_enviroment_type_class
                FROM
                    enviroment_type
                WHERE
                    id_enviroment_type = (
                        SELECT
                            dr.id_enviroment_type
                        FROM
                            deployment_request dr
                        WHERE
                            dr.id_request = pi_id_request
                    );

                IF v_enviroment_type_class = 0 THEN
                    po_subject := replace(po_subject, '|envType|', '(No PRD)');
                ELSIF v_enviroment_type_class = 1 THEN
                    po_subject := replace(po_subject, '|envType|', '(PRD)');
                END IF;

                ---------------------------------------------------------------------------
                ----- Envio de notificación a todos los intervinientes activos de dicha solicitud ---

                FOR c_user IN (
                    SELECT DISTINCT ref.id_user
                        FROM request_exec_flow ref
                        INNER JOIN user_roles ur 
                        ON ref.id_user = ur.id_user
                        WHERE ref.id_request = pi_id_request
                        AND ref.status_result IS NOT NULL
                        AND ur.user_status = 1
                        UNION
                        SELECT ur.id_user
                        FROM user_roles ur
                        WHERE UPPER(ur.user_name) = (SELECT UPPER(dr.user_create)
                                                        FROM deployment_request dr
                                                        WHERE dr.id_request = pi_id_request)
                ) LOOP
                    IF po_message_type = 1 THEN
                        --llama al procedimiento de envio de email
                        pkg_standard_executors.prc_send_mail(pi_notification => v_notification, pi_id_sys_profile => NULL,
                                                            pi_id_user => c_user.id_user,
                                                            pi_subject => po_subject,
                                                            po_response_code => po_response_code,
                                                            po_error_message => po_error_message);

                    ELSE
                                --- v_message_type distinto de  1
                        NULL;
                    END IF;
                END LOOP;
            END IF;
        ELSE
            NULL;
        END IF;

        log_collector(pi_program_name => log_program_name, 
                        pi_log_level => 4, --- DEBUG
                        pi_log_message => 'FIN procedimiento prc_send_deploy_status_message');
    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_deploy_coordinator.update_dep_control - %s', sqlerrm);
            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*----------------SEPT14--------------------------------------------------------*/
    PROCEDURE prc_send_action_message (
        pi_id_action             IN  NUMBER,
        pi_id_request            IN  NUMBER,
        pi_observation           IN  VARCHAR2,
        pi_request_status        IN  VARCHAR2,
        pi_request_flow_message  IN  VARCHAR2,  --'REQUEST_WORKFLOW' /  REQUEST_DEPLOYMENT
        pi_id_sys_profile        IN  NUMBER,
        pi_id_next_user          IN  NUMBER
    ) IS
        po_subject              VARCHAR2(200);
        po_message              VARCHAR2(4000);
        po_message_type         NUMBER(2);
        v_notification          CLOB;
        po_response_code        VARCHAR2(4000);
        po_error_message        VARCHAR2(4000);
        v_nn_id_sys_profile     NUMBER := 0;
        v_subject               VARCHAR2(200);
        v_message_type          NUMBER := 0;
        v_enviroment_type       VARCHAR2(100);
        v_deployment_type       VARCHAR2(100);
        v_enviroment_alias      VARCHAR2(100);
        log_program_name        VARCHAR2(100) := 'pkg_standard_executors.prc_send_action_message';
    BEGIN
        ---busca el tipo de ambiente (Productiva / No productiva)
        SELECT
            enviroment_type_name
        INTO v_enviroment_type
        FROM
            enviroment_type
        WHERE
            id_enviroment_type = (
                SELECT
                    dr.id_enviroment_type
                FROM
                    deployment_request dr
                WHERE
                    dr.id_request = pi_id_request
            );

        ---busca el tipo de solicitud (ESTANDAR/ OTRO)
        SELECT
            deployment_type
        INTO v_deployment_type
        FROM
            deployment_type
        WHERE
            id_deployment_type = (
                SELECT
                    dr.id_deployment_type
                FROM
                    deployment_request dr
                WHERE
                    dr.id_request = pi_id_request
            );

       --Ejecuta procedimeinto para configuracion y contenido del mensaje

        pkg_standard_executors.prc_configure_message(pi_id_action => pi_id_action, pi_id_request => pi_id_request, pi_observation => pi_observation,
                                           pi_request_status => pi_request_status,
                                           pi_request_flow_message => pi_request_flow_message, --'REQUEST_WORKFLOW',
                                           pi_enviroment_type => v_enviroment_type,
                                           pi_deployment_type => v_deployment_type,
                                           pi_enviroment_alias =>  null,
                                           po_subject => v_subject,
                                           po_message => v_notification,
                                           po_message_type => v_message_type);

        IF v_message_type = 1 THEN
        ------------------------------------------------------------------
        ---Se reemplaza las variables particulares de cada mensaje
            v_notification := replace(v_notification, '|link|', pkg_sicd_commons.get_parameter_value('SICD_URL'));

         --Si no se selecciono ningun usuario de destino de notificacion
             IF pi_id_next_user IS NULL THEN

                   --Busca todos los usuarios activos del id_sys_profile responsable del paso
                    FOR c_user IN (
                       SELECT ur.ID_USER 
                       FROM USER_ROLES ur
                       WHERE ur.ID_SYS_PROFILE=pi_id_sys_profile
                       AND USER_STATUS = 1)

                    LOOP
                    --Llama al procedimiento de envio de email
                        pkg_standard_executors.prc_send_mail(pi_notification => v_notification, 
                                                            pi_id_sys_profile => pi_id_sys_profile,
                                                            pi_id_user => c_user.id_user,
                                                            pi_subject => v_subject,
                                                            po_response_code => po_response_code,
                                                            po_error_message => po_error_message);                                                            
                    END LOOP;

             --Si se selecciono usuario
              ELSE
                  --Envia notificacion a usuario seleccionado 

                 --Llama al procedimiento de envio de email
                    pkg_standard_executors.prc_send_mail(pi_notification => v_notification, 
                                                        pi_id_sys_profile => pi_id_sys_profile, --deberia entrar un valor NULL en esta variable
                                                        pi_id_user => pi_id_next_user,   
                                                        pi_subject => v_subject,
                                                        po_response_code => po_response_code,
                                                        po_error_message => po_error_message);
              END IF;

        ELSE
            NULL;
        END IF;

    EXCEPTION
        WHEN OTHERS THEN
            apex_debug.error('pkg_deploy_coordinator.update_dep_control - %s', sqlerrm);
            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
    END;

/*--------------- SEP15-------------------*/

    PROCEDURE prc_jkins_job_ipolaris_java_wb (
        pi_category_action       VARCHAR2,  -- CHECKOUT | COMPILE | DEPLOY
        pi_id_request            NUMBER,  -- id de la solicitud 1
        pi_id_req_det            NUMBER,  -- detalle solictud
        pi_environment_alias     VARCHAR2,  --IPOLARIDES
        pi_scm_alias             VARCHAR2,  
        pi_repository_path       VARCHAR2,  --LaCaja/iPolaris/archive/
        pi_componentes   		 CLOB,
		pi_enviroment_class      NUMBER,
           -- 0: NO PRODUCTIVO | 1: PRODUCTIVO
        pi_build_timeout         NUMBER,
        pi_version               VARCHAR2
    ) AS
        v_jenkins_node      VARCHAR2(50);
        v_auth_basic        VARCHAR2(200);
        vi_http_headers     http_headers_tab := http_headers_tab();
        vo_http_headers     http_headers_tab := http_headers_tab();
        v_jenkins_url       VARCHAR2(4000);
        vo_http_status      VARCHAR(20);
        vo_body             CLOB;
        vo_response_code    VARCHAR(15);
        vo_error_message    VARCHAR(4000);
        exc_category_action EXCEPTION;
        exc_response_code   EXCEPTION;
        v_profile           VARCHAR2(20):= '-Pprod'; 
        v_sedURL            VARCHAR2(50);
        po_response         CLOB;
        log_program_name    VARCHAR2(100) := 'pkg_standard_executors.prc_jkins_job_ipolaris_java_wb';
    BEGIN
        -- Defino el nodo de Jenkins a utilizar  
        v_jenkins_node := fnc_get_jenkins_node(pi_enviroment_class); 
        apex_debug.info('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - v_jenkins_node: %s', v_jenkins_node);       

        -- Busco y armo la URL del Jenkins
        v_jenkins_url := pkg_sicd_commons.get_parameter_value('JENKINS_'
                                                                || v_jenkins_node
                                                                || '_URL')
                                                                || '/job';

        apex_debug.info('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - v_jenkins_url: %s', v_jenkins_url);
        -- Dependiendo de la acción enviada, invoco al Jenkins con los parámetros correspondientes

        CASE pi_category_action
            WHEN 'CHECKOUT' THEN
                pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'ipolaris_checkout'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'environmentAlias'
                    || pi_environment_alias
                    || '&'
                    || 'profile='
                    ||  v_profile
                    || '&'
                    || 'version='
                    ||  pi_version
                    || '&'
                    || 'scmAlias='
                    || pi_scm_alias
                    || '&'
                    || 'repository_path='
                    || pi_repository_path,
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );
			WHEN 'COMPILE' THEN
                pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'ipolaris_compile'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'profile='
                    ||  v_profile
                    || '&'
                    || 'version='
                    ||  pi_version
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'environmentAlias'
                    || pi_environment_alias,
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );
            WHEN 'DEPLOY' THEN
                pkg_sicd_commons.p_rest_call_apim(
                    v_jenkins_url
                    || '/'
                    || 'ipolaris_deploy'
                    || '/'
                    || 'buildWithParameters'
                    || '?'
                    || 'piIdRequest='
                    || pi_id_request
                    || '&'
                    || 'piIdDetReq='
                    || pi_id_req_det
                    || '&'
                    || 'buildTimeout='
                    || pi_build_timeout
                    || '&'
                    || 'environmentAlias='
                    || pi_environment_alias
                    || '&'
                    || 'profile='
                    ||  v_profile
                    || '&'
                    || 'version='
                    ||  pi_version
                    || '&'
                    || 'componentes='
                    || pi_componentes,
                    'POST',
                    vo_body,
                    vo_http_status,
                    vo_http_headers,
                    po_response,
                    vo_response_code,
                    vo_error_message
                );
            WHEN 'ROLLBACK' THEN
                        ------------------------------------------------------------------        
                log_collector(
                    pi_program_name  => log_program_name,
                    pi_log_level     => 2, --- WARNING
                    pi_log_message   => 'ROLLBACK: '
                );
                        ------------------------------------------------------------------  
            ELSE
                RAISE exc_category_action;
        END CASE;

        log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4,--- DEBUG
                pi_log_message   => 'LOG next - case - Code: '
                                  || vo_response_code
                                  || CHR(13)
                                  || ' - vo_error_message: '
                                  || vo_error_message
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );

        log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 4, --- DEBUG
                pi_log_message   => 'Body: '
                                  || vo_body
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            ); 

        -- Analizo el response_code
        apex_debug.info('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - vo_response_code: %s', vo_response_code);
        IF ( vo_response_code = 'OK' ) THEN
            -- Si es OK, invoco al procedimiento de OUT
            apex_debug.warn('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - pi_id_request: %s', pi_id_request);
            apex_debug.warn('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - pi_id_req_det: %s', pi_id_req_det);
            prc_jenkins_process_job_out(
                pi_id_request,
                pi_id_req_det,
                pi_category_action,
                pi_environment_alias,
                pi_enviroment_class,
                vo_http_status,
                vo_http_headers,
                vo_body
            );
            log_collector(
                    pi_program_name  => log_program_name,
                    pi_log_level     => 4, --- DEBUG
                    pi_log_message   => 'Ingreso dentro de response_code: OK ');
        ELSE
            -- Si no es OK
            log_collector(
                    pi_program_name  => log_program_name,
                    pi_log_level     => 4, --- DEBUG
                    pi_log_message   => 'Ingreso dentro de response_code: NO OK - RAISE exc_response_code'
            );
            RAISE exc_response_code;
        END IF;

    EXCEPTION
        WHEN exc_category_action THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb (CATEGORY ACTION NO EXISTENTE) - %s', sqlerrm);
            dbms_output.put_line('ERROR - CATEGORY ACTION NO EXISTENTE: '
                                 || pi_category_action
                                 || chr(13)
                                 || 'PLSQL_LINE: '
                                 || $$plsql_line);
            ------------------------------------------------------------------  
            -- Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE =>' Error - Category action NO EXISTENTE: '|| pi_category_action,
                                            PI_EXEC_DATE => sysdate) ; 
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'Error - Category action NO EXISTENTE: '
                                  || pi_category_action
                                  || CHR(13)
                                  || 'PLSQL_LINE: '
                                  || $$plsql_line
            );
            ------------------------------------------------------------------  
        WHEN exc_response_code THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb (CATEGORY ACTION NO EXISTENTE) - %s', sqlerrm);
            dbms_output.put_line('ERROR -ERROR - RESPONSE_CODE-JENKINS: NO OK '
                                 || chr(13)
                                 || 'PLSQL_LINE: '
                                 || $$plsql_line);
            -- 
            ------------------------------------------------------------------  
            -- Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE => 'Error en la invocación REST al Jenkins - Detalle: '|| vo_error_message,
                                            PI_EXEC_DATE => sysdate) ; 
            ------------------------------------------------------------------        
            log_collector(
                pi_program_name  => log_program_name,
                pi_log_level     => 2, --- WARNING
                pi_log_message   => 'Error en la invocación REST al Jenkins - Detalle: '
                                  || CHR(13)
                                  || vo_error_message
                                  || ' -PLSQL_LINE: '
                                  || $$plsql_line
            );
            ------------------------------------------------------------------  
        WHEN OTHERS THEN
            apex_debug.error('pkg_standard_executors.prc_jkins_job_ipolaris_java_wb - %s', sqlerrm);
            --------------------------------------------------------------------  
            -- Actualizo el estado de la solicitud
            PKG_DEPLOY_COORDINATOR.execution_status (  PI_ID_REQUEST => PI_ID_REQUEST,
                                            PI_ENVIRONMENT_ALIAS => PI_ENVIRONMENT_ALIAS,
                                            PI_ID_DET_REQ => pi_id_req_det,
                                            PI_ID_PRC_EXEC => NULL,
                                            PI_STATUS => -4,
                                            PI_EXEC_MESSAGE => 'Error when others - prc_jkins_job_ipolaris_java_wb - Detalle: '|| sqlerrm,
                                            PI_EXEC_DATE => sysdate) ; 
            ------------------------------------------------------------------        
            log_collector(pi_program_name => log_program_name, 
                            pi_log_level => 1, --- ERROR
                            pi_log_message => substr('Error EXCEPTION WHEN OTHERS - Detalle del error: ' || sqlerrm 
                                            ||  ' - Ubicación: ' || DBMS_UTILITY.format_error_backtrace, 1, 3900));
            ------------------------------------------------------------------  
    END;

----------------------------------------------------------------------------

END pkg_standard_executors;

/
