Class: PushmiPullyu::AIP::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/pushmi_pullyu/aip/downloader.rb

Overview

Download all of the metadata/datastreams and associated data related to an object

Defined Under Namespace

Classes: NoContentFilename, NoFileSets, NoMemberFiles, NoOriginalFile

Constant Summary collapse

PREDICATE_URIS =
{
  filename: 'http://purl.org/dc/terms/title',
  member_files: 'http://pcdm.org/models#hasFile',
  member_file_sets: 'http://pcdm.org/models#hasMember',
  original_file: 'http://pcdm.org/use#OriginalFile',
  type: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(noid, aip_directory) ⇒ Downloader

Returns a new instance of Downloader.


23
24
25
26
# File 'lib/pushmi_pullyu/aip/downloader.rb', line 23

def initialize(noid, aip_directory)
  @noid = noid
  @aip_directory = aip_directory
end

Instance Method Details

#runObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pushmi_pullyu/aip/downloader.rb', line 28

def run
  make_directories

  PushmiPullyu.logger.info("#{@noid}: Retreiving data from Fedora ...")

  # Main object metadata
  object_downloader = PushmiPullyu::AIP::FedoraFetcher.new(@noid)
  download_and_log(object_aip_paths[:main_object], object_downloader)

  # Construct the file ordering file
  list_source_uri = object_downloader.object_url + object_aip_paths.list_source.remote
  create_and_log_file_order_list(list_source_uri)

  member_file_set_uuids.each do |file_set_uuid|
    make_file_set_directories(file_set_uuid)

    # FileSet metadata
    file_set_downloader = PushmiPullyu::AIP::FedoraFetcher.new(file_set_uuid)
    path_spec = file_set_aip_paths(file_set_uuid)[:main_object]
    download_and_log(path_spec, file_set_downloader)

    # Find the original file by looping through the files in the file_set
    original_file_remote_base = nil
    member_files(file_set_uuid).each do |file_path|
      path_spec = OpenStruct.new(
        remote: "/files/#{file_path}/fcr:metadata",
        # Note: local file gets clobbered on each download until it finds the right one
        local: "#{file_set_dirs(file_set_uuid).}/original_file_metadata.n3",
        optional: true
      )
      download_and_log(path_spec, file_set_downloader)
      if original_file?(path_spec.local)
        original_file_remote_base = "/files/#{file_path}"
        break
      end
    end

    raise NoOriginalFile unless original_file_remote_base.present?

    [:content, :fixity].each do |item|
      path_spec = file_aip_paths(file_set_uuid, original_file_remote_base)[item]
      download_and_log(path_spec, file_set_downloader)
    end
  end
end