class Hydra::Works::AddExternalFileToFileSet
Public Class Methods
call(file_set, external_file_url, type, opts = {})
click to toggle source
Adds a file to the file_set @param [Hydra::PCDM::FileSet] file_set the file will be added to @param [String] external_file_url URL representing the externally stored file @param [RDF::URI or String] type URI for the RDF.type that identifies the file's role within the file_set @param [Hash] opts Options @option opts [Boolean] :update_existing When set to true, performs a create_or_update. When set to false, always creates a new file within file_set.files. @option opts [Boolean] :versioning Whether to create new version entries (only applicable if type
corresponds to a versionable file) @option opts [String] :filename A string for the original file name. Defaults to the same value as external_file_url
# File lib/hydra/works/services/add_external_file_to_file_set.rb, line 11 def self.call(file_set, external_file_url, type, opts = {}) fail ArgumentError, 'supplied object must be a file set' unless file_set.file_set? update_existing = opts.fetch(:update_existing, true) versioning = opts.fetch(:versioning, true) filename = opts.fetch(:filename, external_file_url) # 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(external_file_url, filename) status ? file_set : false end