/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2014 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
                       := 'FunctionData';

BEGIN

  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Retrieve function data'
    ,p_path               => 'function-data'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml');
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionData'
    ,p_description        => 'Get function data'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,null /* p_predicates */
                  ,null /* p_binds */
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage})
                      ) "data"
      FROM dual
        ]'
    );

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPk1'
    ,p_description        => 'Get function data by primary key 1'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/by-pk1/{instancePk1Value}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table
                    (xxas_rslt_cache_pkg.object_pk1_column_name
                      (xxas_com_sec_pkg.get_object({pathParam.functionName}))
                  || ' = :INSTANCE_PK1_VALUE')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('INSTANCE_PK1_VALUE', {pathParam.instancePk1Value}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage})
                       ) "data"
      FROM dual
      WHERE xxas_rslt_cache_pkg.object_pk1_column_name
             (xxas_com_sec_pkg.get_object({pathParam.functionName})) IS NOT NULL
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPk2'
    ,p_description        => 'Get function data by primary key 2'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/by-pk2/{instancePk2Value}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
          ({pathParam.functionName}
          ,xxas_com_varchar2_table
            (xxas_rslt_cache_pkg.object_pk2_column_name
              (xxas_com_sec_pkg.get_object({pathParam.functionName}))
          || ' = :INSTANCE_PK2_VALUE')
          ,xxas_com_srv_param_varray
            (xxas_com_srv_param_value('INSTANCE_PK2_VALUE', {pathParam.instancePk2Value}))
          ,null /* p_rowset_tag_name */
          ,'item' /* p_row_tag_name */
          ,{requestParam.pageNumber}
          ,{requestParam.perPage})
                  )  "data"
      FROM dual
      WHERE xxas_rslt_cache_pkg.object_pk2_column_name
             (xxas_com_sec_pkg.get_object({pathParam.functionName})) IS NOT NULL
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPk3'
    ,p_description        => 'Get function data by primary key 3'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true    
    ,p_path               => '{functionName}/by-pk3/{instancePk3Value}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table
                    (xxas_rslt_cache_pkg.object_pk3_column_name
                      (xxas_com_sec_pkg.get_object({pathParam.functionName}))
                  || ' = :INSTANCE_PK3_VALUE')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('INSTANCE_PK3_VALUE', {pathParam.instancePk3Value}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage}) 
                       ) "data"
      FROM dual
      WHERE xxas_rslt_cache_pkg.object_pk3_column_name
             (xxas_com_sec_pkg.get_object({pathParam.functionName})) IS NOT NULL
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPk4'
    ,p_description        => 'Get function data by primary key 4'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true    
    ,p_path               => '{functionName}/by-pk4/{instancePk4Value}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table
                    (xxas_rslt_cache_pkg.object_pk4_column_name
                      (xxas_com_sec_pkg.get_object({pathParam.functionName}))
                  || ' = :INSTANCE_PK4_VALUE')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('INSTANCE_PK4_VALUE', {pathParam.instancePk4Value}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage}) 
                       ) "data"
      FROM dual
      WHERE xxas_rslt_cache_pkg.object_pk4_column_name
             (xxas_com_sec_pkg.get_object({pathParam.functionName})) IS NOT NULL
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPk5'
    ,p_description        => 'Get function data by primary key 5'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true    
    ,p_path               => '{functionName}/by-pk5/{instancePk5Value}'
    ,p_sql                =>
      q'[
       SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table
                    (xxas_rslt_cache_pkg.object_pk5_column_name
                      (xxas_com_sec_pkg.get_object({pathParam.functionName}))
                  || ' = :INSTANCE_PK5_VALUE')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('INSTANCE_PK5_VALUE', {pathParam.instancePk5Value}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage}) 
                       ) "data"
      FROM dual
      WHERE xxas_rslt_cache_pkg.object_pk5_column_name
             (xxas_com_sec_pkg.get_object({pathParam.functionName})) IS NOT NULL
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByPerson'
    ,p_description        => 'Get function data by person'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/by-person/{personId}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table('PERSON_ID = :PERSON_ID')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('PERSON_ID', {pathParam.personId}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage})
                       ) "data"
      FROM dual
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByCreatorPerson'
    ,p_description        => 'Get function data by creator person'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/by-creator-person/{personId}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table('CREATOR_PERSON_ID = :PERSON_ID')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('PERSON_ID', {pathParam.personId}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage})
                        ) "data"
      FROM dual
        ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetFunctionDataByJob'
    ,p_description        => 'Get function data by job'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => '{functionName}/by-job/{assignmentId}'
    ,p_sql                =>
      q'[
      SELECT XMLElement("data"
                 ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
                 ,xxas_com_sec_pkg.get_obj_data_w_binds
                  ({pathParam.functionName}
                  ,xxas_com_varchar2_table('ASSIGNMENT_ID = :ASSIGNMENT_ID')
                  ,xxas_com_srv_param_varray
                    (xxas_com_srv_param_value('ASSIGNMENT_ID', {pathParam.assignmentId}))
                  ,null /* p_rowset_tag_name */
                  ,'item' /* p_row_tag_name */
                  ,{requestParam.pageNumber}
                  ,{requestParam.perPage}) 
                       ) "data"
      FROM dual
        ]'
    );
    
END;
/
COMMIT;
EXIT;
