Skip to content

Commit

Permalink
extract a concern for scrubbing resolvers and include in Site (DLC-1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Dec 12, 2023
1 parent 8f9164a commit c49164b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
17 changes: 17 additions & 0 deletions app/models/concerns/solr_document/clean_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SolrDocument::CleanResolver
# Scrub permanent links from catalog data to use modern resolver syntax
# @param perma_link [String] the original link
# @return [String] link with cgi version of resolver replaced with modern version
def clean_resolver(link_src)
if link_src
link_uri = URI(link_src)
if link_uri.path == "/cgi-bin/cul/resolve" && link_uri.host == "www.columbia.edu"
return "https://resolver.library.columbia.edu/#{link_uri.query}"
end
if link_uri.host == "library.columbia.edu" && link_uri.path =~ /^\/resolve\/([^\/]+)/
return "https://resolver.library.columbia.edu/#{$1}"
end
end
link_src
end
end
6 changes: 6 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class Site < ApplicationRecord
include Dcv::Sites::Constants
include Blacklight::Configurable
include SolrDocument::CleanResolver
has_many :scope_filters, as: :scopeable
has_many :nav_links, dependent: :destroy, inverse_of: :site
has_many :site_pages, dependent: :destroy
Expand Down Expand Up @@ -181,6 +182,11 @@ def watermark_url
watermark_uploader.store_path.sub(File.join(Rails.root, 'public'), '')
end

# scrub CUL resolvers for format, or pass through
def persistent_url
clean_resolver(super)
end

def to_subsite_config
config = {
'slug' => slug, 'restricted' => (slug =~ /restricted/).present?, 'palette' => palette, 'layout' => layout, 'scope_constraints' => constraints
Expand Down
17 changes: 1 addition & 16 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SolrDocument
RESOURCE_MODEL = 'GenericResource'

include Blacklight::Solr::Document
include SolrDocument::CleanResolver
include SolrDocument::FieldSemantics
include SolrDocument::OpenUrlContext
include SolrDocument::PublicationInfo
Expand Down Expand Up @@ -89,22 +90,6 @@ def schema_image_identifier
end
end

# Scrub permanent links from catalog data to use modern resolver syntax
# @param perma_link [String] the original link
# @return [String] link with cgi version of resolver replaced with modern version
def clean_resolver(link_src)
if link_src
link_uri = URI(link_src)
if link_uri.path == "/cgi-bin/cul/resolve" && link_uri.host == "www.columbia.edu"
return "https://resolver.library.columbia.edu/#{link_uri.query}"
end
if link_uri.host == "library.columbia.edu" && link_uri.path =~ /^\/resolve\/([^\/]+)/
return "https://resolver.library.columbia.edu/#{$1}"
end
end
link_src
end

def slug
if self[:restriction_ssim].present?
Array(self[:slug_ssim]).compact.map { |val| "restricted/#{val}" }.first
Expand Down
23 changes: 23 additions & 0 deletions spec/models/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,27 @@
end
end
end
describe '#persistent_url' do
let(:site_slug) { 'persistent_url' }
let(:rkey) { 'lweb0138' }
let(:cgi_http) { "http://www.columbia.edu/cgi-bin/cul/resolve?#{rkey}" }
let(:cgi_https) { "https://www.columbia.edu/cgi-bin/cul/resolve?#{rkey}" }
let(:lweb_http) { "https://library.columbia.edu/resolve/#{rkey}" }
let(:lweb_https) { "https://library.columbia.edu/resolve/#{rkey}" }
let(:current_https) { "https://resolver.library.columbia.edu/#{rkey}" }
let(:na_https) { "https://nothing.library.columbia.edu/#{rkey}" }
it "cleans resolvers" do
site.persistent_url = cgi_http
expect(site.persistent_url).to eql(current_https)
site.persistent_url = cgi_https
expect(site.persistent_url).to eql(current_https)
site.persistent_url = lweb_http
expect(site.persistent_url).to eql(current_https)
site.persistent_url = lweb_https
expect(site.persistent_url).to eql(current_https)
site.persistent_url = na_https
expect(site.persistent_url).to eql(na_https)
end

end
end

0 comments on commit c49164b

Please sign in to comment.