class ActiveFedora::FixityService

Attributes

target[RW]

Public Class Methods

new(target) click to toggle source

@param [String, RDF::URI] target url for a Fedora resource.

# File lib/active_fedora/fixity_service.rb, line 8
def initialize(target)
  raise ArgumentError, 'You must provide a uri' unless target
  @target = target.to_s
end

Public Instance Methods

check() click to toggle source

For backwards compat, check always insists on doing a new request. you might want verified? instead which uses a cached request. @return true or false

# File lib/active_fedora/fixity_service.rb, line 20
def check
  @response = nil
  verified?
end
expected_message_digest() click to toggle source

the currently calculated checksum, as a string URI, like “urn:sha1:09a848b79f86f3a4f3f301b8baafde455d6f8e0e”

# File lib/active_fedora/fixity_service.rb, line 40
def expected_message_digest
  fixity_graph.query({ predicate: ::RDF::Vocab::PREMIS.hasMessageDigest }).first.try(:object).try(:to_s)
end
expected_size() click to toggle source

integer, as reported by fedora. bytes maybe?

# File lib/active_fedora/fixity_service.rb, line 45
def expected_size
  fixity_graph.query({ predicate: ::RDF::Vocab::PREMIS.hasSize }).first.try(:object).try(:to_s).try(:to_i)
end
response() click to toggle source
# File lib/active_fedora/fixity_service.rb, line 13
def response
  @response ||= fixity_response_from_fedora
end
response_graph() click to toggle source

Fedora response as an ::RDF::Graph object. Public API, so consumers can do with it what they will, especially if future fedora versions add more things to it.

# File lib/active_fedora/fixity_service.rb, line 52
def response_graph
  fixity_graph
end
status() click to toggle source

An array of 1 or more literals reported by Fedora. See ‘success’ for which one indicates fixity check is good.

# File lib/active_fedora/fixity_service.rb, line 33
def status
  fixity_graph.query({ predicate: premis_status_predicate }).map(&:object) +
    fixity_graph.query({ predicate: fedora_status_predicate }).map(&:object)
end
verified?() click to toggle source

Executes a fixity check on Fedora @return true or false

# File lib/active_fedora/fixity_service.rb, line 27
def verified?
  status.include?(success)
end

Private Instance Methods

encoded_url(uri) click to toggle source

See jira.duraspace.org/browse/FCREPO-1247 @param [String] uri

# File lib/active_fedora/fixity_service.rb, line 85
def encoded_url(uri)
  if /fcr:versions/.match?(uri)
    uri.gsub(/fcr:versions/, "fcr%3aversions")
  else
    uri
  end
end
fedora_status_predicate() click to toggle source

Fcrepo4.status was used by Fedora < 4.3, but it was removed from the 2015-07-24 version of the fedora 4 ontology fedora.info/definitions/v4/2015/07/24/repository and from rdf-vocab in version 0.8.5

# File lib/active_fedora/fixity_service.rb, line 66
def fedora_status_predicate
  ::RDF::URI("http://fedora.info/definitions/v4/repository#status")
end
fixity_graph() click to toggle source
# File lib/active_fedora/fixity_service.rb, line 79
def fixity_graph
  @fixity_graph ||= ::RDF::Graph.new << ::RDF::Reader.for(:ttl).new(response.body)
end
fixity_response_from_fedora() click to toggle source
# File lib/active_fedora/fixity_service.rb, line 74
def fixity_response_from_fedora
  uri = target + "/fcr:fixity"
  ActiveFedora.fedora.connection.get(encoded_url(uri))
end
premis_status_predicate() click to toggle source
# File lib/active_fedora/fixity_service.rb, line 58
def premis_status_predicate
  ::RDF::Vocab::PREMIS.hasEventOutcome
end
success() click to toggle source
# File lib/active_fedora/fixity_service.rb, line 70
def success
  ::RDF::Literal.new("SUCCESS")
end