Sha256: d31ed3e1dac84ec40ddc008ef35a1d2d31cd1801da0ff615223af1136d4483a4

Contents?: true

Size: 909 Bytes

Versions: 2

Compression:

Stored size: 909 Bytes

Contents

module FedoraMigrate::DatastreamVerification
  
  attr_accessor :datastream

  def valid? datastream=nil
    @datastream = datastream || @source
    has_matching_checksums? || has_matching_nokogiri_checksums?
  end

  def has_matching_checksums?
    datastream.checksum == target_checksum || checksum(datastream.content) == target_checksum
  end

  def has_matching_nokogiri_checksums?
    return false unless datastream.mimeType == "text/xml"
    checksum(Nokogiri::XML(datastream.content).to_xml) == checksum(Nokogiri::XML(target_content).to_xml)
  end

  private 

  def target_checksum
    target.digest.first.to_s.split(/:/).last
  end

  # In some cases, the data is in ldp_source but target.content is empty, so we check both places
  def target_content
    target.content.empty? ? target.ldp_source.content : target.content
  end

  def checksum content
    Digest::SHA1.hexdigest(content)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fedora-migrate-0.3.0 lib/fedora_migrate/datastream_verification.rb
fedora-migrate-0.2.0 lib/fedora_migrate/datastream_verification.rb