diff --git a/lib/hyrax/controlled_vocabularies/location.rb b/lib/hyrax/controlled_vocabularies/location.rb index ecaa49611..6df0da7b8 100644 --- a/lib/hyrax/controlled_vocabularies/location.rb +++ b/lib/hyrax/controlled_vocabularies/location.rb @@ -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. @@ -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 diff --git a/lib/oregon_digital/controlled_vocabularies/resource.rb b/lib/oregon_digital/controlled_vocabularies/resource.rb index efc05d0c6..a498861d6 100644 --- a/lib/oregon_digital/controlled_vocabularies/resource.rb +++ b/lib/oregon_digital/controlled_vocabularies/resource.rb @@ -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, @@ -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 diff --git a/lib/oregon_digital/controlled_vocabularies/vocabularies/spar_media_type.rb b/lib/oregon_digital/controlled_vocabularies/vocabularies/spar_media_type.rb index 5731a9277..2d9abdd0a 100644 --- a/lib/oregon_digital/controlled_vocabularies/vocabularies/spar_media_type.rb +++ b/lib/oregon_digital/controlled_vocabularies/vocabularies/spar_media_type.rb @@ -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) diff --git a/spec/hyrax/controlled_vocabularies/location_spec.rb b/spec/hyrax/controlled_vocabularies/location_spec.rb index 9640e7740..525eeb39a 100644 --- a/spec/hyrax/controlled_vocabularies/location_spec.rb +++ b/spec/hyrax/controlled_vocabularies/location_spec.rb @@ -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 diff --git a/spec/oregon_digital/controlled_vocabularies/institution_spec.rb b/spec/oregon_digital/controlled_vocabularies/institution_spec.rb index 4c50bc853..29017e295 100644 --- a/spec/oregon_digital/controlled_vocabularies/institution_spec.rb +++ b/spec/oregon_digital/controlled_vocabularies/institution_spec.rb @@ -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 diff --git a/spec/oregon_digital/controlled_vocabularies/resource_spec.rb b/spec/oregon_digital/controlled_vocabularies/resource_spec.rb index afec4b678..3157d4034 100644 --- a/spec/oregon_digital/controlled_vocabularies/resource_spec.rb +++ b/spec/oregon_digital/controlled_vocabularies/resource_spec.rb @@ -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