app/models/bplmodels/institution.rb
def curator_export_manifest(path_to_csv = nil, collection_pids = nil)
      puts "Creating export manifest, this may take a minute..."
      path_to_csv ||= BPL_CONFIG_GLOBAL['export_reports_location']
      data_for_csv = []
      data_for_csv << %w(curator_model ark_id attachment_type parent_ark_id file_name_base)
      data_for_csv << ['Institution', pid, '', '', '']

      col_pids = collection_pids || collections.map(&:pid)
      col_pids.each do |col_pid|
        data_for_csv << ['Collection', col_pid, '', '', '']
      end

      col_obj_pids = []
      col_pids.each do |col_pid|
        Bplmodels::ObjectBase.find_in_batches("administrative_set_ssim" => "info:fedora/#{col_pid}") do |batch|
          batch.each { |doc| col_obj_pids << doc['id'] }
        end
      end

      col_obj_pids.each do |obj_pid|
        obj = Bplmodels::ObjectBase.find(obj_pid).adapt_to_cmodel
        data_for_csv << ['DigitalObject', obj.pid, '', '', '']
        filesets = obj.filesets_for_export
        filesets.each do |fileset|
          fs_hash = fileset.fetch(:file_set)
          fs_ark_id = fs_hash.fetch(:ark_id, '')

          fs_parent_ark_id = fs_hash.fetch(:file_set_of).fetch(:ark_id)
          fs_fn_base = fs_hash.fetch(:file_name_base)
          data_for_csv << ["Filestreams::#{fs_hash.fetch(:file_set_type).capitalize}", fs_ark_id, '',
                           fs_parent_ark_id, fs_fn_base]
          # have to check if [:files] is set; #filesets_for_export doesn't return all the data we need
          if fs_hash.fetch(:files, nil).blank?
            f = Bplmodels::File.find(fs_hash.fetch(:ark_id))
            file_set_type = f.class.to_s.split("::").last.match(/[A-Z][a-z]*/).to_s.downcase
            fs_hash[:files] = f.export_filestreams_for_curator_api(file_set_type)
          end
          fs_hash.fetch(:files).each do |f_hash|
            data_for_csv << ["ActiveStorage::Attachment", fs_ark_id, f_hash.fetch(:file_type),
                             fs_parent_ark_id, fs_fn_base]
          end
        end
      end

      csv_fullpath = "#{path_to_csv}/#{name_abbreviation}_#{pid.gsub(/\:/, '_')}_export-manifest_#{Time.zone.now.strftime('%Y-%m-%d')}.csv"
      CSV.open(csv_fullpath, 'w') do |csv_obj|
        data_for_csv.each { |v| csv_obj << v }
      end
      puts "Export manifest created: #{csv_fullpath}"
    end
# create export manifest CSV, to be verified after migration
# CSV contains object class and ark id for all collections, objects, filesets, attachments
create export manifest CSV, to be verified after migration
CSV contains object class and ark id for all collections, objects, filesets, attachments
create export manifest CSV to be verified after migration CSV contains object class and ark id for all collections objects filesets attachments
def curator_export_manifest(path_to_csv = nil, collection_pids = nil)
      puts "Creating export manifest, this may take a minute..."
      path_to_csv ||= BPL_CONFIG_GLOBAL['export_reports_location']
      data_for_csv = []
      data_for_csv << %w(curator_model ark_id attachment_type parent_ark_id file_name_base)
      data_for_csv << ['Institution', pid, '', '', '']
      col_pids = collection_pids || collections.map(&:pid)
      col_pids.each do |col_pid|
        data_for_csv << ['Collection', col_pid, '', '', '']
      end
      col_obj_pids = []
      col_pids.each do |col_pid|
        Bplmodels::ObjectBase.find_in_batches("administrative_set_ssim" => "info:fedora/#{col_pid}") do |batch|
          batch.each { |doc| col_obj_pids << doc['id'] }
        end
      end
      col_obj_pids.each do |obj_pid|
        obj = Bplmodels::ObjectBase.find(obj_pid).adapt_to_cmodel
        data_for_csv << ['DigitalObject', obj.pid, '', '', '']
        filesets = obj.filesets_for_export
        filesets.each do |fileset|
          fs_hash = fileset.fetch(:file_set)
          fs_ark_id = fs_hash.fetch(:ark_id, '')
          fs_parent_ark_id = fs_hash.fetch(:file_set_of).fetch(:ark_id)
          fs_fn_base = fs_hash.fetch(:file_name_base)
          data_for_csv << ["Filestreams::#{fs_hash.fetch(:file_set_type).capitalize}", fs_ark_id, '',
                           fs_parent_ark_id, fs_fn_base]
          if fs_hash.fetch(:files, nil).blank?
            f = Bplmodels::File.find(fs_hash.fetch(:ark_id))
            file_set_type = f.class.to_s.split("::").last.match(/[A-Z][a-z]*/).to_s.downcase
            fs_hash[:files] = f.export_filestreams_for_curator_api(file_set_type)
          end
          fs_hash.fetch(:files).each do |f_hash|
            data_for_csv << ["ActiveStorage::Attachment", fs_ark_id, f_hash.fetch(:file_type),
                             fs_parent_ark_id, fs_fn_base]
          end
        end
      end
      csv_fullpath = "#{path_to_csv}/#{name_abbreviation}_#{pid.gsub(/\:/, '_')}_export-manifest_#{Time.zone.now.strftime('%Y-%m-%d')}.csv"
      CSV.open(csv_fullpath, 'w') do |csv_obj|
        data_for_csv.each { |v| csv_obj << v }
      end
      puts "Export manifest created: #{csv_fullpath}"
    end
def curator_export_manifest ( path_to_csv = nil , collection_pids = nil ) puts "Creating export manifest, this may take a minute..." path_to_csv ||= BPL_CONFIG_GLOBAL [ 'export_reports_location' ] data_for_csv = [ ] data_for_csv << %w( curator_model ark_id attachment_type parent_ark_id file_name_base ) data_for_csv << [ 'Institution' , pid , '' , '' , '' ] col_pids = collection_pids || collections . map ( & :pid ) col_pids . each do | col_pid | data_for_csv << [ 'Collection' , col_pid , '' , '' , '' ] end col_obj_pids = [ ] col_pids . each do | col_pid | Bplmodels :: ObjectBase . find_in_batches ( "administrative_set_ssim" => "info:fedora/#{col_pid}" ) do | batch | batch . each { | doc | col_obj_pids << doc [ 'id' ] } end end col_obj_pids . each do | obj_pid | obj = Bplmodels :: ObjectBase . find ( obj_pid ) . adapt_to_cmodel data_for_csv << [ 'DigitalObject' , obj . pid , '' , '' , '' ] filesets = obj . filesets_for_export filesets . each do | fileset | fs_hash = fileset . fetch ( :file_set ) fs_ark_id = fs_hash . fetch ( :ark_id , '' ) fs_parent_ark_id = fs_hash . fetch ( :file_set_of ) . fetch ( :ark_id ) fs_fn_base = fs_hash . fetch ( :file_name_base ) data_for_csv << [ "Filestreams::#{fs_hash.fetch(:file_set_type).capitalize}" , fs_ark_id , '' , fs_parent_ark_id , fs_fn_base ] if fs_hash . fetch ( :files , nil ) . blank? f = Bplmodels :: File . find ( fs_hash . fetch ( :ark_id ) ) file_set_type = f . class . to_s . split ( "::" ) . last . match ( / [A-Z][a-z]* / ) . to_s . downcase fs_hash [ :files ] = f . export_filestreams_for_curator_api ( file_set_type ) end fs_hash . fetch ( :files ) . each do | f_hash | data_for_csv << [ "ActiveStorage::Attachment" , fs_ark_id , f_hash . fetch ( :file_type ) , fs_parent_ark_id , fs_fn_base ] end end end csv_fullpath = "#{path_to_csv}/#{name_abbreviation}_#{pid.gsub(/\:/, '_')}_export-manifest_#{Time.zone.now.strftime('%Y-%m-%d')}.csv" CSV . open ( csv_fullpath , 'w' ) do | csv_obj | data_for_csv . each { | v | csv_obj << v } end puts "Export manifest created: #{csv_fullpath}" end
create export manifest CSV, to be verified after migration
CSV contains object class and ark id for all collections, objects, filesets, attachments
create export manifest CSV to be verified after migration CSV contains object class and ark id for all collections objects filesets attachments
# have to check if [:files] is set; #filesets_for_export doesn't return all the data we need
path_to_csv
collection_pids