class Zizia::HyraxMetadataOnlyUpdater

Attributes

based_near_attributes[RW]
csv_import_detail[RW]
depositor[RW]
existing_record[RW]
update_record[RW]

Public Class Methods

new(csv_import_detail:, existing_record:, update_record:, attrs:) click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 10
def initialize(csv_import_detail:,
               existing_record:,
               update_record:,
               attrs:)
  @csv_import_detail = csv_import_detail
  @depositor = ::User.find(csv_import_detail.depositor_id)
  @update_record = update_record
  @existing_record = existing_record
  @attrs = attrs
end

Public Instance Methods

actor_stack() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 25
def actor_stack
  terminator = Hyrax::Actors::Terminator.new
  Zizia::MetadataOnlyStack.build_stack.build(terminator)
end
attrs() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 21
def attrs
  @attrs.reject { |k, _v| k == :uploaded_files }
end
create_actor_env() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 42
def create_actor_env
  Hyrax::Actors::Environment.new(existing_record, ::Ability.new(depositor), attrs)
end
failed(attr) click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 38
def failed(attr)
  Rails.logger.error "[zizia] event: validation_failed, batch_id: #{csv_import_detail.batch_id}, collection_id: #{csv_import_detail.collection_id}, attribute: #{attr.capitalize}, message: #{msg}, record_title: record_title: #{attrs[:title] ? attrs[:title] : attrs}"
end
started() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 30
def started
  Rails.logger.info "[zizia] event: record_update_started, batch_id: #{csv_import_detail.batch_id}, collection_id: #{csv_import_detail.collection_id}, #{csv_import_detail.deduplication_field}: #{update_record.respond_to?(csv_import_detail.deduplication_field) ? update_record.send(csv_import_detail.deduplication_field.deduplication_field) : update_record}"
end
succeeded() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 34
def succeeded
  Rails.logger.info "[zizia] event: record_updated, batch_id: #{csv_import_detail.batch_id}, record_id: #{csv_import_detail.existing_record.id}, collection_id: #{csv_import_detail.collection_id}, #{csv_import_detail.deduplication_field}: #{existing_record.respond_to?(csv_import_detail.deduplication_field) ? existing_record.send(csv_import_detail.deduplication_field) : existing_record}"
end
update() click to toggle source
# File lib/zizia/hyrax/hyrax_metadata_only_updater.rb, line 46
def update
  if actor_stack.update(create_actor_env)
    csv_import_detail.success_count += 1
  else
    existing_record.errors.each_key do |attr, _msg|
      failed(attr)
    end
    csv_import_detail.failure_count += 1
  end
  csv_import_detail.save
end