Sha256: 82aedc99e2674225488bef2ff3fcdb1f9caf3fe8a9d5802350d0023c97b1e381

Contents?: true

Size: 1.99 KB

Versions: 13

Compression:

Stored size: 1.99 KB

Contents

# 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 = 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

    # 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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bulkrax-4.4.2 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.4.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.3.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-5.0.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.4.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.3.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.2.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.2.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.1.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.1.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-4.0.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-3.5.1 app/models/concerns/bulkrax/dynamic_record_lookup.rb
bulkrax-3.5.0 app/models/concerns/bulkrax/dynamic_record_lookup.rb