app/controllers/concerns/show_dip.rb
# LEGACY IMPLEMENTATION
# given a dataset, find its METS.xml file, parse it and return an array containing the file names
#   and paths of all files in the DIP
LEGACY IMPLEMENTATION
given a dataset, find its METS.xml file, parse it and return an array containing the file names
and paths of all files in the DIP
LEGACY IMPLEMENTATION given a dataset find its METS . xml file parse it and return an array containing the file names and paths of all files in the DIP
def dip_directory_structure_using_fedora(dataset)
    dip_structure = {}
    if dataset.dips && !dataset.dips.empty?
      dip = dataset.aips[0]
      dip.members.each do |f|
        if f.preflabel =~ /^METS\.[-a-z0-9]{36}\.xml$/
          mets_url = f.files.first.uri.to_s
          mets_doc = Nokogiri::XML(open(mets_url))
          dip_file_ids = mets_doc.xpath("//mets:fileSec/mets:fileGrp[@USE='original']/mets:file/@ID")
          dip_file_paths = mets_doc.xpath("//mets:fileSec/mets:fileGrp[@USE='original']/mets:file/mets:FLocat/@xlink:href")
          filecounter = 0
          dip_file_ids.each do |f|
            file_id = f.to_s[/^file-(.*)$/, 1]
            file_path = dip_file_paths[filecounter].to_s.sub(/^.*?objects\/([a-z0-9]{9}\/)?/, "")
            dip_structure[file_id] = { file_path: file_path }
            filecounter += 1
          end
          break
        end
      end
      dataset.members.each do |f|
        if f.respond_to?(:preflabel)
          file_id = f.preflabel[/^([-a-z0-9]{36})/, 1]
          if dip_structure.key?(file_id)
            dip_structure[file_id][:file_uri] = f.original_file.uri.to_s
            dip_structure[file_id][:thumbnail_uri] = f.thumbnail.uri.to_s
            dip_structure[file_id][:file_path_abs] = File.join(ENV['DIP_LOCATION'], dip.dip_current_path, "objects", f.preflabel)
          end
        end
      end
      dip_structure.sort_by { |file_id, file_details| file_details[:file_path].downcase }.to_h
    end
    dip_structure
  rescue => e
    handle_exception(e, "Unable to present DIP files for download, failed to parse METS.xml",
                     "Given dataset: " + dataset.id, true)
    return {}
  end
def dip_directory_structure_using_fedora ( dataset ) dip_structure = { } if dataset . dips && ! dataset . dips . empty? dip = dataset . aips [ 0 ] dip . members . each do | f | if f . preflabel =~ / ^METS \. [-a-z0-9]{36} \. xml$ / mets_url = f . files . first . uri . to_s mets_doc = Nokogiri :: XML ( open ( mets_url ) ) dip_file_ids = mets_doc . xpath ( "//mets:fileSec/mets:fileGrp[@USE='original']/mets:file/@ID" ) dip_file_paths = mets_doc . xpath ( "//mets:fileSec/mets:fileGrp[@USE='original']/mets:file/mets:FLocat/@xlink:href" ) filecounter = 0 dip_file_ids . each do | f | file_id = f . to_s [ / ^file-(.*)$ / , 1 ] file_path = dip_file_paths [ filecounter ] . to_s . sub ( / ^.*?objects \/ ([a-z0-9]{9} \/ )? / , "" ) dip_structure [ file_id ] = { file_path : file_path } filecounter += 1 end break end end dataset . members . each do | f | if f . respond_to? ( :preflabel ) file_id = f . preflabel [ / ^([-a-z0-9]{36}) / , 1 ] if dip_structure . key? ( file_id ) dip_structure [ file_id ] [ :file_uri ] = f . original_file . uri . to_s dip_structure [ file_id ] [ :thumbnail_uri ] = f . thumbnail . uri . to_s dip_structure [ file_id ] [ :file_path_abs ] = File . join ( ENV [ 'DIP_LOCATION' ] , dip . dip_current_path , "objects" , f . preflabel ) end end end dip_structure . sort_by { | file_id , file_details | file_details [ :file_path ] . downcase } . to_h end dip_structure rescue => e handle_exception ( e , "Unable to present DIP files for download, failed to parse METS.xml" , "Given dataset: " + dataset . id , true ) return { } end
LEGACY IMPLEMENTATION
given a dataset, find its METS.xml file, parse it and return an array containing the file names
and paths of all files in the DIP
LEGACY IMPLEMENTATION given a dataset find its METS . xml file parse it and return an array containing the file names and paths of all files in the DIP
# set up the return variable # if the dataset has a dip with downloadable files # get the dip from the dataset # loop through the DIP files until we find the METS.xml one # get Nokogiri to parse it # get the file ID of every file in the DIP package # get the file path of every file in the DIP package # for each file # get the file id as a string (need to parse out the "file-" prefix) # get the file path/name (parse out everything in the path before the DIP package id) # add these to the return array # no need to continue looping now that we've dealt with METS.xml # now loop over the Dataset files using the file id to find the uri of the stored file and add that #   to the return structure # get the file id of this stored file # the original file is in f.original_file - if it has a thumbnail, that's in f.thumbnail # sort the resulting dip structure by file path
dataset
<not_specific>