From 6fc28fa55aa13372abd7cd0295928ed7d95ad056 Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Tue, 24 Oct 2023 17:25:17 -0400 Subject: [PATCH] Display link to item's collection's item. closes #715 --- app/controllers/preview_controller.rb | 3 +- app/models/public_xml.rb | 6 +- app/models/purl_resource.rb | 17 ++- app/views/purl/_collection.html.erb | 15 ++ app/views/purl/_find_it.html.erb | 2 +- .../purl/_mods_metadata_sections.html.erb | 2 +- .../purl/_mods_upper_metadata_items.html.erb | 4 - app/views/purl/show.html.erb | 2 +- config/settings.yml | 2 +- spec/features/integration_spec.rb | 4 +- .../document_cache/sk/882/gx/0113/mods | 72 ++++++++++ .../document_cache/sk/882/gx/0113/public | 135 ++++++++++++++++++ .../document_cache/yb/533/nc/1884/mods | 20 +++ .../document_cache/yb/533/nc/1884/public | 61 ++++++++ spec/model/purl_resource_spec.rb | 6 +- 15 files changed, 333 insertions(+), 18 deletions(-) create mode 100644 app/views/purl/_collection.html.erb create mode 100644 spec/fixtures/document_cache/sk/882/gx/0113/mods create mode 100644 spec/fixtures/document_cache/sk/882/gx/0113/public create mode 100644 spec/fixtures/document_cache/yb/533/nc/1884/mods create mode 100644 spec/fixtures/document_cache/yb/533/nc/1884/public diff --git a/app/controllers/preview_controller.rb b/app/controllers/preview_controller.rb index efc2e0e8..efe093dc 100644 --- a/app/controllers/preview_controller.rb +++ b/app/controllers/preview_controller.rb @@ -7,7 +7,8 @@ def show @purl = @document = OpenStruct.new( mods?: true, mods: @mods, - title: Array.wrap(@mods.title).join(' -- ') + title: Array.wrap(@mods.title).join(' -- '), + containing_purl_collections: [] ) @purl.define_singleton_method(:released_to?) do |*args| diff --git a/app/models/public_xml.rb b/app/models/public_xml.rb index 69287dce..eb5f67e6 100644 --- a/app/models/public_xml.rb +++ b/app/models/public_xml.rb @@ -20,12 +20,16 @@ def content_metadata def catalog_key @catalog_key ||= document.root.at_xpath('identityMetadata/otherId[@name="catkey"]')&.text.presence @catalog_key ||= begin - key = document.root.at_xpath('identityMetadata/otherId[@name="folio_instance_hrid"]')&.text.presence + key = folio_instance_hrid key = key.delete_prefix('a') if key&.match?(/^a\d+$/) key end end + def folio_instance_hrid + @folio_instance_hrid ||= document.root.at_xpath('identityMetadata/otherId[@name="folio_instance_hrid"]')&.text.presence + end + def released_to?(key) release = document.root.at_xpath("releaseData/release[@to='#{key}']")&.text diff --git a/app/models/purl_resource.rb b/app/models/purl_resource.rb index 0535dbd7..5e9bb1d7 100644 --- a/app/models/purl_resource.rb +++ b/app/models/purl_resource.rb @@ -75,9 +75,18 @@ def public_xml @public_xml ||= PublicXml.new(public_xml_document) end - # @return [String] the identifier of the collection this item is a member of - def containing_collection - @containing_collection ||= public_xml.relations('isMemberOfCollection').first + # @return [Array] the identifiers of the collections this item is a member of + def containing_collections + @containing_collections ||= public_xml.relations('isMemberOfCollection') + end + + # @return [Array] the PURL resources of the collections this item is a member of + def containing_purl_collections + @containing_purl_collections ||= containing_collections.map do |id| + PurlResource.find(id) + rescue ObjectNotReady, DruidNotValid + nil + end.compact end delegate :rights_metadata, to: :public_xml @@ -172,7 +181,7 @@ def use_and_reproduction rights.use_and_reproduction_statement end - delegate :catalog_key, to: :public_xml + delegate :catalog_key, :folio_instance_hrid, to: :public_xml delegate :released_to?, to: :public_xml diff --git a/app/views/purl/_collection.html.erb b/app/views/purl/_collection.html.erb new file mode 100644 index 00000000..60b89893 --- /dev/null +++ b/app/views/purl/_collection.html.erb @@ -0,0 +1,15 @@ +<% if document.containing_purl_collections.present? %> +
+
+

Collection

+
+
+ <% document.containing_purl_collections.each do |collection_document| %> +

<%= collection_document.title %>

+ <% if collection_document.folio_instance_hrid %> + <%= link_to('View other items in this collection in SearchWorks', "#{Settings.searchworks.url}/catalog?f[collection][]=#{collection_document.folio_instance_hrid}") %> + <% end %> + <% end %> +
+
+<% end %> \ No newline at end of file diff --git a/app/views/purl/_find_it.html.erb b/app/views/purl/_find_it.html.erb index 07bccb42..9260544c 100644 --- a/app/views/purl/_find_it.html.erb +++ b/app/views/purl/_find_it.html.erb @@ -18,7 +18,7 @@
<% 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.to_sentence.html_safe %> diff --git a/app/views/purl/_mods_metadata_sections.html.erb b/app/views/purl/_mods_metadata_sections.html.erb index 15a05ce5..1ec7c68b 100644 --- a/app/views/purl/_mods_metadata_sections.html.erb +++ b/app/views/purl/_mods_metadata_sections.html.erb @@ -4,5 +4,5 @@ <%= render "mods_subjects", document: document %> <%= render "mods_bibliographic", document: document %> <%= render "mods_contact", document: document %> +<%= render "collection", document: document %> <%= render "find_it", document: document %> - diff --git a/app/views/purl/_mods_upper_metadata_items.html.erb b/app/views/purl/_mods_upper_metadata_items.html.erb index 80779364..2ef265f7 100644 --- a/app/views/purl/_mods_upper_metadata_items.html.erb +++ b/app/views/purl/_mods_upper_metadata_items.html.erb @@ -3,8 +3,4 @@ <% document.mods.note.select { |x| x.label =~ /Preferred citation/i }.each do |notes| %> <%= mods_record_field(notes) %> <% end %> - - <% document.mods.collection.each do |collection| %> - <%= mods_record_field(collection) %> - <% end %> diff --git a/app/views/purl/show.html.erb b/app/views/purl/show.html.erb index e0db104e..77aa2f09 100644 --- a/app/views/purl/show.html.erb +++ b/app/views/purl/show.html.erb @@ -6,7 +6,7 @@ <% end %> <%= tag :link, rel: "alternate", title: "MODS XML", type: 'application/xml', href: purl_url(@purl, format: 'mods') if @purl.mods? %> <%= tag :link, rel: "alternate", title: "IIIF Manifest", type: 'application/json', href: iiif_manifest_url(@purl) if @purl.iiif_manifest? %> - <%= tag :link, rel: "up", href: purl_url(@purl.containing_collection) if @purl.containing_collection.present? %> + <%= tag :link, rel: "up", href: purl_url(@purl.containing_collections.first) if @purl.containing_collections.present? %> <%= tag :meta, name: 'citation_doi', content: @purl.doi_id if @purl.doi.present? %> <% end %> 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/features/integration_spec.rb b/spec/features/integration_spec.rb index bb834563..1f7a591c 100644 --- a/spec/features/integration_spec.rb +++ b/spec/features/integration_spec.rb @@ -90,12 +90,14 @@ expect(page).to have_metadata_section 'Contributors' expect(page).to have_metadata_section 'Subjects' expect(page).to have_metadata_section 'Bibliographic information' + expect(page).to have_metadata_section 'Collection' expect(page).to have_metadata_section 'Also listed in' end - it 'lists the collection name' do + it 'lists the collection name and links to items in collection' do visit '/cp088pb1682' expect(page).to have_content 'Bay Area video arcades : photographs by Ira Nowinski, 1981-1982' + expect(page).to have_link 'View other items in this collection in SearchWorks', href: 'https://searchworks.stanford.edu/catalog?f[collection][]=a9685083' end it 'has a link to the searchworks record' do diff --git a/spec/fixtures/document_cache/sk/882/gx/0113/mods b/spec/fixtures/document_cache/sk/882/gx/0113/mods new file mode 100644 index 00000000..2983b103 --- /dev/null +++ b/spec/fixtures/document_cache/sk/882/gx/0113/mods @@ -0,0 +1,72 @@ + + + + Bay Area video arcades : photographs by Ira Nowinski, 1981-1982 + + + Nowinski, Ira + + mixed material + + 2 boxes + + + eng + + The Bay Area video arcade photographs were taken in 1980 and 1981 at several locations in the San Francisco Bay Area. The locations include the Santa Cruz Boardwalk, the Exploratorium (site of the 1981 Atari Asteroids competition), and other arcades in Oakland and San Francisco. Materials include black & white prints and approximately 650 35mm images on contact sheets with their negatives. + Each print is identified, signed, and dated by the photographer. + Purchased, 2012 and 2016. Accessions 2012-155 and 2016-129. + + + Nowinski, Ira + + + + + Atari Asteroids Competition (San Francisco, Calif.) + + + + Photography + 1980-1990 + + + Video games + History + Pictorial works + + + Video games + Social aspects + California + San Francisco Bay Area + + + Santa Cruz Beach Boardwalk + + + 1981 + 1982 + + cau + + monographic + + + https://purl.stanford.edu/sk882gx0113 + + + Department of Special Collections, Stanford University Libraries, Stanford, CA 94305 + + + CSt + 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) + 120808 + a9685083 + + Property rights and literary rights reside with the repository. To obtain permission to publish or reproduce, please contact the Special Collections Public Services Librarian at speccollref@stanford.edu. + Copyright (c) Stanford University. All Rights Reserved. + \ No newline at end of file diff --git a/spec/fixtures/document_cache/sk/882/gx/0113/public b/spec/fixtures/document_cache/sk/882/gx/0113/public new file mode 100644 index 00000000..9a479762 --- /dev/null +++ b/spec/fixtures/document_cache/sk/882/gx/0113/public @@ -0,0 +1,135 @@ + + + + collection + Bay Area video arcades : photographs by Ira Nowinski, 1981-1982 + 9685083 + a9685083 + + + + + + + + + + + + + + Property rights and literary rights reside with the repository. To obtain permission to publish or reproduce, please contact the Special Collections Public Services Librarian at speccollref@stanford.edu. + + + + Copyright (c) Stanford University. All Rights Reserved. + + + + + + + + + + Bay Area video arcades : photographs by Ira Nowinski, 1981-1982 + Nowinski, Ira + Collection + 2 boxes + eng + The Bay Area video arcade photographs were taken in 1980 and 1981 at several locations in the San Francisco Bay Area. The locations include the Santa Cruz Boardwalk, the Exploratorium (site of the 1981 Atari Asteroids competition), and other arcades in Oakland and San Francisco. Materials include black & white prints and approximately 650 35mm images on contact sheets with their negatives. + Each print is identified, signed, and dated by the photographer. + Purchased, 2012 and 2016. Accessions 2012-155 and 2016-129. + Nowinski, Ira + Atari Asteroids Competition (San Francisco, Calif.) + Photography + 1980-1990 + Photography--1980-1990 + Video games--History + Video games--History--Pictorial works + Video games--Social aspects + California + San Francisco Bay Area + Video games--Social aspects--California--San Francisco Bay Area + + Santa Cruz Beach Boardwalk + 1981-1982 + https://purl.stanford.edu/sk882gx0113 + Open for research. Material must be requested at least 36 hours in advance of intended use. + + + + Bay Area video arcades : photographs by Ira Nowinski, 1981-1982 + + + Nowinski, Ira + + mixed material + + 2 boxes + + + eng + + The Bay Area video arcade photographs were taken in 1980 and 1981 at several locations in the San Francisco Bay Area. The locations include the Santa Cruz Boardwalk, the Exploratorium (site of the 1981 Atari Asteroids competition), and other arcades in Oakland and San Francisco. Materials include black & white prints and approximately 650 35mm images on contact sheets with their negatives. + Each print is identified, signed, and dated by the photographer. + Purchased, 2012 and 2016. Accessions 2012-155 and 2016-129. + + + Nowinski, Ira + + + + + Atari Asteroids Competition (San Francisco, Calif.) + + + + Photography + 1980-1990 + + + Video games + History + Pictorial works + + + Video games + Social aspects + California + San Francisco Bay Area + + + Santa Cruz Beach Boardwalk + + + 1981 + 1982 + + cau + + monographic + + + https://purl.stanford.edu/sk882gx0113 + + + Department of Special Collections, Stanford University Libraries, Stanford, CA 94305 + + + CSt + 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) + 120808 + a9685083 + + Property rights and literary rights reside with the repository. To obtain permission to publish or reproduce, please contact the Special Collections Public Services Librarian at speccollref@stanford.edu. + Copyright (c) Stanford University. All Rights Reserved. + + + true + true + + diff --git a/spec/fixtures/document_cache/yb/533/nc/1884/mods b/spec/fixtures/document_cache/yb/533/nc/1884/mods new file mode 100644 index 00000000..1aaef992 --- /dev/null +++ b/spec/fixtures/document_cache/yb/533/nc/1884/mods @@ -0,0 +1,20 @@ + + + + Stanford University, Cabinet, Records + + Agenda, minutes, memoranda, reports, and other records from Cabinet meetings. + + https://purl.stanford.edu/yb533nc1884 + + universityarchives@stanford.edu + + + Finding aid + + + http://www.oac.cdlib.org/findaid/ark:/13030/kt1h4nf2fr + + + 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. + diff --git a/spec/fixtures/document_cache/yb/533/nc/1884/public b/spec/fixtures/document_cache/yb/533/nc/1884/public new file mode 100644 index 00000000..519aa70e --- /dev/null +++ b/spec/fixtures/document_cache/yb/533/nc/1884/public @@ -0,0 +1,61 @@ + + + + collection + Stanford University, Cabinet, Records + 4487517 + a4487517 + sul:SC0602 + + + + + + + + + + + + + + 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. + + + + + + + + + + + Stanford University, Cabinet, Records + Agenda, minutes, memoranda, reports, and other records from Cabinet meetings. + https://purl.stanford.edu/yb533nc1884 + universityarchives@stanford.edu + Finding aid + + + + Stanford University, Cabinet, Records + + Agenda, minutes, memoranda, reports, and other records from Cabinet meetings. + + https://purl.stanford.edu/yb533nc1884 + + universityarchives@stanford.edu + + + Finding aid + + + http://www.oac.cdlib.org/findaid/ark:/13030/kt1h4nf2fr + + + 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. + + + true + + diff --git a/spec/model/purl_resource_spec.rb b/spec/model/purl_resource_spec.rb index e392cf6d..14ace674 100644 --- a/spec/model/purl_resource_spec.rb +++ b/spec/model/purl_resource_spec.rb @@ -205,8 +205,8 @@ end end - describe '#containing_collection' do - subject { instance.containing_collection } + describe '#containing_collections' do + subject { instance.containing_collections } before do allow(instance).to receive(:public_xml_body).and_return <<-EOF @@ -221,7 +221,7 @@ EOF end - it { is_expected.to eq 'jw357py5564' } + it { is_expected.to eq ['jw357py5564'] } end describe '#catalog_key' do