class Hydra::Works::AddFileToFileSet

Public Class Methods

call(file_set, file, type, update_existing: true, versioning: true) click to toggle source

Adds a file to the file_set @param [Hydra::PCDM::FileSet] file_set the file will be added to @param [IO,File,Rack::Multipart::UploadedFile, read] file 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. @param [RDF::URI or String] type URI for the RDF.type that identifies the file's role within the file_set @param [Boolean] update_existing 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. @param [Boolean] versioning whether to create new version entries (only applicable if type corresponds to a versionable file)

# File lib/hydra/works/services/add_file_to_file_set.rb, line 10
def self.call(file_set, file, type, update_existing: true, versioning: true)
  fail ArgumentError, 'supplied object must be a file set' unless file_set.file_set?
  fail ArgumentError, 'supplied file must respond to read' unless file.respond_to? :read

  # TODO: required as a workaround for https://github.com/samvera/active_fedora/pull/858
  file_set.save unless file_set.persisted?

  updater_class = versioning ? VersioningUpdater : Updater
  updater = updater_class.new(file_set, type, update_existing)
  status = updater.update(file)
  status ? file_set : false
end