class Libis::Ingester::DavIngestPreparer
Protected Instance Methods
process(item)
click to toggle source
# File lib/libis/ingester/tasks/dav_ingest_preparer.rb, line 38 def process(item) check_item_type ::Libis::Ingester::Run, item @dirname = parameter(:ingest_dir) raise RuntimeError, 'No location given.' unless @dirname @dirname = File.join(@dirname, item.name) debug "Preparing ingest in #{@dirname}.", item FileUtils.rmtree @dirname item.items.to_a.map { |i| process_dossier(i) } end
Private Instance Methods
process_children(item, rep, div)
click to toggle source
# File lib/libis/ingester/tasks/dav_ingest_preparer.rb, line 108 def process_children(item, rep, div) item.items.each do |child| case child when Libis::Ingester::FileItem file = process_file(child) file.representation = rep file.parent = div when Libis::Ingester::DirItem process_children(child, rep, @mets.div(label: child.name)).parent = div else # do nothing end end div end
process_dossier(item)
click to toggle source
# File lib/libis/ingester/tasks/dav_ingest_preparer.rb, line 56 def process_dossier(item) check_item_type Libis::Ingester::DavDossier, item # @dossier_dir = @dirname # Enable below to create one ingest per dossier @dossier_dir = File.join(@dirname, item.filename) FileUtils.mkdir_p File.join(@dossier_dir, 'content', 'streams') item.properties[:ingest_sub_dir] = Pathname.new(@dossier_dir).relative_path_from(Pathname.new(parameter(:ingest_dir))).to_s item.save! @mets = Libis::Tools::MetsFile.new # noinspection RubyResolve dc_record = Libis::Tools::DCRecord.new do |xml| xml[:dc].title item.name xml[:dc].identifier item.properties[:rmt_info][:folder][:referenceCode] end if item.properties[:disposition] dc_record.add 'dc:date', Date.new(item.properties[:disposition], 2, 1).rfc3339 end @mets.dc_record = dc_record.root.to_xml @mets.amd_info = { entity_type: parameter(:ie_entity_type), user_a: parameter(:user_a), user_b: parameter(:user_b), user_c: parameter(:user_c), status: parameter(:status), access_right: parameter(:access_right), retention_id: (item.properties[:disposition] ? '361540' : 'NO_RETENTION'), } rep = @mets.representation( label: 'Archiefkopie', preservation_type: 'PRESERVATION_MASTER', usage_type: 'VIEW', ) div = @mets.div label: item.name @mets.map(rep, div) process_children(item, rep, div) mets_filename = File.join(@dossier_dir, 'content', "#{item.filename}.xml") @mets.xml_doc.save mets_filename debug "Created METS file '#{mets_filename}'.", item end
process_file(item)
click to toggle source
# File lib/libis/ingester/tasks/dav_ingest_preparer.rb, line 124 def process_file(item) # copy file to stream relative_path = item.filepath file = @mets.file( label: item.name, location: relative_path, target_location: item.filelist[1..-1].join('/'), entity_type: parameter(:file_entity_type), ) target_path = File.join(@dossier_dir, 'content', 'streams', file.target) target_list = target_path.split('/')[0...-1] FileUtils.mkpath(target_list.join('/')) FileUtils.copy_entry(item.fullpath, target_path) debug "Copied file to #{target_path}.", item # noinspection RubyResolve if item.metadata_record && item.metadata_record.format == 'DC' dc = Libis::Tools::DublinCoreRecord.parse item.metadata_record.data file.dc_record = dc.root.to_xml end file end