Skip to content

Commit

Permalink
Don't use Fcrepo digest predicate from rdf-vocab
Browse files Browse the repository at this point in the history
Fcrepo4.digest was used by Fedora < 4.2, 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
  • Loading branch information
jcoyne committed Sep 24, 2015
1 parent ce90057 commit 5bef08e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/active_fedora/file/attributes.rb
Expand Up @@ -17,7 +17,7 @@ def original_name= name
def digest
response = metadata.ldp_source.graph.query(predicate: RDF::Vocab::PREMIS.hasMessageDigest)
# fallback on old predicate for checksum
response = metadata.ldp_source.graph.query(predicate: RDF::Vocab::Fcrepo4.digest) if response.empty?
response = metadata.ldp_source.graph.query(predicate: fallback_digest_predicate) if response.empty?
response.map(&:object)
end

Expand All @@ -43,6 +43,18 @@ def empty?

private

# Fcrepo4.digest 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 fallback_digest_predicate
@fallback_digest ||= if RDF::Vocab::Fcrepo4.respond_to? :digest
RDF::Vocab::Fcrepo4.digest
else
::RDF::URI("http://fedora.info/definitions/v4/repository#digest")
end
end

def links
@links ||= Ldp::Response.links(ldp_source.head)
end
Expand Down
10 changes: 9 additions & 1 deletion lib/active_fedora/fixity_service.rb
Expand Up @@ -18,11 +18,19 @@ def check
end

def status
fixity_graph.query(predicate: ::RDF::Vocab::Fcrepo4.status).map(&:object).first.to_s
fixity_graph.query(predicate: status_predicate).map(&:object).first.to_s
end

private

# 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
::RDF::URI("http://fedora.info/definitions/v4/repository#status")
end

def get_fixity_response_from_fedora
uri = target + "/fcr:fixity"
ActiveFedora.fedora.connection.get(encoded_url(uri))
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/file_spec.rb
Expand Up @@ -232,8 +232,10 @@
end
context "with pre-4.3.0 predicate" do
before do
predicate = ::RDF::URI("http://fedora.info/definitions/v4/repository#digest")
object = RDF::URI.new("urn:sha1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15")
graph = ActiveTriples::Resource.new
graph << RDF::Statement.new(file.uri, RDF::Vocab::Fcrepo4.digest, RDF::URI.new("urn:sha1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"))
graph << RDF::Statement.new(file.uri, predicate, object)
allow(file).to receive_message_chain(:metadata, :ldp_source, :graph).and_return(graph)
end
it "falls back on fedora:digest if premis:hasMessageDigest is not present" do
Expand Down

0 comments on commit 5bef08e

Please sign in to comment.