--------------------------------------------------------
--  DDL for View HIERARCHICAL_WORKFLOW_ENV_TYPE
--------------------------------------------------------

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "ENVX_OPER"."HIERARCHICAL_WORKFLOW_ENV_TYPE" ("LEVEL_ALIAS", "ID", "PARENT_ID", "GROUP_ID", "LEVEL_PATH_ID", "LEVEL_ORDER", "LEVEL_NAME", "LEVEL_STATUS", "DESCRIPTION") AS 
  SELECT UNIQUE 'D'                     AS level_alias,
                 'D'
                 || d.id_deployment_type
                 || '-'
                 || w.id_enviroment_type AS id,
                 NULL                    AS parent_id,
                 w.id_enviroment_type    AS group_id,
                 to_char(
                    d.id_deployment_type
                 ) AS level_path_id,
                 0                       AS level_order,
                 d.deployment_type AS level_name,
                 1                       AS level_status,
                 d.deployment_type_desc  AS description
             -------------------- FUNCTIONAL INFO -----------------------------                                  
             -----------------------------------------------------------------
     FROM request_workflow    w,
          deployment_type     d
    WHERE d.id_deployment_type = w.id_deployment_type
   UNION ALL
                ------------------ HIERARCHICAL INFO ------------------------------
   SELECT 'F'                      AS level_alias,
          'F' || w.id_req_flow     AS id,
          'D'
          || w.id_deployment_type
          || '-'
          || w.id_enviroment_type AS parent_id,
          w.id_enviroment_type     AS group_id,
          w.id_deployment_type
          || ','
          || w.id_req_flow AS level_path_id,
          0                        AS level_order,
          w.request_flow_name      AS level_name,
          w.request_flow_status    AS level_status,
          w.request_flow_desc      AS description
                -------------------- FUNCTIONAL INFO -----------------------------
                ------------------------------------------------------------------
     FROM request_workflow w
   UNION ALL
                ------------------ HIERARCHICAL INFO ------------------------------
   SELECT 'S'                       AS level_alias,
          'S' || s.id_step_flow     AS level_id,
          'F' || s.id_req_flow      AS parent_id,
          w.id_enviroment_type      AS group_id,
          w.id_deployment_type
          || ','
          || s.id_req_flow
          || ','
          || s.id_step_flow AS level_path_id,
          s.step_order              AS level_order,
          s.step_name               AS level_name,
          w.request_flow_status     AS level_status,
          s.step_description        AS description
               -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM request_step_workflow    s,
          request_workflow         w
    WHERE s.id_req_flow = w.id_req_flow
   UNION ALL
                ------------------ HIERARCHICAL INFO ------------------------------
   SELECT 'A'                       AS level_alias,
          'A' || a.id_action        AS level_id,
          'S' || a.id_step_flow     AS parent_id,
          w.id_enviroment_type      AS group_id,
          w.id_deployment_type
          || ','
          || s.id_req_flow
          || ','
          || s.id_step_flow
          || ','
          || a.id_action AS level_path_id,
          a.id_action               AS level_order,
          a.action_name             AS level_name,
          w.request_flow_status     AS level_status,
          a.status_result           AS description
                -------------------- FUNCTIONAL INFO -----------------------------
                -----------------------------------------------------------------
     FROM request_action_flow      a,
          request_step_workflow    s,
          request_workflow         w
    WHERE s.id_req_flow = w.id_req_flow
      AND a.id_step_flow = s.id_step_flow
;
