-
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 pull request #315 from scientist-softserv/extracting-transactions
🎁 Add Transaction for Cleaning Up Split Pages
- Loading branch information
Showing
13 changed files
with
195 additions
and
23 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
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
6 changes: 6 additions & 0 deletions
6
spec/transactions/hyrax/transactions/container_decorator_spec.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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe do | ||
end |
21 changes: 21 additions & 0 deletions
21
spec/transactions/hyrax/transactions/iiif_print_container_decorator_spec.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::Transactions::Container do | ||
describe 'file_set.destroy' do | ||
subject(:transaction_step) { described_class['file_set.destroy'] } | ||
describe '#steps' do | ||
subject { transaction_step.steps } | ||
it { | ||
is_expected.to match_array(["file_set.iiif_print_conditionally_destroy_spawned_children", | ||
"file_set.remove_from_work", | ||
"file_set.delete"]) | ||
} | ||
end | ||
end | ||
describe 'file_set.iiif_print_conditionally_destroy_spawned_children' do | ||
subject(:transaction_step) { described_class['file_set.iiif_print_conditionally_destroy_spawned_children'] } | ||
it { is_expected.to be_a Hyrax::Transactions::Steps::ConditionallyDestroyChildrenFromSplit } | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
spec/transactions/hyrax/transactions/steps/conditionally_destroy_children_from_split_spec.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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::Transactions::Steps::ConditionallyDestroyChildrenFromSplit do | ||
describe '#call' do | ||
let(:file_set) { double(Hyrax::FileSet, persisted?: persisted) } | ||
subject { described_class.new.call(file_set) } | ||
|
||
describe 'with an unsaved resource' do | ||
let(:persisted) { false } | ||
it { is_expected.to be_failure } | ||
end | ||
|
||
describe 'with a saved resource' do | ||
let(:persisted) { true } | ||
before { expect(IiifPrint.persistence_adapter).to receive(:parent_for).and_return(parent) } | ||
|
||
context 'without a parent' do | ||
let(:parent) { nil } | ||
it { is_expected.to be_success } | ||
end | ||
|
||
context 'with a parent' do | ||
let(:parent) { double(Valkyrie::Resource) } | ||
it do | ||
expect(IiifPrint::SplitPdfs::DestroyPdfChildWorksService).to receive(:conditionally_destroy_spawned_children_of) | ||
.with(file_set: file_set, work: parent) | ||
is_expected.to be_success | ||
end | ||
end | ||
end | ||
end | ||
end |