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

Constructor Details

#initialize(client) ⇒ DataImport

Returns a new instance of DataImport.

Parameters:



12
13
14
# File 'lib/folio_client/data_import.rb', line 12

def initialize(client)
  @client = client
end

Instance Method Details

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

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

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



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

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(client, 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



48
49
50
51
52
53
# File 'lib/folio_client/data_import.rb', line 48

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