Class: FolioClient::DataImport

Inherits:
Object
  • Object
show all
Defined in:
lib/folio_client/data_import.rb

Overview

Imports MARC records into FOLIO

Constant Summary collapse

JOB_PROFILE_ATTRIBUTES =
%w[id name description dataType].freeze

Instance Method Summary collapse

Instance Method Details

#import(records:, job_profile_id:, job_profile_name:) ⇒ JobStatus

rubocop:disable Metrics/MethodLength

Parameters:

  • records (Array<MARC::Record>)

    records to be imported

  • job_profile_id (String)

    job profile id to use for import

  • job_profile_name (String)

    job profile name to use for import

Returns:

  • (JobStatus)

    a job status instance to get information about the data import job



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/folio_client/data_import.rb', line 16

def import(records:, job_profile_id:, job_profile_name:)
  response_hash = client.post('/data-import/uploadDefinitions', { fileDefinitions: [{ name: marc_filename }] })
  upload_definition_id = response_hash.dig('fileDefinitions', 0, 'uploadDefinitionId')
  job_execution_id = response_hash.dig('fileDefinitions', 0, 'jobExecutionId')
  file_definition_id = response_hash.dig('fileDefinitions', 0, 'id')

  upload_file_response_hash = client.post(
    "/data-import/uploadDefinitions/#{upload_definition_id}/files/#{file_definition_id}",
    marc_binary(records),
    content_type: 'application/octet-stream'
  )

  client.post(
    "/data-import/uploadDefinitions/#{upload_definition_id}/processFiles",
    {
      uploadDefinition: upload_file_response_hash,
      jobProfileInfo: {
        id: job_profile_id,
        name: job_profile_name,
        dataType: 'MARC'
      }
    }
  )

  JobStatus.new(job_execution_id: job_execution_id)
end

#job_profilesArray<Hash<String,String>>

Returns a list of job profile hashes.

Returns:

  • (Array<Hash<String,String>>)

    a list of job profile hashes



45
46
47
48
49
50
# File 'lib/folio_client/data_import.rb', line 45

def job_profiles
  client
    .get('/data-import-profiles/jobProfiles')
    .fetch('jobProfiles', [])
    .map { |profile| profile.slice(*JOB_PROFILE_ATTRIBUTES) }
end