app/models/proquest_behaviors.rb
# Export a zipped directory of an ETD in the format expected by ProQuest
# @return [String] the full path of the exported .zip file
Export a zipped directory of an ETD in the format expected by ProQuest
Export a zipped directory of an ETD in the format expected by ProQuest
def export_zipped_proquest_package
    FileUtils.mkdir_p export_directory
    output_file = "#{@export_directory}/#{upload_file_id}.zip"
    File.delete(output_file) if File.file? output_file
    Zip::File.open(output_file, Zip::File::CREATE) do |zip|
      zip.dir.mkdir(upload_file_id)
      zip.file.open("#{upload_file_id}/#{xml_filename}", 'w') { |file| file.write(export_proquest_xml) }
      zip.file.open("#{upload_file_id}/#{export_id}.pdf", "wb") do |saved_file|
        open(primary_pdf_file.uri, "rb") do |read_file|
          saved_file.write(read_file.read)
        end
        raise "Primary file not exported" unless File.file? saved_file
      end
      zip.dir.mkdir("#{upload_file_id}/#{supplemental_files_directory}")
      supplemental_files_fs.each do |fs|
        zip.file.open("#{upload_file_id}/#{supplemental_files_directory}/#{fs.label}", "wb") do |saved_file|
          open(fs.files.first.uri, "rb") do |read_file|
            saved_file.write(read_file.read)
          end
          raise "Supplemental file not exported" unless File.file? saved_file
        end
      end
    end
    Rails.logger.info "ProQuest package created: #{output_file}"
    output_file
  end
def export_zipped_proquest_package FileUtils . mkdir_p export_directory output_file = "#{@export_directory}/#{upload_file_id}.zip" File . delete ( output_file ) if File . file? output_file Zip :: File . open ( output_file , Zip :: File :: CREATE ) do | zip | zip . dir . mkdir ( upload_file_id ) zip . file . open ( "#{upload_file_id}/#{xml_filename}" , 'w' ) { | file | file . write ( export_proquest_xml ) } zip . file . open ( "#{upload_file_id}/#{export_id}.pdf" , "wb" ) do | saved_file | open ( primary_pdf_file . uri , "rb" ) do | read_file | saved_file . write ( read_file . read ) end raise "Primary file not exported" unless File . file? saved_file end zip . dir . mkdir ( "#{upload_file_id}/#{supplemental_files_directory}" ) supplemental_files_fs . each do | fs | zip . file . open ( "#{upload_file_id}/#{supplemental_files_directory}/#{fs.label}" , "wb" ) do | saved_file | open ( fs . files . first . uri , "rb" ) do | read_file | saved_file . write ( read_file . read ) end raise "Supplemental file not exported" unless File . file? saved_file end end end Rails . logger . info "ProQuest package created: #{output_file}" output_file end
Export a zipped directory of an ETD in the format expected by ProQuest
Export a zipped directory of an ETD in the format expected by ProQuest
# The primary thesis file goes in the main directory # Any supplemental files go into a subdirectory called lastname_firstname_Media
the full path of the exported .zip file
the full path of the exported . zip file
String