Class: Zizia::HyraxMetadataOnlyUpdater
- Inherits:
-
Object
- Object
- Zizia::HyraxMetadataOnlyUpdater
show all
- Defined in:
- lib/zizia/hyrax/hyrax_metadata_only_updater.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(csv_import_detail:, existing_record:, update_record:, attrs:) ⇒ HyraxMetadataOnlyUpdater
Returns a new instance of HyraxMetadataOnlyUpdater.
10
11
12
13
14
15
16
17
18
19
|
# 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
|
Instance Attribute Details
#based_near_attributes ⇒ Object
Returns the value of attribute based_near_attributes.
4
5
6
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 4
def based_near_attributes
@based_near_attributes
end
|
#csv_import_detail ⇒ Object
Returns the value of attribute csv_import_detail.
4
5
6
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 4
def csv_import_detail
@csv_import_detail
end
|
#depositor ⇒ Object
Returns the value of attribute depositor.
4
5
6
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 4
def depositor
@depositor
end
|
#existing_record ⇒ Object
Returns the value of attribute existing_record.
4
5
6
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 4
def existing_record
@existing_record
end
|
#update_record ⇒ Object
Returns the value of attribute update_record.
4
5
6
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 4
def update_record
@update_record
end
|
Instance Method Details
#actor_stack ⇒ Object
25
26
27
28
|
# 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 ⇒ Object
21
22
23
|
# File 'lib/zizia/hyrax/hyrax_metadata_only_updater.rb', line 21
def attrs
@attrs.reject { |k, _v| k == :uploaded_files }
end
|
#create_actor_env ⇒ Object
42
43
44
|
# 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) ⇒ Object
38
39
40
|
# 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 ⇒ Object
30
31
32
|
# 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 ⇒ Object
34
35
36
|
# 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 ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# 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
|