Архив

Публикации с меткой ‘инициализация сессии’

ОЕБС Расширенный скрипт инициализации сессиии

6 Апрель 2012 3 comments

ОЕБС Инициализация сессии
ОЕБС Расширенный скрипт для инициализации сессии:

  • Выводит в output короткую запись для инициализации.
  • Если не заданы полномочия или приложение, то выводит в output список назначенных пользователю полномочий.
declare
 l_lang           varchar2(2)   := 'RU';
 l_user_name      varchar2(100) := 'AOSTAPISHEN';
 l_resp_name      varchar2(400);
 l_resp_appl_name varchar2(400);
 -- ------------------------------------------------------------------
 l_user_id        NUMBER;
 l_resp_id        NUMBER;
 l_resp_appl_id   NUMBER;
 l_appl_code      VARCHAR2(10);
 l_org_id         NUMBER;
 l_mo_sec_profile NUMBER;
 l_mo_product     number;
begin
 
 -- l_resp_name := 'Управление активами предприятия';
 -- l_resp_name := 'Диспетчер Дебиторов';
 -- l_resp_name := 'Разработчик приложений';
 -- l_resp_name := 'Движение денежных средств: суперпользователь';
 
 -- l_resp_appl_name := 'Управление активами предприятия';
 -- l_resp_appl_name := 'Главная книга';
 -- l_resp_appl_name := 'Дебиторы'
 -- l_resp_appl_name := 'Кредиторы';
 -- l_resp_appl_name := 'Движение денежных средств';
 -- l_resp_appl_name := 'Библиотека объектов приложений';
 
   select user_id into l_user_id from fnd_user t where user_name like l_user_name; 
 
   if (l_resp_name is null or l_resp_appl_name is null) then
 
     for i in (
                 SELECT ap.application_short_name as appl_code,
                        a.application_name        as appl_name,
                        r.responsibility_name     as resp_name,
                        r0.responsibility_key,
                        --
                        max(length(a.application_name )) over() as length_appl_name
                  FROM fnd_user u,
                       fnd_user_resp_groups g,
                       fnd_application_tl a,
                       fnd_responsibility_tl r,
                       fnd_responsibility    r0,
                       fnd_application       ap
                 WHERE g.user_id(+) = u.user_id
                   AND g.responsibility_application_id = a.application_id
                   AND a.application_id = r.application_id
                   AND g.responsibility_id = r.responsibility_id
                   and a.language = l_lang
                   and ap.application_id = a.application_id
                   and r.language = l_lang
                   and u.user_name = l_user_name
                   and r.responsibility_name <> 'Диагностика приложения'
                   and r.responsibility_name = nvl(l_resp_name,r.responsibility_name)
                   and a.application_name = nvl(l_resp_appl_name,a.application_name)
                   and r0.responsibility_id = r.responsibility_id
 
                 ORDER BY appl_name, resp_name
               )
     loop
       dbms_output.put_line(rpad('l_resp_appl_name := '''||i.appl_name||'''',i.length_appl_name+22,' ') || ' ; l_resp_name := '''||i.resp_name||''';');
       dbms_output.put_line(rpad('appl_code := '''||i.appl_code||'''',i.length_appl_name+22,' ') || ' ; responsibility_key := '''||i.responsibility_key||''';');
     end loop;
 
   else
  
     select b.application_id, b.application_short_name into l_resp_appl_id, l_appl_code
     from fnd_application_tl t
         ,fnd_application    b
     where 1=1
           and t.application_name like l_resp_appl_name
           and t.language = l_lang
           and b.application_id = t.application_id;
            
     select t.responsibility_id into l_resp_id from fnd_responsibility_tl t 
     where t.responsibility_name like l_resp_name and t.language = l_lang and t.application_id = l_resp_appl_id;
 
     l_org_id := fnd_profile.VALUE_SPECIFIC(NAME => 'ORG_ID', RESPONSIBILITY_ID => l_resp_id, APPLICATION_ID=> l_resp_appl_id);
 
     fnd_global.apps_initialize( user_id      => l_user_id,
                                 resp_id      => l_resp_id,
                                 resp_appl_id => l_resp_appl_id
                               );
                               
     SELECT count(1) into l_mo_product FROM fnd_mo_product_init mpi where mpi.application_short_name = l_appl_code and nvl(mpi.status, 'N') = 'Y';                             
     
     if (l_mo_product = 1) then
       begin
         MO_GLOBAL.init(l_appl_code);
   
         if (l_org_id is not null) then
           mo_global.set_policy_context('M',l_org_id);
         end if;
   
         l_mo_sec_profile := fnd_profile.value('XLA_MO_SECURITY_PROFILE_LEVEL');
   
         mo_global.set_org_context(l_resp_id,l_mo_sec_profile,l_appl_code);
       exception
         when others then
           dbms_output.put_line('SQLERRM:'||SQLERRM||chr(10));
           dbms_output.put_line('FORMAT_ERROR_BACKTRACE:'||chr(10)||dbms_utility.format_error_backtrace);
       end;
 
       dbms_output.put_line('begin'||chr(10)||' fnd_global.apps_initialize('||l_user_id||', '||l_resp_id||', '||l_resp_appl_id||'); --'||l_resp_name||' - '||l_resp_appl_name
                            ||chr(10)||' mo_global.init('''|| l_appl_code||''');'
                            ||case when l_org_id is not null then chr(10)||' mo_global.set_policy_context(''M'','||l_org_id||');' end
                            ||chr(10)||' mo_global.set_org_context('||l_resp_id||', '||l_mo_sec_profile||', '''||l_appl_code||''');'
                            ||chr(10)||'end;');
     else
       dbms_output.put_line('begin'||chr(10)||' fnd_global.apps_initialize('||l_user_id||', '||l_resp_id||', '||l_resp_appl_id||'); --'||l_resp_name||' - '||l_resp_appl_name
                            ||chr(10)||'end;');       
     end if;                            
   end if;
end;