app/models/concerns/bplmodels/digital_object_export.rb
def filesets_for_export(include_files = true)
        filesets = []
        has_ereader_files = false
        # get file-level filesets (image, document, video, etc); remove ereader (do 'em separately)
        all_files = Bplmodels::Finder.getFiles(pid)
        all_files.delete(:ereader)
        ## all_files.delete(:images) # uncomment for easier testing of IA objects
        all_files.each_value do |files_array|
          filesets.concat filesets_for_files(files_array, false)
        end
        # get EReader filesets and combine, make EPub the 'primary'
        ereader_files = Bplmodels::Finder.getEreaderFiles(pid)
        if ereader_files.present?
          has_ereader_files = true
          ereader_fileset_for_export = nil
          if include_files
            ereader_filesets = filesets_for_files(ereader_files, include_files)
            ereader_filesets.each_with_index do |er_fileset, index|
              if er_fileset[:file_set][:files][0][:content_type] == 'application/epub+zip'
                ereader_fileset_for_export = er_fileset
                ereader_filesets.delete_at(index)
              end
            end
            ereader_filesets.each do |er_fileset|
              er_fileset[:file_set][:files].each do |er_file|
                next unless er_file[:file_type].match?(/ebook_access/)

                ereader_fileset_for_export[:file_set][:files] << er_file
              end
            end
          else
            ereader_files = ereader_files.select { |erf| erf["mime_type_tesim"].include?("application/epub+zip") }
            if ereader_files.present?
              ereader_fileset_obj = Bplmodels::File.find(ereader_files.first['id'])
              ereader_fileset_for_export = ereader_fileset_obj.export_data_for_curator_api(include_files)
            end
          end
          filesets << ereader_fileset_for_export
        end
        # have to modify keys of ebook_access_mobi and ebook_access_daisy files to use epub pid
        if has_ereader_files
          filesets.each do |fs|
            fileset = fs[:file_set]
            next unless fileset[:file_set_type] == 'ereader'

            pid_for_key = fileset[:ark_id]
            fileset[:files].each do |file|
              if file[:file_type] == 'ebook_access_daisy' || file[:file_type] == 'ebook_access_mobi'
                key_parts = file[:key].split('/')
                key_parts[1] = pid_for_key if key_parts[1].match?(/[\w-]*:[0-9a-z]*/)
                file[:key] = key_parts.join('/')
              end
            end
          end
        end
        # get the object-level filesets (metadata, plainText, etc)
        object_filesets = object_filesets_for_export(object_filestreams_for_export)
        filesets + object_filesets
      end
# the object returned is too large in certain cases (items with 900+ pages)
# so we don't include all the file/attachment data for "normal" (non-Ereader) Bplmodels::File objects
# upstream methods will have to call #export_data_for_curator_api(true) to get
# the export has with files included.
the object returned is too large in certain cases (items with 900+ pages)
so we don't include all the file/attachment data for "normal" (non-Ereader) Bplmodels::File objects
upstream methods will have to call #export_data_for_curator_api(true) to get
the export has with files included.
the object returned is too large in certain cases ( items with 900 + pages ) so we don ' t include all the file / attachment data for " normal " ( non - Ereader ) Bplmodels :: File objects upstream methods will have to call #export_data_for_curator_api ( true ) to get the export has with files included .
def filesets_for_export(include_files = true)
        filesets = []
        has_ereader_files = false
        all_files = Bplmodels::Finder.getFiles(pid)
        all_files.delete(:ereader)
        all_files.each_value do |files_array|
          filesets.concat filesets_for_files(files_array, false)
        end
        ereader_files = Bplmodels::Finder.getEreaderFiles(pid)
        if ereader_files.present?
          has_ereader_files = true
          ereader_fileset_for_export = nil
          if include_files
            ereader_filesets = filesets_for_files(ereader_files, include_files)
            ereader_filesets.each_with_index do |er_fileset, index|
              if er_fileset[:file_set][:files][0][:content_type] == 'application/epub+zip'
                ereader_fileset_for_export = er_fileset
                ereader_filesets.delete_at(index)
              end
            end
            ereader_filesets.each do |er_fileset|
              er_fileset[:file_set][:files].each do |er_file|
                next unless er_file[:file_type].match?(/ebook_access/)
                ereader_fileset_for_export[:file_set][:files] << er_file
              end
            end
          else
            ereader_files = ereader_files.select { |erf| erf["mime_type_tesim"].include?("application/epub+zip") }
            if ereader_files.present?
              ereader_fileset_obj = Bplmodels::File.find(ereader_files.first['id'])
              ereader_fileset_for_export = ereader_fileset_obj.export_data_for_curator_api(include_files)
            end
          end
          filesets << ereader_fileset_for_export
        end
        if has_ereader_files
          filesets.each do |fs|
            fileset = fs[:file_set]
            next unless fileset[:file_set_type] == 'ereader'
            pid_for_key = fileset[:ark_id]
            fileset[:files].each do |file|
              if file[:file_type] == 'ebook_access_daisy' || file[:file_type] == 'ebook_access_mobi'
                key_parts = file[:key].split('/')
                key_parts[1] = pid_for_key if key_parts[1].match?(/[\w-]*:[0-9a-z]*/)
                file[:key] = key_parts.join('/')
              end
            end
          end
        end
        object_filesets = object_filesets_for_export(object_filestreams_for_export)
        filesets + object_filesets
      end
def filesets_for_export ( include_files = true ) filesets = [ ] has_ereader_files = false all_files = Bplmodels :: Finder . getFiles ( pid ) all_files . delete ( :ereader ) all_files . each_value do | files_array | filesets . concat filesets_for_files ( files_array , false ) end ereader_files = Bplmodels :: Finder . getEreaderFiles ( pid ) if ereader_files . present? has_ereader_files = true ereader_fileset_for_export = nil if include_files ereader_filesets = filesets_for_files ( ereader_files , include_files ) ereader_filesets . each_with_index do | er_fileset , index | if er_fileset [ :file_set ] [ :files ] [ 0 ] [ :content_type ] == 'application/epub+zip' ereader_fileset_for_export = er_fileset ereader_filesets . delete_at ( index ) end end ereader_filesets . each do | er_fileset | er_fileset [ :file_set ] [ :files ] . each do | er_file | next unless er_file [ :file_type ] . match? ( / ebook_access / ) ereader_fileset_for_export [ :file_set ] [ :files ] << er_file end end else ereader_files = ereader_files . select { | erf | erf [ "mime_type_tesim" ] . include? ( "application/epub+zip" ) } if ereader_files . present? ereader_fileset_obj = Bplmodels :: File . find ( ereader_files . first [ 'id' ] ) ereader_fileset_for_export = ereader_fileset_obj . export_data_for_curator_api ( include_files ) end end filesets << ereader_fileset_for_export end if has_ereader_files filesets . each do | fs | fileset = fs [ :file_set ] next unless fileset [ :file_set_type ] == 'ereader' pid_for_key = fileset [ :ark_id ] fileset [ :files ] . each do | file | if file [ :file_type ] == 'ebook_access_daisy' || file [ :file_type ] == 'ebook_access_mobi' key_parts = file [ :key ] . split ( '/' ) key_parts [ 1 ] = pid_for_key if key_parts [ 1 ] . match? ( / [ \w -]*:[0-9a-z]* / ) file [ :key ] = key_parts . join ( '/' ) end end end end object_filesets = object_filesets_for_export ( object_filestreams_for_export ) filesets + object_filesets end
the object returned is too large in certain cases (items with 900+ pages)
so we don't include all the file/attachment data for "normal" (non-Ereader) Bplmodels::File objects
upstream methods will have to call #export_data_for_curator_api(true) to get
the export has with files included.
the object returned is too large in certain cases ( items with 900 + pages ) so we don ' t include all the file / attachment data for " normal " ( non - Ereader ) Bplmodels :: File objects upstream methods will have to call #export_data_for_curator_api ( true ) to get the export has with files included .
# get file-level filesets (image, document, video, etc); remove ereader (do 'em separately) ## all_files.delete(:images) # uncomment for easier testing of IA objects # get EReader filesets and combine, make EPub the 'primary' # have to modify keys of ebook_access_mobi and ebook_access_daisy files to use epub pid # get the object-level filesets (metadata, plainText, etc)
include_files