Class: Bulkrax::ChildRelationshipsJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Bulkrax::ChildRelationshipsJob
- Defined in:
- app/jobs/bulkrax/child_relationships_job.rb
Instance Method Summary collapse
- #child_entries ⇒ Object
- #child_works_hash ⇒ Object
- #collection_membership ⇒ Object
- #entry ⇒ Object
- #importer_run_id ⇒ Object
- #perform(*args) ⇒ Object
- #user ⇒ Object
- #work_membership ⇒ Object
Instance Method Details
#child_entries ⇒ Object
49 50 51 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 49 def child_entries @child_entries ||= @args[1].map { |e| Bulkrax::Entry.find(e) } end |
#child_works_hash ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 53 def child_works_hash @child_works_hash ||= child_entries.each_with_object({}) do |child_entry, hash| work = child_entry.factory.find # If we can't find the Work/Collection, raise a custom error raise ChildWorksError if work.blank? hash[work.id] = { class_name: work.class.to_s, entry.parser.source_identifier => child_entry.identifier } end end |
#collection_membership ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 21 def collection_membership # add collection to works member_of_collection = [] child_works_hash.each { |k, v| member_of_collection << k if v[:class_name] != 'Collection' } member_of_collection.each { |work| work_child_collection_parent(work) } # add collections to collection members_collections = [] child_works_hash.each { |k, v| members_collections << k if v[:class_name] == 'Collection' } collection_parent_collection_child(members_collections) if members_collections.present? end |
#entry ⇒ Object
45 46 47 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 45 def entry @entry ||= Bulkrax::Entry.find(@args[0]) end |
#importer_run_id ⇒ Object
62 63 64 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 62 def importer_run_id @args[2] end |
#perform(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 8 def perform(*args) @args = args if entry.factory_class == Collection collection_membership else work_membership end # Not all of the Works/Collections exist yet; reschedule rescue Bulkrax::ChildWorksError reschedule(args[0], args[1], args[2]) end |
#user ⇒ Object
66 67 68 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 66 def user @user ||= entry.importerexporter.user end |
#work_membership ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/jobs/bulkrax/child_relationships_job.rb', line 33 def work_membership # add works to work # reject any Collections, they can't be children of Works members_works = [] # reject any Collections, they can't be children of Works child_works_hash.each { |k, v| members_works << k if v[:class_name] != 'Collection' } if members_works.length < child_entries.length # rubocop:disable Style/IfUnlessModifier Rails.logger.warn("Cannot add collections as children of works: #{(@child_entries.length - members_works.length)} collections were discarded for parent entry #{@entry.id} (of #{@child_entries.length})") end work_parent_work_child(members_works) if members_works.present? end |