Skip to content

Commit

Permalink
Parameterize purl, stacks, and geoserver URLs in geo config
Browse files Browse the repository at this point in the history
Ref #742
  • Loading branch information
thatbudakguy committed Jan 19, 2023
1 parent 1e4719c commit a601a6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
79 changes: 48 additions & 31 deletions lib/traject/config/geo_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ def log_skip(context)
provide "reader_class_name", "Traject::DruidReader"
end

provide 'purl_fetcher.target', ENV.fetch('PURL_FETCHER_TARGET', 'Earthworks')
provide 'purl.url', ENV.fetch('PURL_URL', 'https://purl.stanford.edu')
provide 'stacks.url', ENV.fetch('STACKS_URL', 'https://stacks.stanford.edu')
provide 'geoserver.pub_url', ENV.fetch('GEOSERVER_PUB_URL', 'https://geowebservices.stanford.edu/geoserver')
provide 'geoserver.stan_url', ENV.fetch('GEOSERVER_STAN_URL', 'https://geowebservices-restricted.stanford.edu/geoserver')

provide 'purl_fetcher.target', ENV.fetch('PURL_FETCHER_TARGET', 'Earthworks')
provide 'purl_fetcher.skip_catkey', ENV['PURL_FETCHER_SKIP_CATKEY']
provide 'solr_writer.commit_on_close', true
if defined?(JRUBY_VERSION)
require 'traject/manticore_http_client'
Expand Down Expand Up @@ -129,11 +134,11 @@ def mods_display(method, *args, default: nil)
end
end

module Constants
GEOWEBSERVICES = {
'Public': 'https://geowebservices.stanford.edu/geoserver',
'Restricted': 'https://geowebservices-restricted.stanford.edu/geoserver'
}
# Get the right geoserver url for a record given its access rights
def geoserver_url(record)
return settings['geoserver.stan_url'] if record.stanford_only?

settings['geoserver.pub_url']
end

each_record do |record, context|
Expand All @@ -150,7 +155,7 @@ module Constants
end

to_field 'dc_identifier_s' do |record, accumulator|
accumulator << "http://purl.stanford.edu/#{record.druid}"
accumulator << "#{settings['purl.url']}/#{record.druid}"
end

each_record do |record, context|
Expand Down Expand Up @@ -266,44 +271,56 @@ module Constants
to_field 'geoblacklight_version', literal('1.0')
to_field 'dct_references_s' do |record, accumulator, context|
references = {
'http://schema.org/url' => "https://purl.stanford.edu/#{record.druid}",
'http://www.loc.gov/mods/v3' => "https://purl.stanford.edu/#{record.druid}.mods",
'http://schema.org/url' => "#{settings['purl.url']}/#{record.druid}",
'http://www.loc.gov/mods/v3' => "#{settings['purl.url']}/#{record.druid}.mods"
}
case record.dor_content_type
when 'file'
references.merge!({
'https://oembed.com' => "https://purl.stanford.edu/embed.json?&hide_title=true&url=https://purl.stanford.edu/#{record.druid}",
})
references.merge!(
{
'https://oembed.com' => "#{settings['purl.url']}/embed.json?&hide_title=true&url=#{settings['purl.url']}/#{record.druid}"
}
)
when 'image', 'map', 'book'
references.merge!({
'https://oembed.com' => "https://purl.stanford.edu/embed.json?&hide_title=true&url=https://purl.stanford.edu/#{record.druid}",
'http://iiif.io/api/presentation#manifest' => "https://purl.stanford.edu/#{record.druid}/iiif/manifest"
})
references.merge!(
{
'https://oembed.com' => "#{settings['purl.url']}/embed.json?&hide_title=true&url=#{settings['purl.url']}/#{record.druid}",
'http://iiif.io/api/presentation#manifest' => "#{settings['purl.url']}/#{record.druid}/iiif/manifest"
}
)
when 'geo'
formats = context.output_hash['dc_format_s'] || []

references.merge!({
'http://schema.org/downloadUrl' => "https://stacks.stanford.edu/file/druid:#{record.druid}/data.zip",
'http://www.opengis.net/def/serviceType/ogc/wms' => "#{Constants::GEOWEBSERVICES[context.output_hash['dc_rights_s'][0].to_sym]}/wms",
'http://www.isotc211.org/schemas/2005/gmd/' => "https://raw.githubusercontent.com/OpenGeoMetadata/edu.stanford.purl/master/#{record.druid_tree}/iso19139.xml",
})
references.merge!(
{
'http://schema.org/downloadUrl' => "#{settings['stacks.url']}/file/druid:#{record.druid}/data.zip",
'http://www.opengis.net/def/serviceType/ogc/wms' => "#{geoserver_url(record)}/wms",
'http://www.isotc211.org/schemas/2005/gmd/' => "https://raw.githubusercontent.com/OpenGeoMetadata/edu.stanford.purl/master/#{record.druid_tree}/iso19139.xml"
}
)

if formats.include?('Shapefile')
references.merge!({
'http://www.opengis.net/def/serviceType/ogc/wfs' => "#{Constants::GEOWEBSERVICES[context.output_hash['dc_rights_s'][0].to_sym]}/wfs",
})
references.merge!(
{
'http://www.opengis.net/def/serviceType/ogc/wfs' => "#{geoserver_url(record)}/wfs"
}
)
elsif formats.include?('GeoTIFF') || formats.include?('ArcGRID')
references.merge!({
'http://www.opengis.net/def/serviceType/ogc/wcs' => "#{Constants::GEOWEBSERVICES[context.output_hash['dc_rights_s'][0].to_sym]}/wcs",
})
references.merge!(
{
'http://www.opengis.net/def/serviceType/ogc/wcs' => "#{geoserver_url(record)}/wcs"
}
)
end

index_map = record.public_xml_doc.xpath('//file[@id="index_map.json"]').length > 0
index_map = !record.public_xml_doc.xpath('//file[@id="index_map.json"]').empty?

if index_map
references.merge!({
'https://openindexmaps.org' => "https://stacks.stanford.edu/file/druid:#{record.druid}/index_map.json"
})
references.merge!(
{
'https://openindexmaps.org' => "#{settings['stacks.url']}/file/druid:#{record.druid}/index_map.json"
}
)
end
end
accumulator << references.to_json
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/geo_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def stub_mods_request(druid, body)
stub_purl_request(druid, File.read(file_fixture("#{druid}.xml").to_s))
end
it 'maps things to the right places' do
expect(result).to include 'dc_identifier_s' => ['http://purl.stanford.edu/dc482zx1528'],
expect(result).to include 'dc_identifier_s' => ['https://purl.stanford.edu/dc482zx1528'],
'dc_title_s' => ['Jōshū Kusatsu Onsenzu'],
'dc_rights_s' => ['Public'],
'layer_geom_type_s' => ['Image'],
Expand Down Expand Up @@ -110,7 +110,7 @@ def stub_mods_request(druid, body)
stub_purl_request(druid, File.read(file_fixture("#{druid}.xml").to_s))
end
it 'maps the metadata' do
expect(result).to include 'dc_identifier_s' => ['http://purl.stanford.edu/vv853br8653'],
expect(result).to include 'dc_identifier_s' => ['https://purl.stanford.edu/vv853br8653'],
'dc_title_s' => ['Abundance Estimates of the Pacific Salmon Conservation Assessment Database, 1978-2008'],
'dct_provenance_s' => ['Stanford'],
'layer_geom_type_s' => ['Polygon'],
Expand Down Expand Up @@ -231,7 +231,7 @@ def stub_mods_request(druid, body)
end

it 'has expected fields' do
expect(result).to include 'dc_identifier_s' => ['http://purl.stanford.edu/bq589tv8583'],
expect(result).to include 'dc_identifier_s' => ['https://purl.stanford.edu/bq589tv8583'],
'layer_geom_type_s' => ['Collection']
end
it 'does not include a layer_id_s' do
Expand All @@ -246,7 +246,7 @@ def stub_mods_request(druid, body)
end

it 'has expected fields' do
expect(result).to include 'dc_identifier_s' => ['http://purl.stanford.edu/pq479rm6462'],
expect(result).to include 'dc_identifier_s' => ['https://purl.stanford.edu/pq479rm6462'],
'dc_format_s' => ['Geodatabase'],
'layer_geom_type_s' => ['Mixed']
end
Expand Down

0 comments on commit a601a6a

Please sign in to comment.