Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rdf_subject if CV rdf_subject doesn't match fetched rdf_subject #3196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/oregon_digital/controlled_vocabularies/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def rdf_label
# use of the provided graph.
def fetch(*_args, &_block)
persistence_strategy.graph = triplestore_fetch

# Reset the rdf_subject if the rdf_subject doesn't match the rdf_subject from the fetched URI
# This is most common when this object is initialized with an 'https' scheme rather than 'http'
@rdf_subject = subjects.select do |subject_uri|
# Find subjects that match rdf_subject excluding the scheme. I think this should almost always be a length 1 array
subject_uri.is_a?(RDF::URI) && [rdf_subject.host, rdf_subject.path].join == [subject_uri.host, subject_uri.path].join
end[0]
end

# DISABLES RUBOCOP BECAUSE SET_SUBJECT! IS AN OVERRIDE FROM AT::RESOURCE
Expand Down Expand Up @@ -90,14 +97,20 @@ def solrize
# Sanity check for valid rdf_subject. Subject should never be blank but in the event,
# it should return an empty graph.
def triplestore_fetch
URI.parse(rdf_subject).is_a?(URI::HTTP) ? triplestore.fetch(rdf_subject) : RDF::Graph.new
URI.parse(rdf_subject).is_a?(URI::HTTP) ? triplestore.fetch(query_uri) : RDF::Graph.new
end

def in_triplestore?
# Nil return from triplestore signifies that the term isnt in the cache
!triplestore.fetch_cached_term(rdf_subject).nil?
end

# the linkeddata or rdf gem can't always recognize what content-type to use in the accept header
# this will be the same URI used to complete the QA autocomplete page, this is right more often
def query_uri
self.class.query_to_vocabulary(rdf_subject).as_query(rdf_subject)
end

def language_label(language)
language.blank? ? rdf_label.first : language
end
Expand Down