/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2016 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 

  e_dir_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_dir_exists, -31003);

  e_does_not_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_does_not_exists , -31001);

  result boolean;
  
BEGIN

  BEGIN

    result := DBMS_XDB.createfolder('/public/xxas/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/view/');

  EXCEPTION
    WHEN e_dir_exists THEN
      NULL;
  END;

  
  BEGIN

    DBMS_XDB.DeleteResource('/public/xxas/emp/view/directreports.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/directreports.xml',
'<View objectType="XXAS_DIRECT_REPORT" deleteAllowed="false" title="Direct reports" defaultFormHandler="">

  <CreateFields>
    <Date id="DR_EFFECTIVE_DATE" label="{message.XXAS_MSS_DR_EFFECTIVE_DATE}" enabled="true" visible="false" required="true"/>
    <Hidden id="DR_PERSON_ID"/>
    <ListItem id="DR_LI_PERSON_ID" label="{message.XXAS_MSS_DR_LI_PERSON_ID}" visible="true" listFunction="xxas_mss_util_pkg.get_dr_list_item_data"/>
    <Hidden id="DIRECT_REPORT"/>
    <Hidden id="JOB_ID"/>
    <Hidden id="DR_JOB"/>
    <Hidden id="DR_CUR_MANAGER"/>
    <Combolist id="DR_NEW_MANAGER" label="{message.XXAS_MSS_DR_NEW_MANAGER}" enabled="true" visible="true" listProvider="REST:peoplesearch/dir-reportee?q={searchText}" longlist="true" required="true"/>
  </CreateFields>

</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/directreports.xml');
END;
/
COMMIT;
EXIT;
