Advertisement
fkeles

document-understanding-api-call.pkb

Feb 11th, 2024
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.18 KB | Source Code | 0 0
  1.         IF apex_web_service.g_status_code != 200 THEN
  2.             RAISE upload_failed_exception;
  3.         END IF;
  4.        
  5.         /** Invoke Document Understanding API*/
  6.         l_json_str := document_pkg.get_processorjobs_json(
  7.             p_compartment_id => :DOCAI_COMPARTMENT_ID,
  8.             p_bucket_name => :BUCKET_NAME,
  9.             p_namespace => :TENANCY_OBJSTR_NAMESPACE,
  10.             p_object_name => l_object_name
  11.         );
  12.         --log
  13.         document_pkg.ws_log(l_json_str);
  14.         -- Set the Request HTTP Headers.
  15.         apex_web_service.set_request_headers (
  16.             p_name_01  => 'Content-Type',
  17.             p_value_01 => 'application/json',
  18.             p_reset    => TRUE)
  19.         ;
  20.         l_response := apex_web_service.make_rest_request(
  21.             p_url => :DOCAI_API_ENDPOINT || '/processorJobs'
  22.             , p_http_method => 'POST'
  23.             , p_body => l_json_str
  24.             , p_credential_static_id => :G_OCI_WEB_CREDENTIAL
  25.         );
  26.         --log
  27.         document_pkg.ws_log(l_response);
  28.         document_pkg.ws_log(''||apex_web_service.g_status_code);
  29.        
  30.         IF apex_web_service.g_status_code NOT IN (200, 201) THEN
  31.             RAISE upload_failed_exception;
  32.         END IF;
  33.  
  34.         document_pkg.parse_processorjobs_json (
  35.             p_json_str        => l_response,
  36.             x_compartment_id  => l_compartment_id,
  37.             x_id              => l_job_id,
  38.             x_percentcomplete => l_percentcomplete,
  39.             x_lifecyclestate  => l_lifecyclestate,
  40.             x_namespacename   => l_namespacename,
  41.             x_bucketname      => l_bucketname,
  42.             x_prefix          => l_prefix
  43.         );
  44.         UPDATE document
  45.         SET job_id = l_job_id
  46.             , compartment_id = l_compartment_id
  47.             , percentcomplete = l_percentcomplete
  48.             , lifecyclestate = l_lifecyclestate
  49.         WHERE document_id = l_document_id;
  50.  
  51.         document_pkg.ws_log('l_compartment_id:'||l_compartment_id);
  52.         document_pkg.ws_log('l_job_id:'||l_job_id);
  53.         document_pkg.ws_log('l_percentcomplete:'||l_percentcomplete);
  54.  
  55.         IF l_percentcomplete = 100 THEN
  56.             document_pkg.get_object(P_DOCUMENT_ID => l_document_id);
  57.         END IF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement