REM This file updates the Meta Data tables for MR2

DECLARE

BEGIN 

    
    -- M41.002
    -- 1486558 OCX CONTROL FOR UNBOUND DATATYPE 
    -- 1395056 IMPOSSIBLE TO SELECT DESCRIPTIVE FLEXFIELD DISPLAY TYPE FOR UNBOUND ITEM 
    -- 
    
    dbms_output.put_line ('Applying Meta Data Patch M41.002');   
    
    
    delete from ref_values 
    where ref_domain = 'UBI_DISPLAY_TYPE'
    and ref_code in ('DFLEX', 'OCX CONTROL', 'OLE CONTAINER');
    
    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('DFLEX', 'UBI_DISPLAY_TYPE', 'Descriptive flexfield');

    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('OCX CONTROL', 'UBI_DISPLAY_TYPE', 'OCX control');

    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('OLE CONTAINER', 'UBI_DISPLAY_TYPE', 'OLE container');

    delete from ref_values 
    where ref_domain = 'UBI_DISPLAY_TYPE_OF'
    and ref_code in ('DFLEX', 'OCX CONTROL', 'OLE CONTAINER');
    
    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('DFLEX', 'UBI_DISPLAY_TYPE_OF', 'Descriptive flexfield');

    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('OCX CONTROL', 'UBI_DISPLAY_TYPE_OF', 'OCX control');

    insert into ref_values (REF_CODE, REF_DOMAIN, REF_MEANING)values
    ('OLE CONTAINER', 'UBI_DISPLAY_TYPE_OF', 'OLE container');

    delete from rm$nls_data_type_values
    where did = '22732'
    and dev_value in ('DFLEX', 'OCX CONTROL', 'OLE CONTAINER');
    
    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22732, 32, 'DFLEX', 'Descriptive flexfield');

    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22732, 34, 'OCX CONTROL', 'OCX control');

    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22732, 36, 'OLE CONTAINER', 'OLE container');

    delete  from rm$nls_data_type_values
    where did = '22733'
    and dev_value in ('DFLEX', 'OCX CONTROL', 'OLE CONTAINER');
    
    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22733, 32, 'DFLEX', 'Descriptive flexfield');

    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22733, 34, 'OCX CONTROL', 'OCX control');

    insert into rm$nls_data_type_values (irid,  NLS_LANGUAGE, DID, SEQ, DEV_VALUE, NLS_VALUE)
    values
    (jr_util.get_new_irid(), 'US', 22733, 36, 'OLE CONTAINER', 'OLE container');
   
    dbms_output.put_line ('Finished Patch M41.002');   
    
    -- M41.003
    -- 1311500 CHANGED DUAL TO SYS.DUAL TO FIX BUG 
    -- 2055998 CHANGED DELETE AND INSERT STATEMENTS ON I$SDD_RULES TO UPDATE TO FIX BUG
    dbms_output.put_line ('Applying Meta Data Patch M41.003');   

    -- sdd_rules
    -- DELETE and INSERT statements chaged to UPDATE : Alan Fackerell 16-OCT-2001
    -- fix for RAU Upgrade bug 2055998
    
    update i$sdd_rules 
    set rule_sql = 
    'select va.irid ov_irid, va.to_ivid ov_ivid
      from sdd_version_associations va
          ,I$sdd_configuration_members cm
          ,I$sdd_branches br
     where va.branch_id = br.branch_id
     and   br.name = :branch
     and   va.edge_kind = ''T''
     and   va.irid = cm.object_irid
     and   cm.config_ivid in (select jr_name.get_IVID(:configuration) from sys.dual)'
    where name = 'LATEST_CONFIG_CONTENTS';

    
    update i$sdd_rules 
    set rule_sql = 
    'select va.irid ov_irid, va.to_ivid ov_ivid
      from SDD_VERSION_ASSOCIATIONS va
          ,I$SDD_DEU deu
          ,I$SDD_BRANCHES br
     where deu.parent_ivid in (select jr_name.get_IVID(:diagram) from sys.dual)
     and va.irid = deu.cielement_ref
     and va.edge_kind = (''T'')
     and va.branch_id = br.branch_id
     and br.name=:branch'
    where name = 'LATEST_DIAGRAM_CONTENTS';
    
     
     -- rm_link_customized_query
     delete from rm_link_customized_query
     where query_name = 'ATV';


     INSERT into RM_LINK_CUSTOMIZED_QUERY (query_name, query_text )
     values
     ( 'ATV',
     ' in ( select domain_ref from i$sdd_col
     where irid = :C1 union all select :C1 from sys.dual  )' );


    dbms_output.put_line ('Finished Patch M41.003');   
    
    -- M41.005
    -- 1511736 BACKPORT 1511656: MOVING FOLDER WITHIN OWN HIERACHY CORRUPTS DATA 
    -- 1521610 TARGET PARENT FOLDER IS CORRUPTED AFTER MOVING CHECKED OUT TABLE DEFINTIIONS 

    dbms_output.put_line ('Applying Meta Data Patch M41.005');   

    delete from rm$nls_messages
    where utility = 'CDA'
    and code in (6104, 6105);

    insert into rm$nls_messages
       (lang_id,     utility,     code,      severity, text)
    values ('US', 'CDA', 6104, 1,'Cannot move element %0!s - target container %1!s is within same hierarchy.');

    insert into rm$nls_messages
       (lang_id,     utility,     code,      severity, text)
    values ('US', 'CDA', 6105, 1,'Cannot move : %0!s into itself.');


    dbms_output.put_line ('Finished Patch M41.005');   
    
    
    -- M46.001
    -- 1568489 NEW PREFERENCES MODPTL,MODCSS AND MODFOU ADDED TO FOR WSG 

      
    dbms_output.put_line ('Applying Meta Data Patch M46.001');   

    DELETE FROM CDI_DFLT_USER_PREF_USAGES
    WHERE  DUP_SNAME IN ('MODPTL','MODCSS','MODFOU')
    AND    P_SNAME = 'WSG';
    
    insert into cdi_dflt_user_pref_usages
    (P_SNAME
    ,P_CGVERSION
    ,PF_SEQ
    ,DUP_SNAME
    ,DESCRIPTION
    ,VALUE
    ,DUP_INTERNAL
    ,DUP_TYPE
    ,DESCRIPTION_MSGID
    ,MANDATORY
    ,CHR_DOMAIN
    ,CHR_MAXLEN
    ,NUM_HIVAL
    ,NUM_LOVAL
    ,DOM
    ,TAB
    ,CON
    ,COL
    ,MOD
    ,DTU
    ,CONU
    ,IGRP
    ,DCU
    ,ACI
    ,SUB
    ,LOV
    ,NLS_LANG)
    values
    (
    'WSG', -- P_SNAME
    '1.0', -- P_CGVERSION
    1, -- PF_SEQ
    'MODPTL', -- DUP_SNAME
    'Generate Module as an Oracle Portlet', -- DESCRIPTION
    'N', -- VALUE
    'N', -- DUP_INTERNAL
    'GENERAL LAYOUT', -- DUP_TYPE
    21680, -- DESCRIPTION_MSGID
    'Y', -- MANDATORY
    'FLAG', -- CHR_DOMAIN
    NULL,  -- CHR_MAXLEN
    NULL,  -- NUM_HIVAL
    NULL,  -- NUM_LOVAL
    'N', -- DOM
    'N', -- TAB
    'N', -- CON
    'N', -- COL
    'Y', -- MOD
    'N', -- DTU
    'N', -- CONU
    'N', -- IGRP
    'N', -- DCU
    'N', -- ACI
    'N', -- SUB
    'N', -- LOV
    'US') -- NLS_LANG
    ;
    
    insert into cdi_dflt_user_pref_usages
    (P_SNAME
    ,P_CGVERSION
    ,PF_SEQ
    ,DUP_SNAME
    ,DESCRIPTION
    ,VALUE
    ,DUP_INTERNAL
    ,DUP_TYPE
    ,DESCRIPTION_MSGID
    ,MANDATORY
    ,CHR_DOMAIN
    ,CHR_MAXLEN
    ,NUM_HIVAL
    ,NUM_LOVAL
    ,DOM
    ,TAB
    ,CON
    ,COL
    ,MOD
    ,DTU
    ,CONU
    ,IGRP
    ,DCU
    ,ACI
    ,SUB
    ,LOV
    ,NLS_LANG)
    values
    (
    'WSG', -- P_SNAME
    '1.0', -- P_CGVERSION
    1, -- PF_SEQ
    'MODCSS', -- DUP_SNAME
    'Cascading Style Sheet (CSS) URL', -- DESCRIPTION
    '', -- VALUE
    'N', -- DUP_INTERNAL
    'DOCUMENT ATTRIBUTES', -- DUP_TYPE
    21681, -- DESCRIPTION_MSGID
    'N', -- MANDATORY
    '', -- CHR_DOMAIN
    240,  -- CHR_MAXLEN
    NULL,  -- NUM_HIVAL
    NULL,  -- NUM_LOVAL
    'N', -- DOM
    'N', -- TAB
    'N', -- CON
    'N', -- COL
    'Y', -- MOD
    'N', -- DTU
    'N', -- CONU
    'N', -- IGRP
    'N', -- DCU
    'N', -- ACI
    'N', -- SUB
    'N', -- LOV
    'US') -- NLS_LANG
    ;
    
    insert into cdi_dflt_user_pref_usages
    (P_SNAME
    ,P_CGVERSION
    ,PF_SEQ
    ,DUP_SNAME
    ,DESCRIPTION
    ,VALUE
    ,DUP_INTERNAL
    ,DUP_TYPE
    ,DESCRIPTION_MSGID
    ,MANDATORY
    ,CHR_DOMAIN
    ,CHR_MAXLEN
    ,NUM_HIVAL
    ,NUM_LOVAL
    ,DOM
    ,TAB
    ,CON
    ,COL
    ,MOD
    ,DTU
    ,CONU
    ,IGRP
    ,DCU
    ,ACI
    ,SUB
    ,LOV
    ,NLS_LANG)
    values
    (
    'WSG', -- P_SNAME
    '1.0', -- P_CGVERSION
    1, -- PF_SEQ
    'MODFOU', -- DUP_SNAME
    'Module Form Links URL', -- DESCRIPTION
    '', -- VALUE
    'N', -- DUP_INTERNAL
    'LINKS', -- DUP_TYPE
    21683, -- DESCRIPTION_MSGID
    'N', -- MANDATORY
    '', -- CHR_DOMAIN
    240,  -- CHR_MAXLEN
    NULL,  -- NUM_HIVAL
    NULL,  -- NUM_LOVAL
    'N', -- DOM
    'N', -- TAB
    'N', -- CON
    'N', -- COL
    'Y', -- MOD
    'N', -- DTU
    'N', -- CONU
    'N', -- IGRP
    'N', -- DCU
    'N', -- ACI
    'N', -- SUB
    'N', -- LOV
    'US') -- NLS_LANG
    ;

    dbms_output.put_line ('Finished Patch M46.001');  
    
    -- Register MR2 Upgrade in the RM$PATCHES RM$PATCHES table 

    rmpatch.install('CI04012.MR2_UPGRADE');
	
    rmpatch.installed_ok;

    commit;
	
	
EXCEPTION

    when others then 
	dbms_output.put_line('* Exception Raised  ');
	dbms_output.put_line('...ERROR: '||substrb(sqlerrm,1,240));
	rollback work;
	raise;

END;
/




