class Darlingtonia::RecordImporter

Attributes

batch_id[RW]

@!attribute [rw] error_stream

@return [#<<]

@!attribute [rw] info_stream

@return [#<<]

@!attribute [rw] batch_id

@return [String] an optional batch id for this import run

@!attribute [rw] success_count

@return [Integer] a count of the records that were successfully created

@!attribute [rw] failure_count

@return [Integer] a count of the records that failed import
error_stream[RW]

@!attribute [rw] error_stream

@return [#<<]

@!attribute [rw] info_stream

@return [#<<]

@!attribute [rw] batch_id

@return [String] an optional batch id for this import run

@!attribute [rw] success_count

@return [Integer] a count of the records that were successfully created

@!attribute [rw] failure_count

@return [Integer] a count of the records that failed import
failure_count[RW]

@!attribute [rw] error_stream

@return [#<<]

@!attribute [rw] info_stream

@return [#<<]

@!attribute [rw] batch_id

@return [String] an optional batch id for this import run

@!attribute [rw] success_count

@return [Integer] a count of the records that were successfully created

@!attribute [rw] failure_count

@return [Integer] a count of the records that failed import
info_stream[RW]

@!attribute [rw] error_stream

@return [#<<]

@!attribute [rw] info_stream

@return [#<<]

@!attribute [rw] batch_id

@return [String] an optional batch id for this import run

@!attribute [rw] success_count

@return [Integer] a count of the records that were successfully created

@!attribute [rw] failure_count

@return [Integer] a count of the records that failed import
success_count[RW]

@!attribute [rw] error_stream

@return [#<<]

@!attribute [rw] info_stream

@return [#<<]

@!attribute [rw] batch_id

@return [String] an optional batch id for this import run

@!attribute [rw] success_count

@return [Integer] a count of the records that were successfully created

@!attribute [rw] failure_count

@return [Integer] a count of the records that failed import

Public Class Methods

new(error_stream: Darlingtonia.config.default_error_stream, info_stream: Darlingtonia.config.default_info_stream) click to toggle source

@param error_stream [#<<]

# File lib/darlingtonia/record_importer.rb, line 20
def initialize(error_stream: Darlingtonia.config.default_error_stream,
               info_stream: Darlingtonia.config.default_info_stream)
  self.error_stream = error_stream
  self.info_stream  = info_stream
end

Public Instance Methods

import(record:) click to toggle source

@param record [ImportRecord]

@return [void]

# File lib/darlingtonia/record_importer.rb, line 30
def import(record:)
  create_for(record: record)
rescue Faraday::ConnectionFailed, Ldp::HttpError => e
  error_stream << e
rescue RuntimeError => e
  error_stream << e
  raise e
end
import_type() click to toggle source
# File lib/darlingtonia/record_importer.rb, line 39
def import_type
  raise 'No curation_concern found for import' unless
    defined?(Hyrax) && Hyrax&.config&.curation_concerns&.any?

  Hyrax.config.curation_concerns.first
end

Private Instance Methods

create_for(record:) click to toggle source
# File lib/darlingtonia/record_importer.rb, line 48
def create_for(record:)
  info_stream << 'Creating record: ' \
                 "#{record.respond_to?(:title) ? record.title : record}."

  created = import_type.create(record.attributes)

  info_stream << "Record created at: #{created.id}"
end