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

Solrize CVs with consistant https scheme #3056

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion lib/hyrax/controlled_vocabularies/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def solrize
return [rdf_subject.to_s] if rdf_label.first.to_s.blank? || rdf_label_uri_same?

fetch
[rdf_subject.to_s, { label: "#{rdf_label.first}$#{rdf_subject}" }]
[storage_uri.to_s, { label: "#{rdf_label.first}$#{storage_uri}" }]
end

# Overrides rdf_label to add location disambiguation when available.
Expand Down Expand Up @@ -132,6 +132,12 @@ def persist!

private

def storage_uri
standard_uri = URI.parse(rdf_subject.to_s)
standard_uri.scheme = 'https'
RDF::URI.new(standard_uri)
end

# Identify if this is a county in the USA
def us_county?
feature_code = featureCode.first
Expand Down
10 changes: 8 additions & 2 deletions lib/oregon_digital/controlled_vocabularies/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ def set_subject!(uri_or_str)
end
# rubocop:enable AccessorMethodName

def storage_uri
standard_uri = URI.parse(rdf_subject.to_s)
standard_uri.scheme = 'https'
RDF::URI.new(standard_uri)
end

# Return a tuple of url & label
def solrize
return [rdf_subject.to_s] if rdf_label.first.to_s.blank? || rdf_label_uri_same?

[rdf_subject.to_s, { label: "#{language_label(get_language_label(rdf_label))}$#{rdf_subject}" }]
[storage_uri.to_s, { label: "#{language_label(get_language_label(rdf_label))}$#{storage_uri}" }]
end

# Sanity check for valid rdf_subject. Subject should never be blank but in the event,
Expand Down Expand Up @@ -105,7 +111,7 @@ def self.in_vocab?(uri)

# Return the URI as a string
def to_s
respond_to?(:rdf_subject) ? rdf_subject.to_s : super
respond_to?(:rdf_subject) ? solrize.first : super
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module ControlledVocabularies::Vocabularies
# Receives information pulled from the endpoint and can parse and generate queries
class SparMediaType
def self.expression
%r{^https:\/\/w3id.org\/spar\/mediatype\/.*/.*}
%r{^http[s]:\/\/w3id.org\/spar\/mediatype\/.*/.*}
end

def self.label(data)
Expand Down
14 changes: 7 additions & 7 deletions spec/hyrax/controlled_vocabularies/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@
context 'with a valid label and subject' do
before do
allow(location).to receive(:rdf_label).and_return(['RDF_Label'])
allow(location).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(location).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(location.solrize).to eq ['RDF.Subject.Org', { label: 'RDF_Label$RDF.Subject.Org' }] }
it { expect(location.solrize).to eq ['https://RDF.Subject.Org', { label: 'RDF_Label$https://RDF.Subject.Org' }] }
end

context 'without a label' do
before do
allow(location).to receive(:rdf_label).and_return([''])
allow(location).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(location).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(location.solrize).to eq ['RDF.Subject.Org'] }
it { expect(location.solrize).to eq ['http://RDF.Subject.Org'] }
end

context 'when label and uri are the same' do
before do
allow(location).to receive(:rdf_label).and_return(['RDF.Subject.Org'])
allow(location).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(location).to receive(:rdf_label).and_return(['http://RDF.Subject.Org'])
allow(location).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(location.solrize).to eq ['RDF.Subject.Org'] }
it { expect(location.solrize).to eq ['http://RDF.Subject.Org'] }
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/oregon_digital/controlled_vocabularies/institution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@
context 'with a valid label and subject' do
before do
allow(vocab_inst).to receive(:rdf_label).and_return([RDF::Literal.new('RDF_Label', language: I18n.locale)])
allow(vocab_inst).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(vocab_inst).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(vocab_inst.solrize).to eq ['RDF.Subject.Org', { label: 'RDF_Label$RDF.Subject.Org' }] }
it { expect(vocab_inst.solrize).to eq ['https://RDF.Subject.Org', { label: 'RDF_Label$https://RDF.Subject.Org' }] }
end

context 'without a label' do
before do
allow(vocab_inst).to receive(:rdf_label).and_return([])
allow(vocab_inst).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(vocab_inst).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(vocab_inst.solrize).to eq ['RDF.Subject.Org'] }
it { expect(vocab_inst.solrize).to eq ['http://RDF.Subject.Org'] }
end

context 'when label and uri are the same' do
before do
allow(vocab_inst).to receive(:rdf_label).and_return([RDF::Literal.new('RDF.Subject.Org', language: I18n.locale)])
allow(vocab_inst).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(vocab_inst).to receive(:rdf_label).and_return([RDF::Literal.new('http://RDF.Subject.Org', language: I18n.locale)])
allow(vocab_inst).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(vocab_inst.solrize).to eq ['RDF.Subject.Org'] }
it { expect(vocab_inst.solrize).to eq ['http://RDF.Subject.Org'] }
end
end
end
14 changes: 7 additions & 7 deletions spec/oregon_digital/controlled_vocabularies/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
context 'with a valid label and subject' do
before do
allow(resource).to receive(:rdf_label).and_return(['RDF_Label'])
allow(resource).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(resource).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(resource.solrize).to eq ['RDF.Subject.Org', { label: 'RDF_Label$RDF.Subject.Org' }] }
it { expect(resource.solrize).to eq ['https://RDF.Subject.Org', { label: 'RDF_Label$https://RDF.Subject.Org' }] }
end

context 'without a label' do
before do
allow(resource).to receive(:rdf_label).and_return([''])
allow(resource).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(resource).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(resource.solrize).to eq ['RDF.Subject.Org'] }
it { expect(resource.solrize).to eq ['http://RDF.Subject.Org'] }
end

context 'when label and uri are the same' do
before do
allow(resource).to receive(:rdf_label).and_return(['RDF.Subject.Org'])
allow(resource).to receive(:rdf_subject).and_return('RDF.Subject.Org')
allow(resource).to receive(:rdf_label).and_return(['http://RDF.Subject.Org'])
allow(resource).to receive(:rdf_subject).and_return('http://RDF.Subject.Org')
end

it { expect(resource.solrize).to eq ['RDF.Subject.Org'] }
it { expect(resource.solrize).to eq ['http://RDF.Subject.Org'] }
end
end

Expand Down