-
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.
Merge branch 'main' into rails_hyrax_upgrade
* main: 🎁 Add Transaction for Cleaning Up Split Pages ♻️ Extract direct ActiveFedora calls to adapter
- Loading branch information
Showing
21 changed files
with
378 additions
and
53 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
32 changes: 32 additions & 0 deletions
32
app/transactions/hyrax/transactions/iiif_print_container_decorator.rb
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,32 @@ | ||
module Hyrax | ||
module Transactions | ||
## | ||
# This decorator does the following: | ||
# | ||
# - Prepend the {ConditionallyDestroyChildrenFromSplit} transaction to the "file_set.destroy" | ||
# step. The prependment corresponds to the behavior for | ||
# {IiifPrint::Actors::FileSetActorDecorator#destroy} | ||
# | ||
# For more information about adjusting transactions, see | ||
# [Transitioning workshop solution for adding transaction](https://github.com/samvera-labs/transitioning-to-valkyrie-workshop/commit/bcab2bb8f65078e88395c68f72be00e7ffad57ec) | ||
# | ||
# @see https://github.com/samvera/hyrax/blob/f875d61dc87229cf1f05eb2bb6d414b5ef314616/lib/hyrax/transactions/container.rb | ||
class IiifPrintContainerDecorator | ||
extend Dry::Container::Mixin | ||
|
||
namespace 'file_set' do |ops| | ||
ops.register 'iiif_print_conditionally_destroy_spawned_children' do | ||
Steps::ConditionallyDestroyChildrenFromSplit.new | ||
end | ||
ops.register 'destroy' do | ||
Hyrax::Transactions::FileSetDestroy.new( | ||
steps: (['file_set.iiif_print_conditionally_destroy_spawned_children'] + | ||
Hyrax::Transactions::FileSetDestroy::DEFAULT_STEPS) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hyrax::Transactions::Container.merge(Hyrax::Transactions::IiifPrintContainerDecorator) |
31 changes: 31 additions & 0 deletions
31
app/transactions/hyrax/transactions/steps/conditionally_destroy_children_from_split.rb
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,31 @@ | ||
module Hyrax | ||
module Transactions | ||
module Steps | ||
## | ||
# For a FileSet that is a PDF, we need to delete any works and file_sets that are the result of | ||
# splitting that PDF into constituent images of each page of the PDF. This is responsible for | ||
# that work. | ||
class ConditionallyDestroyChildrenFromSplit | ||
include Dry::Monads[:result] | ||
|
||
## | ||
# @param resource [Hyrax::FileSet] | ||
def call(resource) | ||
return Failure(:resource_not_persisted) unless resource.persisted? | ||
|
||
parent = IiifPrint.persistence_adapter.parent_for(resource) | ||
return Success(true) unless parent | ||
|
||
# We do not care about the results of this call; as it is conditionally looking for things | ||
# to destroy. | ||
IiifPrint::SplitPdfs::DestroyPdfChildWorksService.conditionally_destroy_spawned_children_of( | ||
file_set: resource, | ||
work: parent | ||
) | ||
|
||
Success(true) | ||
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
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,58 @@ | ||
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 | ||
## | ||
# @param file_set [Object] | ||
# @param work [Object] | ||
# @param model [Class] The class name for which we'll split children. | ||
def self.destroy_children_split_from(file_set:, work:, model:) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.parent_for(*) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.grandparent_for(*) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.solr_field_query(*) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.clean_for_tests! | ||
return false unless Rails.env.test? | ||
yield | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.solr_query(*args) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
end | ||
|
||
## | ||
# @abstract | ||
def self.solr_name(*args) | ||
raise NotImplementedError, "#{self}.{__method__}" | ||
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,83 @@ | ||
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 | ||
|
||
## | ||
# @param file_set [Object] | ||
# @param work [Object] | ||
# @param model [Class] The class name for which we'll split children. | ||
def self.destroy_children_split_from(file_set:, work:, model:) | ||
# look first for children by the file set id they were split from | ||
children = model.where(split_from_pdf_id: file_set.id) | ||
if children.blank? | ||
# find works where file name and work `to_param` are both in the title | ||
children = model.where(title: file_set.label).where(title: work.to_param) | ||
end | ||
return if children.blank? | ||
children.each do |rcd| | ||
rcd.destroy(eradicate: true) | ||
end | ||
true | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.