-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Extract direct ActiveFedora calls to adapter
With Valkyrie looming large, this change refactors the code towards an adapter pattern; one that will allow for creating a Valkyrie adapter and then configuring IIIFPrint accordingly. We'll also need to consider how we duplicate the actor work within a transaction and/or publisher/listener setup. There are likely other places where we're making assumptions about presenters and/or the data models we're processing.
- Loading branch information
Showing
13 changed files
with
191 additions
and
38 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
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
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,40 @@ | ||
module IiifPrint | ||
## | ||
# The PersistenceLayer module provides the namespace for other adapters: | ||
# | ||
# - {IiifPrint::PersistenceLayer::ActiveFedoraAdapter} | ||
# - {IiifPrint::PersistenceLayer::ValkyrieAdapter} | ||
# | ||
# And the defining interface in the {IiifPrint::PersistenceLayer::AbstractAdapter} | ||
module PersistenceLayer | ||
# @abstract | ||
class AbstractAdapter | ||
## | ||
# @abstract | ||
def self.parent_for(*); end | ||
|
||
## | ||
# @abstract | ||
def self.grandparent_for(*); end | ||
|
||
## | ||
# @abstract | ||
def self.solr_field_query(*); end | ||
|
||
## | ||
# @abstract | ||
def self.clean_for_tests! | ||
return false unless Rails.env.test? | ||
yield | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.solr_query(*args); end | ||
|
||
## | ||
# @abstract | ||
def self.solr_name(*args); end | ||
end | ||
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,65 @@ | ||
module IiifPrint | ||
module PersistenceLayer | ||
class ActiveFedoraAdapter < AbstractAdapter | ||
## | ||
# Return the immediate parent of the given :file_set. | ||
# | ||
# @param file_set [FileSet] | ||
# @return [#work?, Hydra::PCDM::Work] | ||
# @return [NilClass] when no parent is found. | ||
def self.parent_for(file_set) | ||
# fallback to Fedora-stored relationships if work's aggregation of | ||
# file set is not indexed in Solr | ||
file_set.parent || file_set.member_of.find(&:work?) | ||
end | ||
|
||
## | ||
# Return the parent's parent of the given :file_set. | ||
# | ||
# @param file_set [FileSet] | ||
# @return [#work?, Hydra::PCDM::Work] | ||
# @return [NilClass] when no grand parent is found. | ||
def self.grandparent_for(file_set) | ||
parent_of_file_set = parent_for(file_set) | ||
# HACK: This is an assumption about the file_set structure, namely that an image page split from | ||
# a PDF is part of a file set that is a child of a work that is a child of a single work. That | ||
# is, it only has one grand parent. Which is a reasonable assumption for IIIF Print but is not | ||
# valid when extended beyond IIIF Print. That is GenericWork does not have a parent method but | ||
# does have a parents method. | ||
parent_of_file_set.try(:parent_works).try(:first) || | ||
parent_of_file_set.try(:parents).try(:first) || | ||
parent_of_file_set&.member_of&.find(&:work?) | ||
end | ||
|
||
def self.solr_construct_query(*args) | ||
if defined?(Hyrax::SolrQueryBuilderService) | ||
Hyrax::SolrQueryBuilderService.construct_query(*args) | ||
else | ||
ActiveFedora::SolrQueryBuilderService.construct_query(*args) | ||
end | ||
end | ||
|
||
def self.clean_for_tests! | ||
super do | ||
ActiveFedora::Cleaner.clean! | ||
end | ||
end | ||
|
||
def self.solr_query(*args) | ||
if defined?(Hyrax::SolrService) | ||
Hyrax::SolrService.query(*args) | ||
else | ||
ActiveFedora::SolrService.query(*args) | ||
end | ||
end | ||
|
||
def self.solr_name(field_name) | ||
if defined?(Hyrax) && Hyrax.config.respond_to?(:index_field_mapper) | ||
Hyrax.config.index_field_mapper.solr_name(field_name.to_s) | ||
else | ||
::ActiveFedora.index_field_mapper.solr_name(field_name.to_s) | ||
end | ||
end | ||
end | ||
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,45 @@ | ||
module IiifPrint | ||
module PersistenceLayer | ||
class ValkyrieAdapter < AbstractAdapter | ||
## | ||
# Return the immediate parent of the given :file_set. | ||
# | ||
# @param file_set [FileSet] | ||
# @return [#work?, Hydra::PCDM::Work] | ||
# @return [NilClass] when no parent is found. | ||
def self.parent_for(file_set) | ||
Hyrax.index_adapter.find_parents(resource: file_set).first | ||
end | ||
|
||
## | ||
# Return the parent's parent of the given :file_set. | ||
# | ||
# @param file_set [FileSet] | ||
# @return [#work?, Hydra::PCDM::Work] | ||
# @return [NilClass] when no grand parent is found. | ||
def self.grandparent_for(file_set) | ||
parent = Hyrax.index_adapter.find_parents(resource: file_set).first | ||
return nil unless parent | ||
Hyrax.index_adapter.find_parents(resource: parent).first | ||
end | ||
|
||
def self.solr_construct_query(*args) | ||
Hyrax::SolrQueryBuilderService.construct_query(*args) | ||
end | ||
|
||
def self.clean_for_tests! | ||
# For Fedora backed repositories, we'll want to consider some cleaning mechanism. For | ||
# database backed repositories, we can rely on the database_cleaner gem. | ||
raise NotImplementedError | ||
end | ||
|
||
def self.solr_query(*args) | ||
Hyrax::SolrService.query(*args) | ||
end | ||
|
||
def self.solr_name(field_name) | ||
Hyrax.config.index_field_mapper.solr_name(field_name.to_s) | ||
end | ||
end | ||
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