Class: Hyrax::Listeners::WorkflowListener
- Inherits:
-
Object
- Object
- Hyrax::Listeners::WorkflowListener
- Defined in:
- app/services/hyrax/listeners/workflow_listener.rb
Overview
Listens for object lifecycle events that require workflow changes and manages workflow accordingly.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(factory: Hyrax::Workflow::WorkflowFactory) ⇒ WorkflowListener
constructor
A new instance of WorkflowListener.
-
#on_object_deleted(event) ⇒ void
Called when ‘object.deleted’ event is published.
-
#on_object_deposited(event) ⇒ void
Called when ‘object.deposited’ event is published.
Constructor Details
#initialize(factory: Hyrax::Workflow::WorkflowFactory) ⇒ WorkflowListener
Returns a new instance of WorkflowListener.
16 17 18 |
# File 'app/services/hyrax/listeners/workflow_listener.rb', line 16 def initialize(factory: Hyrax::Workflow::WorkflowFactory) @factory = factory end |
Instance Attribute Details
#factory ⇒ #create
12 13 14 |
# File 'app/services/hyrax/listeners/workflow_listener.rb', line 12 def factory @factory end |
Instance Method Details
#on_object_deleted(event) ⇒ void
This method returns an undefined value.
Called when ‘object.deleted’ event is published
39 40 41 42 43 44 45 |
# File 'app/services/hyrax/listeners/workflow_listener.rb', line 39 def on_object_deleted(event) event = event.to_h return unless event[:object] gid = Hyrax::ValkyrieGlobalIdProxy.new(resource: event[:object]).to_global_id return if gid.blank? Sipity::Entity.where(proxy_for_global_id: gid.to_s).destroy_all end |
#on_object_deposited(event) ⇒ void
This method returns an undefined value.
Called when ‘object.deposited’ event is published
24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/hyrax/listeners/workflow_listener.rb', line 24 def on_object_deposited(event) event = event.to_h return Hyrax.logger.warn("Skipping workflow initialization for #{event[:object]}; no user is given\n\t#{event}") if event[:user].blank? factory.create(event[:object], {}, event[:user]) rescue Sipity::StateError, Sipity::ConversionError => err # don't error on known sipity error types; log instead Hyrax.logger.error(err) end |