/* $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
                       := 'ApplicantResumesAndLetters';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'View applicant''s resumes and letters'
    ,p_path               => '/vacancies/{vacancyId}/applicants/{applicantId}/resumes-letters'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
   
	 
 xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetResumesAndLetters'
    ,p_description        => 'Get resumes and letters for one applicant'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
        SELECT XMLElement
                 ("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_applicant_pkg.get_attachments_xml
                   ({pathParam.vacancyId}
                   ,{pathParam.applicantId})
                 ) "data"
        FROM dual
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetResumeOrLetter'
    ,p_description        => 'Get one resume or letter document'
    ,p_methods            => 'GET'
    ,p_path               => '{fileId}'
    ,p_produces           => 'application/xml'
    ,p_sql                =>
      q'[
         SELECT xxas_http_response.ok()
               .entity(fl.file_data, fl.file_content_type)
               .header(''Content-Disposition'',''attachment;filename="''||fl.file_name||''"'')
               .build() "httpResponse"
         FROM   fnd_lobs fl
         WHERE  fl.file_id = {pathParam.fileId}
      ]'
    );

END;
/
COMMIT;
EXIT;



