Rem
Rem This file is used to register the sample provider
Rem for the portlets it implements.
Rem
Rem This is called internally from the install.sql file
Rem

set define on
set serveroutput on

show user
--
set define on

declare
    l_provider_rec wwpro_api_provider_registry.provider_record;
    l_provider_id  integer;
    l_exist_nodeprov   wwpro_api_provider_registry.node_provider_record;
begin

    dbms_output.put_line('---- Registering Sample Provider ----' );
    l_provider_rec.name := 'Sample_Provider';
    l_provider_rec.display_name := 'Sample Provider'; 
    l_provider_rec.node_id := null;
    l_provider_rec.timeout := 10;
    l_provider_rec.timeout_msg_id := null;
    l_provider_rec.timeout_msg := 'Application timed out';
    l_provider_rec.implementation_style
        := wwpro_api_provider_registry.PLSQL_IMPL;
    l_provider_rec.implementation_owner       := upper('&&1');
    l_provider_rec.implementation_name        := 'SAMPLE_PROVIDER';
    l_provider_rec.enable_distribution        := false;
    l_provider_rec.login_frequency 
        := wwpro_api_provider_registry.LOGIN_FREQUENCY_NEVER;
    l_provider_rec.created_on := sysdate;
    l_provider_rec.created_by := wwctx_api.get_user;
    l_provider_rec.last_updated_on := sysdate;
    l_provider_rec.last_updated_by := wwctx_api.get_user;

        
    -- check if a provider already exists with the same name
    l_exist_nodeprov := wwpro_api_provider_registry.find_provider(
        p_name => l_provider_rec.name
        );

    if (l_exist_nodeprov.name is not null) then
        dbms_output.put_line('ERROR: Could not register '
            || l_provider_rec.name
            || ' because a provider already exists with the same name. '
            || ' Please specify a unique provider name.'
            );
         return;
    end if;

    l_provider_id := wwpro_api_provider_registry.register_provider
        (p_provider_rec => l_provider_rec);

    dbms_output.put_line(' PROVIDER ID = ' || l_provider_id);
    dbms_output.put_line('---- Sample Provider successfully registered ----');
    dbms_output.put_line('');
    dbms_output.put_line('---- Sample Provider ----');
    wwpro_api_provider_registry.print_provider(l_provider_id, wwnls_api.AMERICAN);
    dbms_output.put_line('---- End Sample Provider ----');

    commit;

exception
    when others then
        dbms_output.put_line('ERROR: Failed to register Sample Provider');
        dbms_output.put_line('SQLERRM: ' || sqlerrm);
        rollback;
end;

/
