/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2015 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  l_SERVICE CONSTANT xxas_com_service_repository.service_name%TYPE
                       := 'WfParticipants';

BEGIN

  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Find Wf participants'
    ,p_path               => '/wfparticipants'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml');
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'FindParticipants'
    ,p_description        => 'Find Wf participants matching the given criteria'
    ,p_methods            => 'GET'
    ,p_path               => '{id}'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
            SELECT XMLElement
                 ("data"
                 ,XMLAgg
                   (XMLElement
                     ("role"
                     ,XMLForest
                       (p.name as "id"
                       ,p.value as "label"
                       ,p.value as "value"
                       )
                     )
                   )
                 )
        FROM  TABLE(xxas_com_worklist_pkg.get_rfc_participants({pathParam.id})) p
        WHERE p.value NOT IN ('SYSADMIN','SYSADMIN SYSADMIN',fnd_global.user_name)
        ]'
     );
        
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'FindParticipantTypesForRequestInformation'
    ,p_description        => 'Any user or wf participant'
    ,p_methods            => 'GET'
    ,p_path               => '/forRMI'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
            SELECT XMLElement
                 ("data"
                 ,XMLAgg
                   (XMLElement
                     ("role"
                     ,XMLForest
                       (p.code as "id"
                       ,p.meaning as "label"
                       ,p.meaning as "value"
                       )
                     ) ORDER BY p.code desc
                   )
                 )
        FROM  (SELECT 'PARTICIPANT' code,
                      xxas_com_msg_pkg.get_string('XXAS_WF_RMI_EP') meaning
                       FROM dual
               UNION        
               SELECT 'ANYONE' code,
                      xxas_com_msg_pkg.get_string('XXAS_WF_RMI_ANY') meaning
                       FROM dual
                ) p
        ]'
    );

END;
/
COMMIT;
EXIT;
