  /* $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/testaccess.xml');

    EXCEPTION
      WHEN e_does_not_exists THEN
        NULL;
    END;

    
    result := DBMS_XDB.createresource('/public/xxas/emp/view/testaccess.xml',
  '<View title="Test access" showSubmit="false" defaultFormHandler="xxas_bk_test_access.xxas_available_page_keys" clientAutosave="false">
  <EditFields>
    <Hidden id="MENU_ID"/>
    <Hidden id="FUNCTION_ID"/>
    <Hidden id="OBJECT_ID"/>
    <Hidden id="PAGE_ID"/>
    <TextInput id="VALID_OBJECT_ID" label="{message.XXAS_BK_TST_ABOUT_ME}" required="false" enabled="true" visible="true" hideIf="model.OBJECT_ID.value == NULL" refreshOnChange="true"/>
    <Combolist id="USER_ID" label="{message.XXAS_BK_TST_USER_NAME}" required="true" enabled="true" visible="true" longlist="true" listProvider="REST:users?q={searchText}" refreshOnChange="true"/>
    <TextInput id="AVAILABLE_PAGE_KEYS" label="{message.XXAS_BK_TST_PAGE_KEYS}" visible="true" enabled="false" required="false" hideIf="!model.USER_ID.value || model.VALID_OBJECT_ID.value == NULL"/>
    <TextInput id="OBJECTID_RESTRICTION" label="{message.XXAS_BK_TST_OBJID}" visible="true" enabled="false" required="false" hideIf="!model.USER_ID.value || model.VALID_OBJECT_ID.value == NULL"/>
    <TextArea id="SECURITY_PREDICATE" label="{message.XXAS_BK_TST_PREDICATE}" visible="true" enabled="false" required="false" hideIf="!model.USER_ID.value || model.VALID_OBJECT_ID.value == NULL"/>
    <TextInput id="USER_ACCESS" label="{message.XXAS_BK_TST_ACCESS}" visible="true" enabled="false" required="false" hideIf="!model.USER_ID.value"/>
  </EditFields>
</View>
' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/testaccess.xml');
END;
/
COMMIT;
EXIT;
