Skip to content

Commit

Permalink
Support both Fedora and Premis fixity predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Oct 16, 2015
1 parent 664cca6 commit 1f320f1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
17 changes: 13 additions & 4 deletions lib/active_fedora/fixity_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,35 @@ def initialize target
end

# Executes a fixity check on Fedora and saves the Faraday::Response.
# Returns true when the fixity check was successfully.
# @return true or false
def check
@response = get_fixity_response_from_fedora
status.match("SUCCESS") ? true : false
status.include?(success)
end

def status
fixity_graph.query(predicate: status_predicate).map(&:object).first.to_s
fixity_graph.query(predicate: premis_status_predicate).map(&:object) +
fixity_graph.query(predicate: fedora_status_predicate).map(&:object)
end

private

def premis_status_predicate
::RDF::Vocab::PREMIS.hasEventOutcome
end

# Fcrepo4.status was used by Fedora < 4.3, but it was removed
# from the 2015-07-24 version of the fedora 4 ontology
# http://fedora.info/definitions/v4/2015/07/24/repository and
# from rdf-vocab in version 0.8.5
def status_predicate
def fedora_status_predicate
::RDF::URI("http://fedora.info/definitions/v4/repository#status")
end

def success
::RDF::Literal.new("SUCCESS")
end

def get_fixity_response_from_fedora
uri = target + "/fcr:fixity"
ActiveFedora.fedora.connection.get(encoded_url(uri))
Expand Down
42 changes: 33 additions & 9 deletions spec/unit/fixity_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,44 @@
end

describe "#check" do
before do
allow(service).to receive(:get_fixity_response_from_fedora).and_return(response)
end
before { allow(service).to receive(:get_fixity_response_from_fedora).and_return(response) }
subject { service.check }
context "with a passing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "SUCCESS"^^<http://www.w3.org/2001/XMLSchema#string> .')

context "with Fedora version >= 4.4.0" do
context "with a passing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://www.loc.gov/premis/rdf/v1#hasEventOutcome> "SUCCESS"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
it { is_expected.to be true }
end

context "with a failing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://www.loc.gov/premis/rdf/v1#hasEventOutcome> "BAD_CHECKSUM"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
it { is_expected.to be false }
end
end

context "with Fedora version < 4.4.0" do
context "with a passing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "SUCCESS"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
it { is_expected.to be true }
end

context "with a failing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "BAD_CHECKSUM"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
it { is_expected.to be false }
end
it { is_expected.to be true }
end

context "with a failing result" do
context "with a non-existent predicate" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "BAD_CHECKSUM"^^<http://www.w3.org/2001/XMLSchema#string> .')
instance_double("Response", body: '<subject> <http://bogus.com/definitions/v1/bogusTerm#foo> "SUCCESS"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
it { is_expected.to be false }
end
Expand Down

0 comments on commit 1f320f1

Please sign in to comment.