<commit_before>create or replace package body oos_util_apex
as

  /**
   * Returns true/false if APEX developer is enable
   * Supports both APEX 4 and 5
   *
   * Can be used in APEX to declaratively determine if in development mode.
   *
   * @example
   * begin
   *   if oos_util_apex.is_developer then
   *     dbms_output.put_line('Developer mode');
   *   else
   *     dbms_output.put_line('Non-Dev mode');
   *   end if;
   * end;
   *
   * @issue 25
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @return boolan True: Developer has an active session in Application Builder
   */
  function is_developer
    return boolean
  as
  begin
    if coalesce(apex_application.g_edit_cookie_session_id, v('APP_BUILDER_SESSION')) is null then
      return false;
    else
      return true;
    end if;
  end is_developer;


  /**
   * Returns Y/N if APEX developer is enable
   * See `is_developer` for details
   *
   * @example
   * begin
   *   if oos_util_apex.is_developer_yn = 'Y' then
   *     dbms_output.put_line('Developer mode');
   *   else
   *     dbms_output.put_line('Non-Dev mode');
   *   end if;
   * end;
   *
   * @issue #25
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @return Y or N
   */
  function is_developer_yn
    return varchar2
  as
    $if dbms_db_version.version >= 12 $then
      pragma udf;
    $end
  begin
    if is_developer then
      return 'Y';
    else
      return 'N';
    end if;
  end is_developer_yn;


  /**
   * Checks if APEX session is still active/valid
   *
   * @example
   *
   * begin
   *   if oos_util_apex.is_session_valid(p_session_id => :app_session) then
   *     dbms_output.put_line('Session is active');
   *   else
   *     dbms_output.put_line('Session is inactive');
   *   end if;
   * end;
   *
   * @issue #9
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_session_id APEX session ID
   * @return true/false
   */
  function is_session_valid(
    p_session_id in apex_workspace_sessions.apex_session_id%type)
    return boolean
  as
    l_count pls_integer;
  begin
    oos_util.assert(p_session_id is not null, 'p_session_id must contain value');

    select count(1)
    into l_count
    from apex_workspace_sessions aws
    where 1=1
      and aws.apex_session_id = p_session_id
      and sysdate <= aws.session_idle_timeout_on
      and sysdate <= aws.session_life_timeout_on;

    if l_count = 0 then
      return false;
    else
      return true;
    end if;
  end is_session_valid;


  /**
   * Checks if session is still active
   *
   * @example
   *
   * begin
   *   if oos_util_apex.is_session_valid_yn(p_session_id => :app_session) = 'Y' then
   *     dbms_output.put_line('Session is active');
   *   else
   *     dbms_output.put_line('Session is inactive');
   *   end if;
   * end;
   *
   * @issue 9
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_session_id APEX session ID
   * @return Y/N
   */
  function is_session_valid_yn(
    p_session_id in apex_workspace_sessions.apex_session_id%type)
    return varchar2
  as
    $if dbms_db_version.version >= 12 $then
      pragma udf;
    $end
  begin
    if is_session_valid(p_session_id => p_session_id) then
      return 'Y';
    else
      return 'N';
    end if;

  end is_session_valid_yn;


  /**
   * Creates a new APEX session.
   * Useful when testing APEX functionality in PL/SQL or using apex_mail etc
   *
   * Can only create one per Oracle session. To connect to a different APEX session, reconnect the Oracle session
   *
   *
   * Notes:
   *  - Content taken from:
   *    - http://www.talkapex.com/2012/08/how-to-create-apex-session-in-plsql.html
   *    - http://apextips.blogspot.com.au/2014/10/debugging-parameterised-views-outside.html
   *
   * @example
   *
   * begin
   *   oos_util_apex.create_session(
   *     p_app_id => :app_id,
   *     p_user_name => :app_user,
   *     p_page_id => :app_page_id);
   *   );
   * end;
   *
   * @issue #7
   * @issue #49 ensure page and user exist
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_app_id
   * @param p_user_name
   * @param p_page_id Page to try and register for post login. Recommended to leave null
   * @param p_session_id Session to re-join. Recommended leave null
   */
  procedure create_session(<commit_msg>minor example code bug<commit_after>create or replace package body oos_util_apex
as

  /**
   * Returns true/false if APEX developer is enable
   * Supports both APEX 4 and 5
   *
   * Can be used in APEX to declaratively determine if in development mode.
   *
   * @example
   * begin
   *   if oos_util_apex.is_developer then
   *     dbms_output.put_line('Developer mode');
   *   else
   *     dbms_output.put_line('Non-Dev mode');
   *   end if;
   * end;
   *
   * @issue 25
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @return boolan True: Developer has an active session in Application Builder
   */
  function is_developer
    return boolean
  as
  begin
    if coalesce(apex_application.g_edit_cookie_session_id, v('APP_BUILDER_SESSION')) is null then
      return false;
    else
      return true;
    end if;
  end is_developer;


  /**
   * Returns Y/N if APEX developer is enable
   * See `is_developer` for details
   *
   * @example
   * begin
   *   if oos_util_apex.is_developer_yn = 'Y' then
   *     dbms_output.put_line('Developer mode');
   *   else
   *     dbms_output.put_line('Non-Dev mode');
   *   end if;
   * end;
   *
   * @issue #25
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @return Y or N
   */
  function is_developer_yn
    return varchar2
  as
    $if dbms_db_version.version >= 12 $then
      pragma udf;
    $end
  begin
    if is_developer then
      return 'Y';
    else
      return 'N';
    end if;
  end is_developer_yn;


  /**
   * Checks if APEX session is still active/valid
   *
   * @example
   *
   * begin
   *   if oos_util_apex.is_session_valid(p_session_id => :app_session) then
   *     dbms_output.put_line('Session is active');
   *   else
   *     dbms_output.put_line('Session is inactive');
   *   end if;
   * end;
   *
   * @issue #9
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_session_id APEX session ID
   * @return true/false
   */
  function is_session_valid(
    p_session_id in apex_workspace_sessions.apex_session_id%type)
    return boolean
  as
    l_count pls_integer;
  begin
    oos_util.assert(p_session_id is not null, 'p_session_id must contain value');

    select count(1)
    into l_count
    from apex_workspace_sessions aws
    where 1=1
      and aws.apex_session_id = p_session_id
      and sysdate <= aws.session_idle_timeout_on
      and sysdate <= aws.session_life_timeout_on;

    if l_count = 0 then
      return false;
    else
      return true;
    end if;
  end is_session_valid;


  /**
   * Checks if session is still active
   *
   * @example
   *
   * begin
   *   if oos_util_apex.is_session_valid_yn(p_session_id => :app_session) = 'Y' then
   *     dbms_output.put_line('Session is active');
   *   else
   *     dbms_output.put_line('Session is inactive');
   *   end if;
   * end;
   *
   * @issue 9
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_session_id APEX session ID
   * @return Y/N
   */
  function is_session_valid_yn(
    p_session_id in apex_workspace_sessions.apex_session_id%type)
    return varchar2
  as
    $if dbms_db_version.version >= 12 $then
      pragma udf;
    $end
  begin
    if is_session_valid(p_session_id => p_session_id) then
      return 'Y';
    else
      return 'N';
    end if;

  end is_session_valid_yn;


  /**
   * Creates a new APEX session.
   * Useful when testing APEX functionality in PL/SQL or using apex_mail etc
   *
   * Can only create one per Oracle session. To connect to a different APEX session, reconnect the Oracle session
   *
   *
   * Notes:
   *  - Content taken from:
   *    - http://www.talkapex.com/2012/08/how-to-create-apex-session-in-plsql.html
   *    - http://apextips.blogspot.com.au/2014/10/debugging-parameterised-views-outside.html
   *
   * @example
   *
   * begin
   *   oos_util_apex.create_session(
   *     p_app_id => :app_id,
   *     p_user_name => :app_user,
   *     p_page_id => :app_page_id
   *   );
   * end;
   *
   * @issue #7
   * @issue #49 ensure page and user exist
   *
   * @author <NAME>
   * @created 29-Dec-2015
   * @param p_app_id
   * @param p_user_name
   * @param p_page_id Page to try and register for post login. Recommended to leave null
   * @param p_session_id Session to re-join. Recommended leave null
   */
  procedure create_session(
{'fraction_non_alphanumeric': 0.09488458415497042, 'fraction_numerical': 0.014615473842941654, 'mean_word_length': 2.4570970328789095, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5266051', 'n_tokens_mistral': 3258, 'n_tokens_neox': 3087, 'n_words': 772}