From 318baca3091afe05f834d9519f15e551e22cbea3 Mon Sep 17 00:00:00 2001 From: Corey Gillen Date: Fri, 8 Nov 2024 12:40:06 -0800 Subject: [PATCH 1/2] Update rdf_subject if CV rdf_subject doesn't match fetched rdf_subject --- .../controlled_vocabularies/resource.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/oregon_digital/controlled_vocabularies/resource.rb b/lib/oregon_digital/controlled_vocabularies/resource.rb index f85c1c028..cfb3d1f8d 100644 --- a/lib/oregon_digital/controlled_vocabularies/resource.rb +++ b/lib/oregon_digital/controlled_vocabularies/resource.rb @@ -61,6 +61,12 @@ 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 + @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 @@ -90,7 +96,7 @@ 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? @@ -98,6 +104,10 @@ def in_triplestore? !triplestore.fetch_cached_term(rdf_subject).nil? end + 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 From e0688b302efd4072015c5b43119a1c814eba471f Mon Sep 17 00:00:00 2001 From: Corey Gillen Date: Fri, 8 Nov 2024 12:45:03 -0800 Subject: [PATCH 2/2] Some more comments --- lib/oregon_digital/controlled_vocabularies/resource.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/oregon_digital/controlled_vocabularies/resource.rb b/lib/oregon_digital/controlled_vocabularies/resource.rb index cfb3d1f8d..e59aef468 100644 --- a/lib/oregon_digital/controlled_vocabularies/resource.rb +++ b/lib/oregon_digital/controlled_vocabularies/resource.rb @@ -63,6 +63,7 @@ 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 @@ -104,6 +105,8 @@ def in_triplestore? !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