Skip to content

Commit

Permalink
subscribe the MetadataIndexListener in config/initializers/listeners.…
Browse files Browse the repository at this point in the history
…rb; add on_object_metadata_created
  • Loading branch information
Julie Allinson committed Jan 25, 2020
1 parent 06c944b commit e22060d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
12 changes: 11 additions & 1 deletion app/services/hyrax/listeners/metadata_index_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ class MetadataIndexListener
#
# @param event [Dry::Event]
def on_object_metadata_updated(event)
Hyrax.index_adapter.save(resource: event[:object])
Hyrax.index_adapter.save(resource:
Hyrax::ValkyrieIndexer.for(resource: event[:object]).resource)
end

##
# Index the resource.
#
# @param event [Dry::Event]
def on_object_metadata_created(event)
Hyrax.index_adapter.save(resource:
Hyrax::ValkyrieIndexer.for(resource: event[:object]).resource)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/listeners.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

Hyrax.publisher.subscribe(Hyrax::Listeners::AclIndexListener.new)
Hyrax.publisher.subscribe(Hyrax::Listeners::MetadataIndexListener.new)
Hyrax.publisher.subscribe(Hyrax::Listeners::BatchNotificationListener.new)
Hyrax.publisher.subscribe(Hyrax::Listeners::ObjectLifecycleListener.new)
Hyrax.publisher.subscribe(Hyrax::Listeners::FileSetLifecycleListener.new)
Expand All @@ -10,6 +11,7 @@
# When callbacks are removed and replaced with direct event publication, drop these blocks
Hyrax.config.callback.set(:after_create_concern, warn: false) do |curation_concern, user|
Hyrax.publisher.publish('object.deposited', object: curation_concern, user: user)
Hyrax.publisher.publish('object.metadata.created', object: curation_concern, user: user)
end

Hyrax.config.callback.set(:after_create_fileset, warn: false) do |file_set, user|
Expand Down
8 changes: 0 additions & 8 deletions lib/generators/hyrax/work_resource/templates/actor.rb.erb

This file was deleted.

1 change: 1 addition & 0 deletions lib/hyrax/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Publisher
register_event('object.deleted')
register_event('object.deposited')
register_event('object.acl.updated')
register_event('object.metadata.created')
register_event('object.metadata.updated')
end
end
6 changes: 5 additions & 1 deletion lib/hyrax/specs/spy_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Specs
class SpyListener
attr_reader :file_set_attached, :file_set_url_imported, :object_deleted,
:object_deposited, :object_acl_updated,
:object_metadata_updated
:object_metadata_created, :object_metadata_updated

def on_object_deleted(event)
@object_deleted = event
Expand All @@ -19,6 +19,10 @@ def on_object_acl_updated(event)
@object_acl_updated = event
end

def on_object_metadata_created(event)
@object_metadata_created = event
end

def on_object_metadata_updated(event)
@object_metadata_updated = event
end
Expand Down
6 changes: 6 additions & 0 deletions spec/actors/hyrax/actors/generic_work_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
.to change { listener.object_deposited&.payload }
.to eq object: curation_concern, user: user
end

it 'publishes an object.metadata.created event' do
expect { middleware.create(env) }
.to change { listener.object_metadata_created&.payload }
.to eq object: curation_concern, user: user
end
end

context 'valid attributes', perform_enqueued: [AttachFilesToWorkJob, IngestJob] do
Expand Down
10 changes: 10 additions & 0 deletions spec/services/hyrax/listeners/metadata_index_listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@
.to contain_exactly(resource)
end
end

describe '#on_object_metadata_created' do
let(:event_type) { :on_object_metadata_created }

it 'indexes the object on the configured adapter' do
expect { listener.on_object_metadata_created(event) }
.to change { fake_adapter.saved_resources }
.to contain_exactly(resource)
end
end
end

0 comments on commit e22060d

Please sign in to comment.