Skip to content
Snippets Groups Projects
Commit 8bc63c39 authored by Kapil Patel's avatar Kapil Patel
Browse files

Extende support to look by source in activefedora dynamic lookup

parent e1211664
No related branches found
No related tags found
3 merge requests!115Tombstone not available for dataset,!930.3 release,!78Fix importer issues
Pipeline #5815 failed
# frozen_string_literal: true
module Bulkrax
module DynamicRecordLookup
# Search entries, collections, and every available work type for a record that
# has the provided identifier.
#
# @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier
# @param importer_run_id [Number] ID of the current_run of this Importer Job
# @return [Entry, nil], [Work, Collection, nil] Entry if found, otherwise nil and a Work or Collection if found, otherwise nil
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 ||= ActiveFedora::Base.find(identifier)
# NameError for if ActiveFedora isn't installed
rescue NameError, ActiveFedora::ObjectNotFoundError
record = ActiveFedora::Base.where(source_tesim: identifier).first
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
# Check if the record is a Work
def curation_concern?(record)
available_work_types.include?(record.class)
end
private
# @return [Array<Class>] list of work type classes
def available_work_types
# If running in a Hyku app, do not include disabled work types
@available_work_types ||= if defined?(::Hyku)
::Site.instance.available_works.map(&:constantize)
else
::Hyrax.config.curation_concerns
end
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment