Class: CurationConcerns::WorkingDirectory

Inherits:
Object
  • Object
show all
Defined in:
app/services/curation_concerns/working_directory.rb

Class Method Summary collapse

Class Method Details

.copy_file_to_working_directory(file, id) ⇒ String

Returns path of the working file.

Parameters:

  • file (File, ActionDispatch::Http::UploadedFile)
  • id (String)

    the identifier of the FileSet

Returns:

  • (String)

    path of the working file



22
23
24
25
# File 'app/services/curation_concerns/working_directory.rb', line 22

def copy_file_to_working_directory(file, id)
  file_name = file.respond_to?(:original_filename) ? file.original_filename : ::File.basename(file)
  copy_stream_to_working_directory(id, file_name, file)
end

.copy_repository_resource_to_working_directory(file, id) ⇒ String

Returns path of the working file.

Parameters:

  • file (ActiveFedora::File)

    the resource in the repo

  • id (String)

    the identifier of the FileSet

Returns:

  • (String)

    path of the working file



30
31
32
33
34
# File 'app/services/curation_concerns/working_directory.rb', line 30

def copy_repository_resource_to_working_directory(file, id)
  Rails.logger.debug "Loading #{file.original_name} (#{file.id}) from the repository to the working directory"
  # TODO: this causes a load into memory, which we'd like to avoid
  copy_stream_to_working_directory(id, file.original_name, StringIO.new(file.content))
end

.find_or_retrieve(repository_file_id, id, filepath = nil) ⇒ String

Returns path of the working file.

Parameters:

  • repository_file_id (String)

    identifier for Hydra::PCDM::File

  • id (String)

    the identifier of the FileSet

  • filepath (String, NilClass) (defaults to: nil)

    path to existing cached copy of the file

Returns:

  • (String)

    path of the working file



8
9
10
11
12
13
14
15
16
17
# File 'app/services/curation_concerns/working_directory.rb', line 8

def find_or_retrieve(repository_file_id, id, filepath = nil)
  return filepath if filepath && File.exist?(filepath)
  repository_file = Hydra::PCDM::File.find(repository_file_id)
  working_path = full_filename(id, repository_file.original_name)
  if File.exist?(working_path)
    Rails.logger.debug "#{repository_file.original_name} already exists in the working directory at #{working_path}"
    return working_path
  end
  copy_repository_resource_to_working_directory(repository_file, id)
end