diff --git a/app/models/public_xml.rb b/app/models/public_xml.rb index bdc507b4..4ceb1f6d 100644 --- a/app/models/public_xml.rb +++ b/app/models/public_xml.rb @@ -45,4 +45,8 @@ def relations(predicate) node.attribute('resource').text.split('/', 2).last.split(':', 2).last end end + + def object_type + document.root.at_xpath('identityMetadata/objectType').try(:text) + end end diff --git a/app/models/purl_resource.rb b/app/models/purl_resource.rb index ced761aa..8c961d62 100644 --- a/app/models/purl_resource.rb +++ b/app/models/purl_resource.rb @@ -80,6 +80,7 @@ def collection end delegate :rights_metadata, to: :public_xml + delegate :object_type, to: :public_xml def content_metadata @content_metadata ||= ContentMetadata.new(public_xml.content_metadata) diff --git a/app/views/purl/_collection_items.html.erb b/app/views/purl/_collection_items.html.erb new file mode 100644 index 00000000..3556be0c --- /dev/null +++ b/app/views/purl/_collection_items.html.erb @@ -0,0 +1,3 @@ +<% if @purl.object_type == 'collection' && @purl.catalog_key %> + <%= link_to 'View items in this collection in SearchWorks', "#{Settings.searchworks.url}/catalog?f[collection][]=#{@purl.catalog_key}" %> +<% end %> diff --git a/app/views/purl/_find_it.html.erb b/app/views/purl/_find_it.html.erb index db5c67a4..44d9d1f8 100644 --- a/app/views/purl/_find_it.html.erb +++ b/app/views/purl/_find_it.html.erb @@ -1,5 +1,5 @@ <% if @purl.catalog_key %> - <%= link_to 'View in SearchWorks', Settings.searchworks.url + @purl.catalog_key %> + <%= link_to 'View in SearchWorks', "#{Settings.searchworks.url}/view/#{@purl.catalog_key}" %> <% end %> <% releases = [] %> diff --git a/app/views/purl/_mods_metadata_sections.html.erb b/app/views/purl/_mods_metadata_sections.html.erb index f496b602..4a58e776 100644 --- a/app/views/purl/_mods_metadata_sections.html.erb +++ b/app/views/purl/_mods_metadata_sections.html.erb @@ -7,6 +7,7 @@ bibliography = render(partial: "mods_bibliographic", locals: {document: document}) contact = render(partial: "mods_contact", locals: {document: document}) find_it = render(partial: "find_it", locals: {document: document}) + collection_items = render(partial: "collection_items", locals: {document: document}) %> <% if description.present? %> @@ -85,6 +86,18 @@ <% end %> +<% if collection_items.present? %> +
+
+

<%= t('record_side_nav.find_it.icon').html_safe %> Items in collection

+
+
+ <%= collection_items %> +
+
+<% end %> + + <% if find_it.present? %>
diff --git a/config/settings.yml b/config/settings.yml index 7e462ceb..a5d1f28b 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -36,7 +36,7 @@ releases: url: 'https://earthworks.stanford.edu/catalog/stanford-%{druid}' searchworks: - url: 'https://searchworks.stanford.edu/view/' + url: 'https://searchworks.stanford.edu' landing_page_druids: - bb112zx3193 diff --git a/spec/fixtures/document_cache/bb/631/ry/3167/mods b/spec/fixtures/document_cache/bb/631/ry/3167/mods new file mode 100644 index 00000000..6694554b --- /dev/null +++ b/spec/fixtures/document_cache/bb/631/ry/3167/mods @@ -0,0 +1,32 @@ + + + + Native American Alumni Oral Histories + + mixed material + + eng + + + + cau + + monographic + + + https://purl.stanford.edu/bb631ry3167 + + + Dept. of Special Collections and University Archives Stanford University Libraries Stanford, CA 94305 + + + CSt + aacr + dacs + Converted from MARCXML to MODS version 3.7 using MARC21slim2MODS3-7_SDR_v2-5.xsl (SUL 3.7 version 2.5 20210421; LC Revision 1.140 20200717) + 210811 + a13965062 + + The materials are open for research use and may be used freely for non-commercial purposes with an attribution. For commercial permission requests, please contact the Stanford University Archives (universityarchives@stanford.edu). + Copyright (c) The Board of Trustees of the Leland Stanford Junior University. All rights reserved. + diff --git a/spec/fixtures/document_cache/bb/631/ry/3167/public b/spec/fixtures/document_cache/bb/631/ry/3167/public new file mode 100644 index 00000000..773a06da --- /dev/null +++ b/spec/fixtures/document_cache/bb/631/ry/3167/public @@ -0,0 +1,73 @@ + + + + collection + Native American Alumni Oral Histories + 13965062 + + + + + + + + + + + + + + The materials are open for research use and may be used freely for non-commercial purposes with an attribution. For commercial permission requests, please contact the Stanford University Archives (universityarchives@stanford.edu). + + + + Copyright (c) The Board of Trustees of the Leland Stanford Junior University. All rights reserved. + + + + + + + + + + Native American Alumni Oral Histories + Collection + eng + https://purl.stanford.edu/bb631ry3167 + + + + Native American Alumni Oral Histories + + mixed material + + eng + + + + cau + + monographic + + + https://purl.stanford.edu/bb631ry3167 + + + Dept. of Special Collections and University Archives Stanford University Libraries Stanford, CA 94305 + + + CSt + aacr + dacs + Converted from MARCXML to MODS version 3.7 using MARC21slim2MODS3-7_SDR_v2-5.xsl (SUL 3.7 version 2.5 20210421; LC Revision 1.140 20200717) + 210811 + a13965062 + + The materials are open for research use and may be used freely for non-commercial purposes with an attribution. For commercial permission requests, please contact the Stanford University Archives (universityarchives@stanford.edu). + Copyright (c) The Board of Trustees of the Leland Stanford Junior University. All rights reserved. + + + true + + diff --git a/spec/fixtures/document_cache/gk/894/yk/3598/public b/spec/fixtures/document_cache/gk/894/yk/3598/public new file mode 100644 index 00000000..95eea3b8 --- /dev/null +++ b/spec/fixtures/document_cache/gk/894/yk/3598/public @@ -0,0 +1,52 @@ + + + + collection + Acquisitions Serials + Hydrus:collection-amanheim-2017-05-12T20:11:22.791Z + + + + + + + + + + + + + + User agrees that, where applicable, content will not be used to identify or to otherwise infringe the privacy or confidentiality rights of individuals. Content distributed via the Stanford Digital Repository may be subject to additional license and use restrictions applied by the depositor. + + + + + + + + + + + Acquisitions Serials + Collection + Collection to load serial titles in digital format into the SDR. + https://purl.stanford.edu/gk894yk3598 + amanheim@stanford.edu + + + + Acquisitions Serials + + mixed material + Collection to load serial titles in digital format into the SDR. + + https://purl.stanford.edu/gk894yk3598 + + amanheim@stanford.edu + User agrees that, where applicable, content will not be used to identify or to otherwise infringe the privacy or confidentiality rights of individuals. Content distributed via the Stanford Digital Repository may be subject to additional license and use restrictions applied by the depositor. + + + false + + diff --git a/spec/integration/purl_spec.rb b/spec/integration/purl_spec.rb index b1a4074b..d6912986 100644 --- a/spec/integration/purl_spec.rb +++ b/spec/integration/purl_spec.rb @@ -10,6 +10,7 @@ @unpublished_object = 'ab123cd4567' @legacy_object = 'ir:rs276tc2764' @nested_resources_object = 'dm907qj6498' + @collection = 'bb631ry3167' end describe 'manifest' do @@ -206,6 +207,14 @@ end end + describe 'items in collection' do + it 'included in purl page' do + visit "/#{@collection}" + expect(page).to have_content 'Items in collection' + expect(page).to have_content 'View items in this collection in SearchWorks' + end + end + describe '/status (app monitoring)' do it 'has response code 200' do visit '/status' diff --git a/spec/model/purl_resource_spec.rb b/spec/model/purl_resource_spec.rb index 119b0c32..355bf251 100644 --- a/spec/model/purl_resource_spec.rb +++ b/spec/model/purl_resource_spec.rb @@ -291,4 +291,20 @@ end end end + + describe '#object_type' do + it 'pulls the value from the identity metadata' do + allow(subject).to receive(:public_xml_body).and_return <<-EOF + + + + collection + Acquisitions Serials + + + EOF + + expect(subject.object_type).to eq 'collection' + end + end end diff --git a/spec/views/purl/_collection_items.html.erb_spec.rb b/spec/views/purl/_collection_items.html.erb_spec.rb new file mode 100644 index 00000000..a0747eee --- /dev/null +++ b/spec/views/purl/_collection_items.html.erb_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe 'purl/_collection_items' do + before do + assign(:purl, purl) + end + + context 'when collection has a catalog record id' do + let(:purl) { PurlResource.new(id: 'bb631ry3167') } + + it 'displays a View items in this collection link' do + render + expect(rendered).to have_css 'a[href="https://searchworks.stanford.edu/catalog?f[collection][]=13965062"]', + text: 'View items in this collection in SearchWorks' + end + end + + context 'when collection does not have a catalog record id' do + let(:purl) { PurlResource.new(id: 'gk894yk3598') } + + it 'does not display View items in this collection link' do + render + expect(rendered).not_to have_css 'a' + end + end + + context 'when not a collection' do + let(:purl) { PurlResource.new(id: 'cg357zz0321') } + + it 'does not display View items in this collection link' do + render + expect(rendered).not_to have_css 'a' + end + end +end