Sha256: c1965fa70aea74baacfa0efc4dbf4f9f6501a49942faab63344519c4196570cd

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module Hyrax
  module Listeners
    ##
    # Listens for events related to {Hyrax::FileMetadata}
    class FileMetadataListener
      ##
      # Called when 'file.characterized' event is published;
      # allows post-characterization handling, like derivatives generation.
      #
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_file_characterized(event)
        CreateDerivativesJob
          .perform_later(event[:file_set], event[:file_id], event[:path_hint])
      end

      ##
      # Called when 'file.metadata.updated' event is published; reindexes a
      # {Hyrax::FileSet} when a file claiming to be its `pcdm_use:OriginalFile`
      #
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_file_metadata_updated(event)
        return unless event[:metadata].original_file?

        file_set = Hyrax.query_service.find_by(id: event[:metadata].file_set_id)
        Hyrax.index_adapter.save(resource: file_set)
      rescue Valkyrie::Persistence::ObjectNotFoundError => err
        Hyrax.logger.warn "tried to index file with id #{event[:metadata].id} " \
                          "in response to an event of type #{event.id} but " \
                          "encountered an error #{err.message}. should this " \
                          "object be in a FileSet #{event[:metadata]}"
      end

      ##
      # Called when 'object.file.uploaded' event is published
      # @param [Dry::Events::Event] event
      # @return [void]
      def on_object_file_uploaded(event)
        # Run characterization
        Hyrax.config
             .characterization_service
             .run(metadata: event[:metadata], file: event[:metadata].file)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-4.0.0 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-4.0.0.rc3 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-4.0.0.rc2 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-4.0.0.rc1 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-3.5.0 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-4.0.0.beta2 app/services/hyrax/listeners/file_metadata_listener.rb
hyrax-3.4.2 app/services/hyrax/listeners/file_metadata_listener.rb