Class: Hyrax::Transactions::Steps::AddFileSets

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/add_file_sets.rb

Overview

Adds a Hyrax::FileSet

Instance Method Summary collapse

Constructor Details

#initialize(handler: Hyrax::WorkUploadsHandler) ⇒ AddFileSets

Returns a new instance of AddFileSets.

Parameters:

  • handler (Class) (defaults to: Hyrax::WorkUploadsHandler)

Since:

  • 2.4.0



16
17
18
# File 'lib/hyrax/transactions/steps/add_file_sets.rb', line 16

def initialize(handler: Hyrax::WorkUploadsHandler)
  @handler = handler
end

Instance Method Details

#call(obj, uploaded_files: [], file_set_params: []) ⇒ Dry::Monads::Result

Parameters:

  • obj (Hyrax::Work)
  • uploaded_files (Enumerable<UploadedFile>) (defaults to: [])
  • file_set_params (Enumerable<Hash>) (defaults to: [])

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hyrax/transactions/steps/add_file_sets.rb', line 26

def call(obj, uploaded_files: [], file_set_params: [])
  if @handler.new(work: obj).add(files: uploaded_files, file_set_params: file_set_params).attach
    file_sets = obj.member_ids.map do |member|
      Hyrax.query_service.find_by(id: member) if Hyrax.query_service.find_by(id: member).is_a? Hyrax::FileSet
    end

    Hyrax::LeaseManager.create_or_update_lease_on_members(file_sets, obj) if obj.lease
    Hyrax::EmbargoManager.create_or_update_embargo_on_members(file_sets, obj) if obj.embargo
    Success(obj)
  else
    Failure[:failed_to_attach_file_sets, uploaded_files]
  end
end