Skip to content

Commit c49164b

Browse files
committed
extract a concern for scrubbing resolvers and include in Site (DLC-1052)
1 parent 8f9164a commit c49164b

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module SolrDocument::CleanResolver
2+
# Scrub permanent links from catalog data to use modern resolver syntax
3+
# @param perma_link [String] the original link
4+
# @return [String] link with cgi version of resolver replaced with modern version
5+
def clean_resolver(link_src)
6+
if link_src
7+
link_uri = URI(link_src)
8+
if link_uri.path == "/cgi-bin/cul/resolve" && link_uri.host == "www.columbia.edu"
9+
return "https://resolver.library.columbia.edu/#{link_uri.query}"
10+
end
11+
if link_uri.host == "library.columbia.edu" && link_uri.path =~ /^\/resolve\/([^\/]+)/
12+
return "https://resolver.library.columbia.edu/#{$1}"
13+
end
14+
end
15+
link_src
16+
end
17+
end

app/models/site.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class Site < ApplicationRecord
33
include Dcv::Sites::Constants
44
include Blacklight::Configurable
5+
include SolrDocument::CleanResolver
56
has_many :scope_filters, as: :scopeable
67
has_many :nav_links, dependent: :destroy, inverse_of: :site
78
has_many :site_pages, dependent: :destroy
@@ -181,6 +182,11 @@ def watermark_url
181182
watermark_uploader.store_path.sub(File.join(Rails.root, 'public'), '')
182183
end
183184

185+
# scrub CUL resolvers for format, or pass through
186+
def persistent_url
187+
clean_resolver(super)
188+
end
189+
184190
def to_subsite_config
185191
config = {
186192
'slug' => slug, 'restricted' => (slug =~ /restricted/).present?, 'palette' => palette, 'layout' => layout, 'scope_constraints' => constraints

app/models/solr_document.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SolrDocument
1515
RESOURCE_MODEL = 'GenericResource'
1616

1717
include Blacklight::Solr::Document
18+
include SolrDocument::CleanResolver
1819
include SolrDocument::FieldSemantics
1920
include SolrDocument::OpenUrlContext
2021
include SolrDocument::PublicationInfo
@@ -89,22 +90,6 @@ def schema_image_identifier
8990
end
9091
end
9192

92-
# Scrub permanent links from catalog data to use modern resolver syntax
93-
# @param perma_link [String] the original link
94-
# @return [String] link with cgi version of resolver replaced with modern version
95-
def clean_resolver(link_src)
96-
if link_src
97-
link_uri = URI(link_src)
98-
if link_uri.path == "/cgi-bin/cul/resolve" && link_uri.host == "www.columbia.edu"
99-
return "https://resolver.library.columbia.edu/#{link_uri.query}"
100-
end
101-
if link_uri.host == "library.columbia.edu" && link_uri.path =~ /^\/resolve\/([^\/]+)/
102-
return "https://resolver.library.columbia.edu/#{$1}"
103-
end
104-
end
105-
link_src
106-
end
107-
10893
def slug
10994
if self[:restriction_ssim].present?
11095
Array(self[:slug_ssim]).compact.map { |val| "restricted/#{val}" }.first

spec/models/site_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,27 @@
249249
end
250250
end
251251
end
252+
describe '#persistent_url' do
253+
let(:site_slug) { 'persistent_url' }
254+
let(:rkey) { 'lweb0138' }
255+
let(:cgi_http) { "http://www.columbia.edu/cgi-bin/cul/resolve?#{rkey}" }
256+
let(:cgi_https) { "https://www.columbia.edu/cgi-bin/cul/resolve?#{rkey}" }
257+
let(:lweb_http) { "https://library.columbia.edu/resolve/#{rkey}" }
258+
let(:lweb_https) { "https://library.columbia.edu/resolve/#{rkey}" }
259+
let(:current_https) { "https://resolver.library.columbia.edu/#{rkey}" }
260+
let(:na_https) { "https://nothing.library.columbia.edu/#{rkey}" }
261+
it "cleans resolvers" do
262+
site.persistent_url = cgi_http
263+
expect(site.persistent_url).to eql(current_https)
264+
site.persistent_url = cgi_https
265+
expect(site.persistent_url).to eql(current_https)
266+
site.persistent_url = lweb_http
267+
expect(site.persistent_url).to eql(current_https)
268+
site.persistent_url = lweb_https
269+
expect(site.persistent_url).to eql(current_https)
270+
site.persistent_url = na_https
271+
expect(site.persistent_url).to eql(na_https)
272+
end
273+
274+
end
252275
end

0 commit comments

Comments
 (0)