Skip to content

Commit

Permalink
🧹 normalize magic strings into constants for referencing later
Browse files Browse the repository at this point in the history
Convert the create_with_bulk_behavior and update_with_bulk_behavior to a constant; that way we can reference it in IiifPrint and document the “magic” string.

Co-Authored-By: LaRita Robinson <[email protected]>
  • Loading branch information
Shana Moore and laritakr committed Jan 24, 2024
1 parent 6cbb00c commit 02db077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create
result = transaction
.with_step_args(
# "work_resource.add_to_parent" => {parent_id: @related_parents_parsed_mapping, user: @user},
"work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user },
"work_resource.#{Bulkrax::Container::AddBulkraxFiles}" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user },
"change_set.set_user_as_depositor" => { user: @user },
"work_resource.change_depositor" => { user: @user },
'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
Expand Down Expand Up @@ -83,7 +83,7 @@ def update

result = update_transaction
.with_step_args(
"work_resource.add_bulkrax_files" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user }
"work_resource.#{Bulkrax::Container::AddBulkraxFiles}" => { files: get_s3_files(remote_files: attributes["remote_files"]), user: @user }

# TODO: uncomment when we upgrade Hyrax 4.x
# 'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
Expand Down Expand Up @@ -165,12 +165,12 @@ def destroy_existing_files
private

def transaction
Hyrax::Transactions::Container["work_resource.create_with_bulk_behavior"]
Hyrax::Transactions::Container["work_resource.#{Bulkrax::Container::CreateWithBulkBehavior}"]
end

# Customize Hyrax::Transactions::WorkUpdate transaction with bulkrax
def update_transaction
Hyrax::Transactions::Container["work_resource.update_with_bulk_behavior"]
Hyrax::Transactions::Container["work_resource.#{Bulkrax::Container::UpdateWithBulkBehavior}"]
end

# Query child FileSet in the resource/object
Expand Down
14 changes: 9 additions & 5 deletions app/transactions/bulkrax/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
module Bulkrax
class Container
extend Dry::Container::Mixin

CreateWithBulkBehavior = 'create_with_bulk_behavior'.freeze
UpdateWithBulkBehavior = 'update_with_bulk_behavior'.freeze
AddBulkraxFiles = 'add_bulkrax_files'.freeze

namespace "work_resource" do |ops|
ops.register "create_with_bulk_behavior" do
ops.register CreateWithBulkBehavior do
steps = Hyrax::Transactions::WorkCreate::DEFAULT_STEPS.dup
steps[steps.index("work_resource.add_file_sets")] = "work_resource.add_bulkrax_files"
steps[steps.index("work_resource.add_file_sets")] = "work_resource.#{Bulkrax::Container::AddBulkraxFiles}"

Hyrax::Transactions::WorkCreate.new(steps: steps)
end

ops.register "update_with_bulk_behavior" do
ops.register UpdateWithBulkBehavior do
steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup
steps[steps.index("work_resource.add_file_sets")] = "work_resource.add_bulkrax_files"
steps[steps.index("work_resource.add_file_sets")] = "work_resource.#{Bulkrax::Container::AddBulkraxFiles}"

Hyrax::Transactions::WorkUpdate.new(steps: steps)
end
Expand All @@ -25,7 +29,7 @@ class Container
# Hyrax::Transactions::Steps::AddFileSets.new(handler: InlineUploadHandler)
# end

ops.register "add_bulkrax_files" do
ops.register AddBulkraxFiles do
Bulkrax::Steps::AddFiles.new
end
end
Expand Down

0 comments on commit 02db077

Please sign in to comment.