-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Match Hyrax convention by using bulkrax/transactions.
- Loading branch information
LaRita Robinson
committed
Jan 24, 2024
1 parent
ed2ffb3
commit f573eb0
Showing
7 changed files
with
100 additions
and
96 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
# frozen_string_literal: true | ||
require 'dry/container' | ||
|
||
module Bulkrax | ||
module Transactions | ||
class Container | ||
extend Dry::Container::Mixin | ||
|
||
ADD_BULKRAX_FILES = 'add_bulkrax_files' | ||
CREATE_WITH_BULK_BEHAVIOR = 'create_with_bulk_behavior' | ||
CREATE_WITH_BULK_BEHAVIOR_STEPS = begin | ||
steps = Hyrax::Transactions::WorkCreate::DEFAULT_STEPS.dup | ||
steps[steps.index("work_resource.add_file_sets")] = "work_resource.#{Bulkrax::Transactions::Container::ADD_BULKRAX_FILES}" | ||
steps | ||
end.freeze | ||
UPDATE_WITH_BULK_BEHAVIOR = 'update_with_bulk_behavior' | ||
UPDATE_WITH_BULK_BEHAVIOR_STEPS = begin | ||
steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup | ||
steps[steps.index("work_resource.add_file_sets")] = "work_resource.#{Bulkrax::Transactions::Container::ADD_BULKRAX_FILES}" | ||
steps | ||
end.freeze | ||
|
||
namespace "work_resource" do |ops| | ||
ops.register CREATE_WITH_BULK_BEHAVIOR do | ||
Hyrax::Transactions::WorkCreate.new(steps: CREATE_WITH_BULK_BEHAVIOR_STEPS) | ||
end | ||
|
||
ops.register UPDATE_WITH_BULK_BEHAVIOR do | ||
Hyrax::Transactions::WorkUpdate.new(steps: UPDATE_WITH_BULK_BEHAVIOR_STEPS) | ||
end | ||
|
||
# TODO: uninitialized constant Bulkrax::Transactions::Container::InlineUploadHandler | ||
# ops.register "add_file_sets" do | ||
# Hyrax::Transactions::Steps::AddFileSets.new(handler: InlineUploadHandler) | ||
# end | ||
|
||
ops.register ADD_BULKRAX_FILES do | ||
Bulkrax::Transactions::Steps::AddFiles.new | ||
end | ||
end | ||
end | ||
end | ||
end | ||
Hyrax::Transactions::Container.merge(Bulkrax::Transactions::Container) |
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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dry/monads" | ||
|
||
module Bulkrax | ||
module Transactions | ||
module Steps | ||
class AddFiles | ||
include Dry::Monads[:result] | ||
|
||
## | ||
# @param [Class] handler | ||
def initialize(handler: Hyrax::WorkUploadsHandler) | ||
@handler = handler | ||
end | ||
|
||
## | ||
# @param [Hyrax::Work] obj | ||
# @param [Array<Fog::AWS::Storage::File>] file | ||
# @param [User] user | ||
# | ||
# @return [Dry::Monads::Result] | ||
def call(obj, files:, user:) | ||
if files && user | ||
begin | ||
files.each do |file| | ||
FileIngest.upload( | ||
content_type: file.content_type, | ||
file_body: StringIO.new(file.body), | ||
filename: Pathname.new(file.key).basename, | ||
last_modified: file.last_modified, | ||
permissions: Hyrax::AccessControlList.new(resource: obj), | ||
size: file.content_length, | ||
user: user, | ||
work: obj | ||
) | ||
end | ||
rescue => e | ||
Hyrax.logger.error(e) | ||
return Failure[:failed_to_attach_file_sets, files] | ||
end | ||
end | ||
|
||
Success(obj) | ||
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