Module: Bulkrax::DynamicRecordLookup
- Included in:
- CreateRelationshipsJob, ImportFileSetJob, ObjectFactoryInterface
- Defined in:
- app/models/concerns/bulkrax/dynamic_record_lookup.rb
Overview
TODO: Extract methods to class methods; there’s no reason for these methods to be a mixin. TODO: Add specs to test in isolation
Instance Method Summary collapse
-
#find_record(identifier, importer_run_id = nil) ⇒ Entry?
Search entries, collections, and every available work type for a record that has the provided identifier.
Instance Method Details
#find_record(identifier, importer_run_id = nil) ⇒ Entry?
Search entries, collections, and every available work type for a record that has the provided identifier.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/concerns/bulkrax/dynamic_record_lookup.rb', line 13 def find_record(identifier, importer_run_id = nil) # check for our entry in our current importer first importer_id = ImporterRun.find(importer_run_id).importer_id default_scope = { identifier: identifier, importerexporter_type: 'Bulkrax::Importer' } begin # the identifier parameter can be a :source_identifier or the id of an object record = Entry.find_by(default_scope.merge({ importerexporter_id: importer_id })) || Entry.find_by(default_scope) record ||= Bulkrax.object_factory.find(identifier) # NameError for if ActiveFedora isn't installed rescue NameError, ActiveFedora::ObjectNotFoundError, Bulkrax::ObjectFactoryInterface::ObjectNotFoundError record = nil end # return the found entry here instead of searching for it again in the CreateRelationshipsJob # also accounts for when the found entry isn't a part of this importer record.is_a?(Entry) ? [record, record.factory.find] : [nil, record] end |