diff --git a/app/models/public_xml.rb b/app/models/public_xml.rb index eb5f67e6..a1f0a193 100644 --- a/app/models/public_xml.rb +++ b/app/models/public_xml.rb @@ -49,4 +49,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')&.text + end end diff --git a/app/models/purl_resource.rb b/app/models/purl_resource.rb index 50cac014..9b748584 100644 --- a/app/models/purl_resource.rb +++ b/app/models/purl_resource.rb @@ -89,7 +89,7 @@ def containing_purl_collections end.compact end - delegate :rights_metadata, to: :public_xml + delegate :rights_metadata, :object_type, to: :public_xml def content_metadata @content_metadata ||= ContentMetadata.new(public_xml.content_metadata) @@ -121,6 +121,10 @@ def iiif3_manifest @iiif3_manifest ||= Iiif3PresentationManifest.new(self) end + def collection? + object_type == 'collection' + end + concerning :Metadata do def title if mods? diff --git a/app/views/purl/_collection_items.html.erb b/app/views/purl/_collection_items.html.erb new file mode 100644 index 00000000..6f421627 --- /dev/null +++ b/app/views/purl/_collection_items.html.erb @@ -0,0 +1,10 @@ +<% if document.collection? && document.folio_instance_hrid %> +
+
+

Items in collection

+
+
+ <%= link_to 'View items in this collection in SearchWorks', "#{Settings.searchworks.url}/catalog?f[collection][]=#{document.folio_instance_hrid}" %> +
+
+<% end %> diff --git a/app/views/purl/_mods_metadata_sections.html.erb b/app/views/purl/_mods_metadata_sections.html.erb index 1ec7c68b..86d07ada 100644 --- a/app/views/purl/_mods_metadata_sections.html.erb +++ b/app/views/purl/_mods_metadata_sections.html.erb @@ -5,4 +5,5 @@ <%= render "mods_bibliographic", document: document %> <%= render "mods_contact", document: document %> <%= render "collection", document: document %> +<%= render "collection_items", document: document %> <%= render "find_it", document: document %> 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..fa5bf413 --- /dev/null +++ b/spec/fixtures/document_cache/bb/631/ry/3167/public @@ -0,0 +1,74 @@ + + + + collection + Native American Alumni Oral Histories + 13965062 + 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. + + + + + + + + + + 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/mods b/spec/fixtures/document_cache/gk/894/yk/3598/mods new file mode 100644 index 00000000..245fca45 --- /dev/null +++ b/spec/fixtures/document_cache/gk/894/yk/3598/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. + \ No newline at end of file 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..773a06da --- /dev/null +++ b/spec/fixtures/document_cache/gk/894/yk/3598/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/integration/purl_spec.rb b/spec/integration/purl_spec.rb index b1a4074b..4c74c602 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 @@ -213,4 +214,12 @@ expect(page).to have_text('Application is running') 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 end diff --git a/spec/model/purl_resource_spec.rb b/spec/model/purl_resource_spec.rb index dfd7f669..21525051 100644 --- a/spec/model/purl_resource_spec.rb +++ b/spec/model/purl_resource_spec.rb @@ -325,4 +325,46 @@ end end end + + describe '#object_type and #collection?' do + context 'when a collection' do + before do + allow(subject).to receive(:public_xml_body).and_return(<<-EOF + + + + collection + Acquisitions Serials + + + EOF + ) + end + + it 'pulls the value from the identity metadata' do + expect(subject.object_type).to eq 'collection' + expect(subject.collection?).to be true + end + end + + context 'when an item' do + before do + allow(subject).to receive(:public_xml_body).and_return(<<-EOF + + + + SUL Logo 2015 + item + + + EOF + ) + end + + it 'pulls the value from the identity metadata' do + expect(subject.object_type).to eq 'item' + expect(subject.collection?).to be false + end + 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..eb7d487d --- /dev/null +++ b/spec/views/purl/_collection_items.html.erb_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe 'purl/_collection_items' do + context 'when collection has a folio HRID' do + let(:purl) { PurlResource.new(id: 'bb631ry3167') } + + it 'displays a View items in this collection link' do + # render + render 'purl/collection_items', document: purl + expect(rendered).to have_css 'a[href="https://searchworks.stanford.edu/catalog?f[collection][]=a13965062"]', + text: 'View items in this collection in SearchWorks' + end + end + + context 'when collection does not have a folio HRID' do + let(:purl) { PurlResource.new(id: 'gk894yk3598') } + + it 'does not display View items in this collection link' do + # render + render 'purl/collection_items', document: purl + 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 + render 'purl/collection_items', document: purl + expect(rendered).not_to have_css 'a' + end + end +end