Class: CurationConcerns::PersistDirectlyContainedOutputFileService

Inherits:
Hydra::Derivatives::PersistBasicContainedOutputFileService
  • Object
show all
Defined in:
app/services/curation_concerns/persist_directly_contained_output_file_service.rb

Overview

This Service is an implementation of the Hydra::Derivatives::PersistOutputFileService It supports directly contained files

Class Method Summary collapse

Class Method Details

.call(stream, directives) ⇒ Object

This method conforms to the signature of the .call method on Hydra::Derivatives::PersistOutputFileService

  • Persists the file within the DirectContainer specified by :container

Parameters:

  • stream (#read)

    the data to be persisted

  • directives (Hash)

    directions which can be used to determine where to persist to.

Options Hash (directives):

  • url (String)

    URI for the parent object.

  • container (String)

    Name of the container association.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/curation_concerns/persist_directly_contained_output_file_service.rb', line 12

def self.call(stream, directives)
  file = Hydra::Derivatives::IoDecorator.new(stream, new_mime_type(directives.fetch(:format)))
  o_name = determine_original_name(file)
  m_type = determine_mime_type(file)
  uri = URI(directives.fetch(:url))
  raise ArgumentError, "#{uri} is not an http uri" unless uri.scheme == 'http'
  file_set = ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri.to_s))
  remote_file = file_set.send("build_#{directives.fetch(:container)}".to_sym)
  remote_file.content = file
  remote_file.mime_type = m_type
  remote_file.original_name = o_name
  file_set.save
end