/* $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
                       := 'FlexibleView';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'View and apply for vacancies'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
   
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFlexibleViewPage'
    ,p_description        => 'Get a flexible view page'
    ,p_methods            => 'GET'
    ,p_path               => 'flexiview-page/{context}'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
        SELECT xxas_emp_views_pkg.get_flexible_view_page
                 ({pathParam.context}) "data"
        FROM  dual
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'DeleteFlexibleViewRow'
    ,p_description        => 'Deletes the requested row'
    ,p_path               => 'flexiview-row/{context}'
    ,p_methods            => 'DELETE'
    ,p_plsql              =>
      q'[
				DECLARE

          l_resp       		xxas_http_resp_obj;
          l_response_xml  XMLType;
          
        BEGIN

          xxas_emp_views_pkg.delete_flexible_view_row
            (p_context       => {pathParam.context}
            ,p_response_xml  => l_response_xml);

          IF l_response_xml IS NULL THEN
            l_resp := xxas_http_response.ok().build();            
          ELSE
            l_resp := xxas_http_response.ok(l_response_xml).build();
          END IF;
          
				 {response} := l_resp;
          
				END
			]'
		);
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFlexibleEditPage'
    ,p_description        => 'Get a flexible edit page'
    ,p_methods            => 'GET'
    ,p_path               => 'flexiedit-page/{context}'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
        SELECT xxas_emp_views_pkg.get_flexible_edit_page
                 ({pathParam.context}) "data"
        FROM  dual
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'SaveFlexibleEditForm'
    ,p_description        => 'Accepts posted forms and processes them'
    ,p_path               => 'flexiedit-form/{context}'
    ,p_methods            => 'POST'
    ,p_plsql              =>
      q'[
				DECLARE

          l_resp       		xxas_http_resp_obj;
          l_request_xml   XMLType;
          l_response_xml  XMLType;
          
        BEGIN
				
          l_request_xml := {requestBody};
        
          xxas_emp_views_pkg.post_flexible_edit_form
            (p_context       => {pathParam.context}
            ,p_form_data_xml => l_request_xml
            ,p_response_xml  => l_response_xml);

          IF l_response_xml IS NULL THEN
            l_resp := xxas_http_response.ok().build();            
          ELSE
            l_resp := xxas_http_response.ok(l_response_xml).build();
          END IF;
          
				 {response} := l_resp;
          
				END
			]'
		);
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFlexibleReviewPage'
    ,p_description        => 'Get a flexible review page'
    ,p_methods            => 'GET'
    ,p_path               => 'flexireview-page/{context}'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
        SELECT xxas_emp_views_pkg.get_flexible_review_page
                 ({pathParam.context}) "data"
        FROM  dual
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'SubmitFlexibleReviewForm'
    ,p_description        => 'Submits the flexible row'
    ,p_path               => 'flexireview-form/{context}'
    ,p_methods            => 'POST'
    ,p_plsql              =>
      q'[
				DECLARE

          l_resp       		xxas_http_resp_obj;
          l_request_xml   XMLType;
          l_response_xml  XMLType;
          
        BEGIN
				
          l_request_xml := {requestBody};
        
          xxas_emp_views_pkg.post_flexible_review_form
            (p_context       => {pathParam.context}
            ,p_form_data_xml => l_request_xml
            ,p_response_xml  => l_response_xml);

          IF l_response_xml IS NULL THEN
            l_resp := xxas_http_response.ok().build();            
          ELSE
            l_resp := xxas_http_response.ok(l_response_xml).build();
          END IF;
          
				 {response} := l_resp;
          
				END
			]'
		);
    
END;
/
COMMIT;
EXIT;
