Class: Wings::Works::AddFileToFileSet

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/hydra/works/services/add_file_to_file_set.rb

Class Method Summary collapse

Class Method Details

.call(file_set:, file:, type:, update_existing: true, versioning: true) ⇒ Object

Adds a file to the file_set

Parameters:

  • file_set (Valkyrie::Resource)

    adding file to this file set

  • file (IO, File, Rack::Multipart::UploadedFile, #read)

    the object that will be the contents. If file responds to :mime_type, :content_type, :original_name, or :original_filename, those will be called to provide metadata.

  • type (RDF::URI or String)

    URI for the RDF.type that identifies the file's role within the file_set

  • update_existing (Boolean) (defaults to: true)

    whether to update an existing file if there is one. When set to true, performs a create_or_update. When set to false, always creates a new file within file_set.files.

  • versioning (Boolean) (defaults to: true)

    whether to create new version entries (only applicable if type corresponds to a versionable file)

Raises:

  • (ArgumentError)

14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wings/hydra/works/services/add_file_to_file_set.rb', line 14

def call(file_set:, file:, type:, update_existing: true, versioning: true)
  raise ArgumentError, 'supplied object must be an instance of Valkyrie::Resource' unless file_set.is_a?(Valkyrie::Resource) && file_set.file_set?
  raise ArgumentError, 'supplied file must respond to read' unless file.respond_to? :read

  af_type = normalize_type(type)
  raise ArgumentError, "supplied type (#{type}) is not supported" if af_type.blank?

  af_file_set = Wings::ActiveFedoraConverter.new(resource: file_set).convert
  result = Hydra::Works::AddFileToFileSet.call(af_file_set, file, af_type, update_existing: update_existing, versioning: versioning)

  # TODO: model_transformer/file_converter_service should create FileMetadata and set ids and attributes
  result ? af_file_set.valkyrie_resource : false
end