Rem drv: <create type="type_bodys" />
Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/core/latest/emInternalSDK/events/events_types_body.sql rbali_oneoff_updated/1 2025/03/14 06:41:14 rbali Exp $
Rem
Rem events_types_body.sql
Rem
Rem Copyright (c) 2010, 2025, Oracle and/or its affiliates. 
Rem All rights reserved.

Rem BEGIN EMRU_FILE_METADATA
Rem EMRU_SOURCE_FILE:emcore/source/oracle/sysman/emdrep/sql/core/latest/emInternalSDK/events/events_types_body.sql
Rem EMRU_UNIX_DELIVERABLES:
Rem emcore/source/oracle/sysman/emdrep/sql/core/latest/emInternalSDK/events/events_types_body.sql

Rem EMRU_FILE_POSTINSTALL:emcore/source/oracle/sysman/emdrep/sql/core/latest/emInternalSDK/events/events_types_body.sql
Rem EMRU_GENERIC_FLAG:NONE
Rem END EMRU_FILE_METADATA

Rem
Rem    NAME
Rem      events_types_body.sql - <one-line expansion of the name>
Rem
Rem    DESCRIPTION
Rem      This package type defines all the pl/sql objects needed to be 
Rem      constructed for events publishing purpose.
Rem      These objects would be required for the pl/sql publishing API stored 
Rem      in GC_EVENT_RECEIVER package
Rem
Rem    NOTES
Rem      <other useful comments, qualifications, etc.>
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    gbafna      02/27/25 - 
Rem    gbafna      02/03/25 - 
Rem    gbafna      01/07/25 - make synonyms noneditionable
Rem    carromer    07/09/18 - Fix bug 26732645
Rem    rnadidar    02/11/15 - cut over to EBR
Rem    zeding      07/30/12 - bug-14222782 intro gc_ev_msg_param
Rem    rpatti      03/30/11 - introduce processing hint NVP for
Rem                           gc_event_publish_obj
Rem    sreddy      01/24/11 - remove deduplicate_key
Rem    rsidlagh    03/17/10 - Changed the gc_event_publish_obj structure to
Rem                           have individual fields for sys_attribs
Rem    zeding      02/09/10 - Created
Rem

/** This constructor function to create gc_event_context_obj
  * This object represents the event context data object. This is primarily 
  * constructed before the construction of an event object prior to publishing 
  * @param p_name The event context name
  * @param p_type The data type of the value, which is stored 
  *               (0) - for numeric data
  *               (1) - for string data
  * @param p_value The numerical value
  * @param p_string_value The string value 
  */

ALTER SESSION SET CURRENT_SCHEMA=SYSMAN_TYPES;

CREATE OR REPLACE TYPE BODY gc_event_context_obj AS
 CONSTRUCTOR FUNCTION gc_event_context_obj (
  p_name                 IN VARCHAR2,
  p_type                 IN NUMBER,
  p_value                IN NUMBER,
  p_string_value         IN VARCHAR2
 ) 
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.name         := p_name ;
  SELF.type         := p_type ;
  SELF.value        := p_value ;
  SELF.string_value := p_string_value ;
  RETURN ;
 END ;
END ;
/

grant execute on gc_event_context_obj to sysman;

CREATE OR REPLACE TYPE BODY gc_event_source_info AS
 CONSTRUCTOR FUNCTION gc_event_source_info (
  p_type      IN VARCHAR2,
  p_id        IN RAW,
  p_name      IN VARCHAR2,
  p_owner     IN VARCHAR2,
  p_sub_type  IN VARCHAR2
 )
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.type     := p_type ;
  SELF.id       := p_id ;
  SELF.name     := p_name ;
  SELF.owner    := p_owner ;
  SELF.sub_type := p_sub_type ;
  RETURN ;
 END ;
END ;
/

grant execute on gc_event_source_info to sysman;

-- message param that allows exact type to be specified
-- p_type based on even context type value
-- 0 for String
-- 1 for Number 
CREATE OR REPLACE TYPE BODY gc_ev_msg_param AS
 CONSTRUCTOR FUNCTION gc_ev_msg_param (
  p_value       IN VARCHAR2,
  p_nlsid       IN VARCHAR2,
  p_resbundle   IN VARCHAR2
 )
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.value        := p_value ;
  SELF.nlsid        := p_nlsid ;
  SELF.resbundle    := p_resbundle ;
  SELF.type := EM_EVENT_RECEIVER.STRING_MSG_PARAM ;
  RETURN ;
 END ;
 CONSTRUCTOR FUNCTION gc_ev_msg_param (
  p_value        IN VARCHAR2
 )
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.value        := p_value ;
  SELF.nlsid        := null ;
  SELF.resbundle    := null ;
  SELF.type := EM_EVENT_RECEIVER.STRING_MSG_PARAM ;
  RETURN ;
 END ;
 CONSTRUCTOR FUNCTION gc_ev_msg_param (
  p_value        IN NUMBER
 )
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.value        := p_value ;
  SELF.nlsid        := null ;
  SELF.resbundle    := null ;
  SELF.type := EM_EVENT_RECEIVER.NUMBER_MSG_PARAM ;
  RETURN ;
 END ;
END ;
/

grant execute on gc_ev_msg_param to sysman;

CREATE OR REPLACE TYPE BODY gc_ev_msg_info AS
 CONSTRUCTOR FUNCTION gc_ev_msg_info (
  p_msg            IN VARCHAR2,
  p_msg_nlsid      IN VARCHAR2,
  p_msg_nlsparams  IN VARCHAR2,
  p_msg_resbundle  IN VARCHAR2
 )
 RETURN SELF AS RESULT
 IS
   l_enc_param VARCHAR2(4000);
 BEGIN
   SELF.msg           := p_msg ;
   SELF.msg_nlsid     := p_msg_nlsid ;
   SELF.msg_nlsparams := p_msg_nlsparams;
   SELF.msg_resbundle := p_msg_resbundle ;
   RETURN ;
 END ;
 CONSTRUCTOR FUNCTION gc_ev_msg_info (
  p_msg            IN VARCHAR2,
  p_msg_nlsid      IN VARCHAR2,
  p_msg_param_arr  IN GC_EV_MSG_PARAM_ARRAY,
  p_msg_resbundle  IN VARCHAR2
 )
 RETURN SELF AS RESULT
 IS
  l_enc_msg_params VARCHAR2(15000) := NULL;
  l_enc_msg_param VARCHAR2(5000) := NULL;
  l_extended_encoding_required BOOLEAN := FALSE;
 BEGIN
  l_enc_msg_params   := NULL;
  SELF.msg           := p_msg ;
  SELF.msg_nlsid     := p_msg_nlsid ;
  SELF.msg_resbundle := p_msg_resbundle ;

 
  IF p_msg_param_arr IS NOT NULL AND p_msg_param_arr.COUNT > 0
  THEN
    FOR i IN 1..p_msg_param_arr.COUNT
    LOOP
      IF p_msg_param_arr(i).type != EM_EVENT_RECEIVER.NUMBER_MSG_PARAM
      THEN
        l_extended_encoding_required := TRUE;
        exit;
      END IF;
    END LOOP;

    FOR i IN 1..p_msg_param_arr.COUNT
    LOOP
      l_enc_msg_param := EM_EVENT_RECEIVER.encode_msg_param(p_msg_param_arr(i), 
                                                        l_extended_encoding_required);

      IF l_extended_encoding_required
      THEN
        IF p_msg_param_arr(i).type = EM_EVENT_RECEIVER.NUMBER_MSG_PARAM
        THEN
          l_enc_msg_param := '#n' || l_enc_msg_param;
        ELSIF p_msg_param_arr(i).type = EM_EVENT_RECEIVER.STRING_MSG_PARAM
        THEN
          l_enc_msg_param := '#s' || l_enc_msg_param;
        END IF;
      END IF;

      IF i > 1
      THEN
        IF (LENGTH(l_enc_msg_params) + 1 + LENGTH(l_enc_msg_param)) > 12000
        THEN
           IF l_extended_encoding_required
           THEN
              l_enc_msg_params := l_enc_msg_params || '&' || SUBSTR(l_enc_msg_param,1,(11996 - (LENGTH(l_enc_msg_params) + 1)));
           ELSE
              l_enc_msg_params := l_enc_msg_params || '&' || SUBSTR(l_enc_msg_param,1,(12000 - (LENGTH(l_enc_msg_params) + 1)));
           END IF;
           EXIT;
        ELSE
           l_enc_msg_params := l_enc_msg_params || '&' || l_enc_msg_param;
        END IF;
      ELSE
        l_enc_msg_params := l_enc_msg_param;
      END IF;
    END LOOP;
  END IF;
  -- extended encoding should be done when there is a non-number parameter
  IF l_extended_encoding_required
  THEN
    l_enc_msg_params := '_V2_' || l_enc_msg_params;
  END IF;
  l_enc_msg_params := SUBSTR(l_enc_msg_params,1,4000);
  SELF.msg_nlsparams := l_enc_msg_params ;
  RETURN ;
 END ;
END ;
/

grant execute on gc_ev_msg_info to sysman;

CREATE OR REPLACE TYPE BODY gc_event_duplicate_info AS
 CONSTRUCTOR FUNCTION gc_event_duplicate_info (
  p_first_occurred_date IN DATE,
  p_last_occurred_date  IN DATE,
  p_occurrence_count    IN NUMBER
 )
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.first_occurred_date  := p_first_occurred_date ;
  SELF.last_occurred_date   := p_last_occurred_date ;
  SELF.occurrence_count     := p_occurrence_count ;
  RETURN ;
 END ;
END ;
/

grant execute on gc_event_duplicate_info to sysman;

/** This constructor function to create gc_event_publish_obj
  * This object represents the event object, with all the necessary attributes 
  * before the publishing system could publish an event.
  * @param event_class The name of the event class
  * @param source_obj_id The source object id. If an event is purely a target 
  *  based, e.g. a Metric Alert on a target Host1, this value will be set as the
  *  target guid of Host1.
  * @param target_guid The related target guid (will be set if the event
  *  belongs to a source object as well as a target)
  * @param reported_date The date reported by publishing system, 
  *  the date should be normalized to UTC timezone. 
  * @param occurrence_date The actual occurrence time of the event, UTC.
  *  Typically, the event is reported when detected by the subsystem 
  *  which is typically not when the event actually occurred, but a little
  *  later than that. This is usually because systems typically poll 
  *  to see if there are any issues on a periodic basis.
  *  In some cases, the sub system publishing the event knows exactly
  *  when a specific event occurred, typically true when the event
  *  is being generated by mining a log.  In such cases, the occurrence
  *  time is passed in by using this method.
  * @param severity_level The event severity. Valid values are below (NUMBER)
  *  FATAL(32),
  *  CRITICAL(16),
  *  WARNING(8),
  *  MINOR_WARNING(4),
  *  INFORMATIONAL(2),
  *  CLEAR(0);
  * @param is_auto_close Used to set if an event is auto closed by the system,
  *  or it has to be manually closed by users. In most cases, the source system
  *  publishing a event with a severity like warning or critical is also able 
  *  to raise a corresponding event with clear severity  when the situation is 
  *  fixed. This is called auto close and is the default behavior.
  *  In some cases, where the source system is only capable of reporting the
  *  problems, but is unable to detect the clearing of the problems, the
  *  users would have to manually generate a clear event via the UI to 
  *  indicate that the problem is fixed. For such events, publishers should
  *  set auto close to false.
  * @param display_tz Timezone information in which event information is  
  *  displayed in UI or sent in notifications. 
  *  If this piece of information is not specified during event publishing, 
  *     If this event is target based, 
  *       => target TZ will be used
  *     If this event is not target based, 
  *       => default timezone of UTC will be used
  * @param attributes These are name value pairs of system attributes as well 
  *  as class specific attributes.
  * @see events_receiver_pkgdef.sql for a list of system attributes that can 
  *  be set and passed in during event publishing.
  * @param context The context attributes for an event. These are attributes 
  * that are not common to all events of a given class (see class specific
  * atribute APIs above), but are specific to an individual event.
  * There is no previous registration of what these attribute names or 
  * value data types may be. Typical usage is for a subsystem to publish
  * additional context about an event which might be useful to an end-user
  * or an integrator or a integration system.
  * For example, if an event is raised indicating that a tablespace % usage
  * is above 80%, it may have an additional event context attribute to
  * indicate that the size of this tablespace is 4 GB and there is .8GB left. 

  * @param categories The category(one or more) the event belogns to. While 
  * category is not a required element, the entire UI is oriented on categories
  * so please ensure that you set the event category unless there is a clear 
  * exception. The list of categories supported is documented on SMP Internal 
  * wiki as this is a changing list.
  */
CREATE OR REPLACE TYPE BODY gc_event_publish_obj AS
 CONSTRUCTOR FUNCTION gc_event_publish_obj (
  p_event_class          IN VARCHAR2,
  p_source_obj           IN GC_EVENT_SOURCE_INFO,
  p_target_guid          IN RAW DEFAULT NULL,
  p_reported_date        IN DATE,
  p_occurrence_date      IN DATE DEFAULT NULL,
  p_severity_level       IN NUMBER,
  p_is_auto_close        IN NUMBER DEFAULT 1,
  p_display_tz           IN VARCHAR2 DEFAULT NULL,
  p_event_name           IN VARCHAR2,
  p_event_key            IN VARCHAR2 DEFAULT NULL,
  p_event_msg            IN GC_EV_MSG_INFO,
  p_action_msg           IN GC_EV_MSG_INFO DEFAULT NULL,
  p_is_adr_aware         IN NUMBER DEFAULT 0,
  p_class_attributes     IN GC_EVENT_PAIR_ARRAY,
  p_context_data         IN GC_EVENT_CONTEXT_ARRAY DEFAULT NULL,
  p_categories           IN MGMT_SHORT_STRING_ARRAY DEFAULT NULL,
  p_deduplicate_data     IN GC_EVENT_DUPLICATE_INFO DEFAULT NULL,
  p_processing_hints     IN GC_EVENT_PAIR_ARRAY DEFAULT NULL
 ) 
 RETURN SELF AS RESULT
 IS
 BEGIN
  SELF.event_class        := p_event_class ;      
  SELF.source_obj         := p_source_obj ;    
  SELF.target_guid        := p_target_guid ;
  SELF.reported_date      := p_reported_date ;    
  SELF.occurrence_date    := p_occurrence_date ;  
  SELF.severity           := p_severity_level ;   
  SELF.is_auto_close      := p_is_auto_close ;       
  SELF.display_tz         := p_display_tz ;
  SELF.event_name         := p_event_name ;
  SELF.event_key          := p_event_key ;
  SELF.event_msg          := p_event_msg ;
  SELF.action_msg         := p_action_msg ;
  SELF.is_adr_aware       := p_is_adr_aware ; 
  SELF.class_attributes   := p_class_attributes ;       
  SELF.context_data       := p_context_data ;           
  SELF.categories         := p_categories ;        
  SELF.deduplicate_data   := p_deduplicate_data ;        
  SELF.processing_hints   := p_processing_hints ;        
  RETURN ;
 END ;
END ;
/

grant execute on gc_event_publish_obj to sysman;

ALTER SESSION SET CURRENT_SCHEMA=SYSMAN;
