-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #104 by adding support for RabbitMQ messaging for the creati…
…on, updates, and deletion of Figgy resources Increasing the test coverage for the FileSet Resource and the publishing of messages for deleted FileSets Restructuring the #parents and #collections methods to be exposed by decorators
- Loading branch information
1 parent
786b0ac
commit 1932c63
Showing
16 changed files
with
356 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,10 @@ def title | |
def manageable_files? | ||
false | ||
end | ||
|
||
# Nested collections are not currently supported | ||
def parents | ||
[] | ||
end | ||
alias collections parents | ||
This comment has been minimized.
Sorry, something went wrong.
escowles
Member
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,12 @@ class FileSetDecorator < Valkyrie::ResourceDecorator | |
def manageable_files? | ||
false | ||
end | ||
|
||
def parents | ||
Valkyrie::MetadataAdapter.find(:indexing_persister).query_service.find_parents(resource: self).to_a | ||
end | ||
|
||
def collections | ||
This comment has been minimized.
Sorry, something went wrong.
escowles
Member
|
||
[] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,9 @@ def iiif_manifest_attributes | |
|
||
current_attributes | ||
end | ||
|
||
def parents | ||
Valkyrie::MetadataAdapter.find(:indexing_persister).query_service.find_references_by(resource: self, property: :member_of_collection_ids).to_a | ||
This comment has been minimized.
Sorry, something went wrong. |
||
end | ||
alias collections parents | ||
This comment has been minimized.
Sorry, something went wrong.
escowles
Member
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
class ManifestEventGenerator | ||
attr_reader :rabbit_exchange | ||
def initialize(rabbit_exchange) | ||
@rabbit_exchange = rabbit_exchange | ||
end | ||
|
||
def record_created(record) | ||
publish_message( | ||
message_with_collections("CREATED", record) | ||
) | ||
end | ||
|
||
def record_deleted(record) | ||
publish_message( | ||
message("DELETED", record) | ||
) | ||
end | ||
|
||
def record_updated(record) | ||
publish_message( | ||
message_with_collections("UPDATED", record) | ||
) | ||
end | ||
|
||
private | ||
|
||
def message(type, record) | ||
{ | ||
"id" => record ? record.id.to_s : nil, | ||
"event" => type, | ||
"manifest_url" => helper.polymorphic_url([:manifest, record]) | ||
} | ||
end | ||
|
||
def message_with_collections(type, record) | ||
output = message(type, record) | ||
if record.decorate.respond_to? :collections | ||
output["collection_slugs"] = record.decorate.collections.map { |collection| collection.try(:slug) }.compact | ||
end | ||
output | ||
end | ||
|
||
def publish_message(message) | ||
rabbit_exchange.publish(message.to_json) | ||
end | ||
|
||
def helper | ||
@helper ||= ManifestBuilder::ManifestHelper.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
class MessagingClient | ||
attr_reader :amqp_url | ||
def initialize(amqp_url) | ||
@amqp_url = amqp_url | ||
end | ||
|
||
def publish(message) | ||
exchange.publish(message, persistent: true) | ||
rescue | ||
Rails.logger.warn "Unable to publish message to #{amqp_url}" | ||
end | ||
|
||
private | ||
|
||
def bunny_client | ||
@bunny_client ||= Bunny.new(amqp_url).tap(&:start) | ||
end | ||
|
||
def channel | ||
@channel ||= bunny_client.create_channel | ||
end | ||
|
||
def exchange | ||
@exchange ||= channel.fanout(Figgy.config['events']['exchange']['plum'], durable: true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
If we are finding the parent of the FileSet, and then sending the delete event on the parent, wouldn't that send a delete message when you removed a page from a ScannedResource?