From 81e0a52278e0e43361d9e57198d7aea315a97680 Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Wed, 5 Jun 2024 15:18:02 +1000 Subject: [PATCH 1/5] feat: extract notes by header --- app/controllers/catalog_controller.rb | 124 ++++++++++++++++++++++---- app/models/solr_document.rb | 25 ++++-- config/locales/en.yml | 31 ++++++- 3 files changed, 154 insertions(+), 26 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 62ef9578..9c861a70 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -302,26 +302,114 @@ class CatalogController < ApplicationController config.add_summary_field "extent", field: "extent_ssm" config.add_summary_field "language", field: "language_ssim" config.add_summary_field "prefercite", field: "prefercite_html_tesm", helper_method: :render_html_tags + config.add_summary_field "cult_sens_adv_notice", + label: I18n.t("ead_notes.cult_sens_adv_notice"), + helper_method: :render_html_tags, + values: ->(_field_config, document, _context) { document.extract_notes_by_header("cult_sens_adv_notice") } + config.add_summary_field "icip_notice", + label: I18n.t("ead_notes.icip_notice"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("icip_notice") } + config.add_summary_field "sens_adv_notice", + label: I18n.t("ead_notes.sens_adv_notice"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("sens_adv_notice") } # Collection Show Page - Background Section - config.add_background_field "scopecontent", field: "scopecontent_html_tesm", helper_method: :render_html_tags - config.add_background_field "bioghist", field: "bioghist_html_tesm", helper_method: :render_html_tags - config.add_background_field "acqinfo", field: "acqinfo_ssim", helper_method: :render_html_tags - config.add_background_field "appraisal", field: "appraisal_html_tesm", helper_method: :render_html_tags - config.add_background_field "custodhist", field: "custodhist_html_tesm", helper_method: :render_html_tags - config.add_background_field "processinfo", field: "processinfo_html_tesm", helper_method: :render_html_tags - config.add_background_field "arrangement", field: "arrangement_html_tesm", helper_method: :render_html_tags - config.add_background_field "accruals", field: "accruals_html_tesm", helper_method: :render_html_tags - config.add_background_field "phystech", field: "phystech_html_tesm", helper_method: :render_html_tags - config.add_background_field "physloc", field: "physloc_html_tesm", helper_method: :render_html_tags - config.add_background_field "descrules", field: "descrules_ssm", helper_method: :render_html_tags + config.add_background_field "scope_content", + label: I18n.t("ead_notes.scope_content"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("scope_content") } + config.add_background_field "biog_hist", + label: I18n.t("ead_notes.biog_hist"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("biog_hist") } + config.add_background_field "biog", + label: I18n.t("ead_notes.biog"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("biog") } + config.add_background_field "org_hist", + label: I18n.t("ead_notes.org_hist"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("org_hist") } + config.add_background_field "general", + label: I18n.t("ead_notes.general"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("general") } + config.add_background_field "coll_retrieval_adv", + label: I18n.t("ead_notes.coll_retrieval_adv"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("coll_retrieval_adv") } + config.add_background_field "reading_room_access", + label: I18n.t("ead_notes.reading_room_access"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("reading_room_access") } + config.add_background_field "imm_source_acq", + label: I18n.t("ead_notes.imm_source_acq"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("imm_source_acq") } + config.add_background_field "provenance", + label: I18n.t("ead_notes.provenance"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("provenance") } + config.add_background_field "access_restrict", + label: I18n.t("ead_notes.access_restrict"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("access_restrict") } + config.add_background_field "access_strict", + label: I18n.t("ead_notes.access_strict"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("access_strict") } + config.add_background_field "accruals", + label: I18n.t("ead_notes.accruals"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("accruals") } + config.add_background_field "arrangement", + label: I18n.t("ead_notes.arrangement"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("arrangement") } + config.add_background_field "listing_rehousing", + label: I18n.t("ead_notes.listing_rehousing"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("listing_rehousing") } + config.add_background_field "custod_hist", + label: I18n.t("ead_notes.custod_hist"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("custod_hist") } + config.add_background_field "dimensions", + label: I18n.t("ead_notes.dimensions"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("dimensions") } + config.add_background_field "material_spec", + label: I18n.t("ead_notes.material_spec"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("material_spec") } + config.add_background_field "phys_desc", + label: I18n.t("ead_notes.phys_desc"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("phys_desc") } # Collection Show Page - Related Section - config.add_related_field "relatedmaterial", field: "relatedmaterial_html_tesm", helper_method: :render_html_tags - config.add_related_field "separatedmaterial", field: "separatedmaterial_html_tesm", helper_method: :render_html_tags - config.add_related_field "otherfindaid", field: "otherfindaid_html_tesm", helper_method: :render_html_tags - config.add_related_field "altformavail", field: "altformavail_html_tesm", helper_method: :render_html_tags - config.add_related_field "originalsloc", field: "originalsloc_html_tesm", helper_method: :render_html_tags + config.add_related_field "related_material", + label: I18n.t("ead_notes.related_material"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("related_material") } + config.add_related_field "separated_material", + label: I18n.t("ead_notes.separated_material"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("separated_material") } + config.add_related_field "other_find_aid", + label: I18n.t("ead_notes.other_find_aid"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("other_find_aid") } + config.add_related_field "alt_form_avail", + label: I18n.t("ead_notes.alt_form_avail"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("alt_form_avail") } + config.add_related_field "origs_loc", + label: I18n.t("ead_notes.origs_loc"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("origs_loc") } # Collection Show Page - Indexed Terms Section config.add_indexed_terms_field "access_subjects", field: "access_subjects_ssim", link_to_facet: true, separator_options: { @@ -354,7 +442,7 @@ class CatalogController < ApplicationController }, if: lambda { |_context, _field_config, document| document.containers.present? } - config.add_component_field "collectionidentifier", field: "collection_identifier", accessor: :collection_identifier, helper_method: :render_html_tags + config.add_component_field "collectionidentifier", accessor: :collection_identifier, helper_method: :render_html_tags config.add_component_field "abstract", field: "abstract_html_tesm", helper_method: :render_html_tags config.add_component_field "extent", field: "extent_ssm" config.add_component_field "scopecontent", field: "scopecontent_html_tesm", helper_method: :render_html_tags @@ -366,7 +454,7 @@ class CatalogController < ApplicationController config.add_component_field "accruals", field: "accruals_html_tesm", helper_method: :render_html_tags config.add_component_field "phystech", field: "phystech_html_tesm", helper_method: :render_html_tags config.add_component_field "physloc", field: "physloc_html_tesm", helper_method: :render_html_tags - config.add_component_field "extentsinfo", field: "extents_information", accessor: :extents_information, helper_method: :render_html_tags + config.add_component_field "extentsinfo", accessor: :extents_information, helper_method: :render_html_tags # Component Show Page - Indexed Terms Section config.add_component_indexed_terms_field "access_subjects", field: "access_subjects_ssim", link_to_facet: true, separator_options: { diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 4f81b2f9..8106ebe7 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -7,6 +7,16 @@ class SolrDocument # alias this field for the request link attribute :bibid, :string, "bibid_ssi" + # attribute :notes, :array, "notes_tesim" + + # self.unique_key = 'id' + + # DublinCore uses the semantic field mappings below to assemble an OAI-compliant Dublin Core document + # Semantic mappings of solr stored fields. Fields may be multi or + # single valued. See Blacklight::Document::SemanticFields#field_semantics + # and Blacklight::Document::SemanticFields#to_semantic_values + # Recommendation: Use field names from Dublin Core + use_extension(Blacklight::Document::DublinCore) def collection_identifier [self["level_ssm"]&.join(" "), self["unitid_ssm"]&.join(" ")].compact.join(" ") @@ -30,12 +40,13 @@ def extents_information end end - # self.unique_key = 'id' + def extract_notes_by_header(header) + notes.select { |note| JSON.parse(note)["head"] == I18n.t("ead_notes.#{header}") }.map { |note| JSON.parse(note)["p"] }.flatten + end - # DublinCore uses the semantic field mappings below to assemble an OAI-compliant Dublin Core document - # Semantic mappings of solr stored fields. Fields may be multi or - # single valued. See Blacklight::Document::SemanticFields#field_semantics - # and Blacklight::Document::SemanticFields#to_semantic_values - # Recommendation: Use field names from Dublin Core - use_extension(Blacklight::Document::DublinCore) + private + + def notes + ["{\"head\":\"Cultural Sensitivity Advisory Notice\", \"p\":[\"This is a paragraph\", \"This is another paragraph\"]}", "{\"head\":\"Immediate source of acquisition\", \"p\":[\"This is a paragraph\", \"This is another paragraph\"]}"] + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7fb3f36d..ab814897 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -32,4 +32,33 @@ en: request_this: "Request this via the Catalogue" hello: "Hello world" - collection_prefix: "Guide to the " \ No newline at end of file + collection_prefix: "Guide to the " + ead_notes: + cult_sens_adv_notice: "Cultural Sensitivity Advisory Notice" + icip_notice: "Indigenous Cultural and Intellectual Property (ICIP) Notice" + sens_adv_notice: "Sensitivity Advisory Notice" + content_summary: "Content Summary" + scope_content: "Content Summary" + biog_hist: "Biographical / Historical" + biog: "Biographical Note" + org_hist: "Organisational History Note" + general: "General" + coll_retrieval_adv: "Collection Retrieval Advice" + reading_room_access: "Reading Room Access Note" + imm_source_acq: "Immediate Source of Acquisition" + provenance: "Provenance" + access_restrict: "Conditions Governing Access" + access_strict: "Conditions Governing Use" + accruals: "Accruals" + arrangement: "Arrangement" + listing_rehousing: "Listing and Rehousing Note" + custod_hist: "Custodial History" + dimensions: "Dimensions" + alt_form_avail: "Existence and Location of Copies" + origs_loc: "Existence and Location of Originals" + material_spec: "Materials Specific Details" + other_find_aid: "Other Finding Aids" + phys_desc: "Physical Description" + related_material: "Related Materials" + separated_material: "Separated Materials" + From 5fffcc5fe3876fc3aa24781c4ef2aa8cbf08241e Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Thu, 6 Jun 2024 11:25:06 +1000 Subject: [PATCH 2/5] feat: extract EAD notes by header --- app/models/solr_document.rb | 30 ++++++++++------- config/locales/en.yml | 2 +- .../breadcrumbs_hierarchy_component_spec.rb | 18 +++++------ spec/models/solr_document_spec.rb | 32 +++++++++++++++++++ 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 8106ebe7..950a98d2 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -7,7 +7,17 @@ class SolrDocument # alias this field for the request link attribute :bibid, :string, "bibid_ssi" - # attribute :notes, :array, "notes_tesim" + attribute :physdesc_quantity, :string, "physdesc_quantity_ssi" + attribute :physdesc_unittype, :string, "physdesc_unittype_ssi" + attribute :physdesc_dimensions, :string, "physdesc_dimensions_ssi" + attribute :physdesc_facet, :string, "physdesc_facet_ssi" + attribute :notes, :array, "note_json_ssm" + + # **** BEWARE! **** + # Arclight aliases "level_ssm" and "unitid_ssm" fields to String type attributes in the + # Arclight::SolrDocument concern. This means, if there are multiple values for these fields, + # calling the attribute alias will only return the first value. + # MAKE SURE YOU'RE NOT LOSING DATA BY CALLING THE ALIAS INSTEAD OF DIRECTLY ACCESSING THE FIELD! # self.unique_key = 'id' @@ -24,13 +34,13 @@ def collection_identifier def extents_information quantity_unittype = [ - self["physdesc_quantity_ssi"], - self["physdesc_unittype_ssi"] + physdesc_quantity, + physdesc_unittype ].compact.join(" ") dimensions_facet = [ - self["physdesc_dimensions_ssi"], - self["physdesc_facet_ssi"] + physdesc_dimensions, + physdesc_facet ].compact.join(", ") if quantity_unittype.blank? @@ -41,12 +51,8 @@ def extents_information end def extract_notes_by_header(header) - notes.select { |note| JSON.parse(note)["head"] == I18n.t("ead_notes.#{header}") }.map { |note| JSON.parse(note)["p"] }.flatten - end - - private - - def notes - ["{\"head\":\"Cultural Sensitivity Advisory Notice\", \"p\":[\"This is a paragraph\", \"This is another paragraph\"]}", "{\"head\":\"Immediate source of acquisition\", \"p\":[\"This is a paragraph\", \"This is another paragraph\"]}"] + notes.select { |note| JSON.parse(note)["head"] == I18n.t("ead_notes.#{header}") } + .map { |note| JSON.parse(note)["p"] } + .flatten end end diff --git a/config/locales/en.yml b/config/locales/en.yml index ab814897..aec24690 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -38,7 +38,7 @@ en: icip_notice: "Indigenous Cultural and Intellectual Property (ICIP) Notice" sens_adv_notice: "Sensitivity Advisory Notice" content_summary: "Content Summary" - scope_content: "Content Summary" + scope_contents: "Scope and Contents" biog_hist: "Biographical / Historical" biog: "Biographical Note" org_hist: "Organisational History Note" diff --git a/spec/components/arclight/breadcrumbs_hierarchy_component_spec.rb b/spec/components/arclight/breadcrumbs_hierarchy_component_spec.rb index 25abbec4..4ecb03ee 100644 --- a/spec/components/arclight/breadcrumbs_hierarchy_component_spec.rb +++ b/spec/components/arclight/breadcrumbs_hierarchy_component_spec.rb @@ -6,10 +6,10 @@ let(:document) do SolrDocument.new( ead_ssi: "abc123", - repository_ssm: "National Library of Australia", + repository_ssm: ["National Library of Australia"], _root_: "abc123", - normalized_title_ssm: "ABC123", - level_ssm: "collection" + normalized_title_ssm: ["ABC123"], + level_ssm: ["collection"] ) end let(:view_context) { ActionView::Base.new(nil, {}, nil) } @@ -33,10 +33,10 @@ parent_unittitles_ssm: %w[ABC123 DEF], parent_levels_ssm: %w[collection Series], ead_ssi: "abc123", - repository_ssm: "National Library of Australia", + repository_ssm: ["National Library of Australia"], _root_: "abc123", - normalized_title_ssm: "GHI", - level_ssm: "Subseries" + normalized_title_ssm: ["GHI"], + level_ssm: ["Subseries"] ) end @@ -62,10 +62,10 @@ parent_unittitles_ssm: %w[ABC123 DEF GHI], parent_levels_ssm: %w[collection Series Subseries], ead_ssi: "abc123", - repository_ssm: "National Library of Australia", + repository_ssm: ["National Library of Australia"], _root_: "abc123", - normalized_title_ssm: "JKL", - level_ssm: "file" + normalized_title_ssm: ["JKL"], + level_ssm: ["file"] ) end diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index 0bf42618..a1069674 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -113,4 +113,36 @@ end end end + + describe "#extract_notes_by_header" do + let(:document) do + described_class.new( + note_json_ssm: ["{\"head\":\"Conditions Governing Access\",\"p\":\"Please refer to the collection's catalogue record for the access conditions (http://nla.gov.au/nla.cat-vn1132324).\",\"audience\":\"internal\"}", + "{\"head\":\"References\",\"p\":[\"References used in the creation of this finding aid include:\",\"Australian colonial currency and promissory notes by Michael P. Vort-Ronald, second edition, 2012 and Standard catalogue of world paper money by Albert Pick, vol 2, c1990.\"],\"audience\":\"internal\"}", + "{\"head\":\"Scope and Contents\",\"p\":\"Includes merchants' promissory notes, Fijian treasury notes and money issued in \\\"New Australia\\\", Paraguay.\",\"audience\":\"internal\"}", + "{\"head\":\"Conditions Governing Use\",\"p\":\"Copying and publishing of unpublished manuscript material is subject to copyright restrictions. For such material, written permission to publish must be obtained from the copyright holder(s). Copying of unpublished material for research purposes is permissible 50 years after the death of the creator of the material.\",\"audience\":\"internal\"}", + "{\"head\":\"Immediate Source of Acquisition\",\"p\":\"Acquired from Tyrrell's Antiquarian Bookshop, Sydney, in 1953.\",\"audience\":\"internal\"}"] + ) + end + + context "when notes contains a note with a header matching a localised string literal" do + subject(:notes_value) do + document.extract_notes_by_header("scope_contents") + end + + it "returns the notes with the matching header" do + expect(notes_value).to eq ["Includes merchants' promissory notes, Fijian treasury notes and money issued in \"New Australia\", Paraguay."] + end + end + + context "when notes does not contain a note with a header matching a localised string literal" do + subject(:notes_value) do + document.extract_notes_by_header("coll_retrieval_adv") + end + + it "returns an empty array" do + expect(notes_value).to eq [] + end + end + end end From 04cf925b87c82d8257ce134372e3625d2fdcd448 Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Thu, 6 Jun 2024 12:50:45 +1000 Subject: [PATCH 3/5] fix: translate Scope and Contents heading --- app/controllers/catalog_controller.rb | 6 +++--- app/models/solr_document.rb | 6 ++++++ config/locales/en.yml | 5 ++--- spec/models/solr_document_spec.rb | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 9c861a70..f4e21999 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -303,9 +303,9 @@ class CatalogController < ApplicationController config.add_summary_field "language", field: "language_ssim" config.add_summary_field "prefercite", field: "prefercite_html_tesm", helper_method: :render_html_tags config.add_summary_field "cult_sens_adv_notice", - label: I18n.t("ead_notes.cult_sens_adv_notice"), + label: I18n.t("ead_notes.cultural_sens_adv_notice"), helper_method: :render_html_tags, - values: ->(_field_config, document, _context) { document.extract_notes_by_header("cult_sens_adv_notice") } + values: ->(_field_config, document, _context) { document.extract_notes_by_header("cultural_sens_adv_notice") } config.add_summary_field "icip_notice", label: I18n.t("ead_notes.icip_notice"), helper_method: :render_html_tags, @@ -319,7 +319,7 @@ class CatalogController < ApplicationController config.add_background_field "scope_content", label: I18n.t("ead_notes.scope_content"), helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("scope_content") } + values: ->(__field_config, document, _context) { document.scope_contents } config.add_background_field "biog_hist", label: I18n.t("ead_notes.biog_hist"), helper_method: :render_html_tags, diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 950a98d2..4ea383d3 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -50,6 +50,12 @@ def extents_information end end + def scope_contents + notes.select { |note| JSON.parse(note)["head"] == "Scope and Contents" } + .map { |note| JSON.parse(note)["p"] } + .flatten + end + def extract_notes_by_header(header) notes.select { |note| JSON.parse(note)["head"] == I18n.t("ead_notes.#{header}") } .map { |note| JSON.parse(note)["p"] } diff --git a/config/locales/en.yml b/config/locales/en.yml index aec24690..f235b894 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,11 +34,10 @@ en: hello: "Hello world" collection_prefix: "Guide to the " ead_notes: - cult_sens_adv_notice: "Cultural Sensitivity Advisory Notice" + cultural_sens_adv_notice: "Cultural Sensitivity Advisory Notice" icip_notice: "Indigenous Cultural and Intellectual Property (ICIP) Notice" sens_adv_notice: "Sensitivity Advisory Notice" - content_summary: "Content Summary" - scope_contents: "Scope and Contents" + scope_contents: "Content Summary" biog_hist: "Biographical / Historical" biog: "Biographical Note" org_hist: "Organisational History Note" diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index a1069674..3087157a 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -127,7 +127,7 @@ context "when notes contains a note with a header matching a localised string literal" do subject(:notes_value) do - document.extract_notes_by_header("scope_contents") + document.scope_contents end it "returns the notes with the matching header" do From e3df0117f40e2f381920d43a08f19d5db8970834 Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Thu, 6 Jun 2024 14:33:29 +1000 Subject: [PATCH 4/5] feat: compare note headings using parameterized values --- app/models/solr_document.rb | 3 ++- spec/models/solr_document_spec.rb | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 4ea383d3..252020d8 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -57,7 +57,8 @@ def scope_contents end def extract_notes_by_header(header) - notes.select { |note| JSON.parse(note)["head"] == I18n.t("ead_notes.#{header}") } + # compares against the parameterized value of the header to ignore case and punctuation + notes.select { |note| JSON.parse(note)["head"].parameterize == I18n.t("ead_notes.#{header}").parameterize } .map { |note| JSON.parse(note)["p"] } .flatten end diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index 3087157a..2e6076da 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -125,7 +125,7 @@ ) end - context "when notes contains a note with a header matching a localised string literal" do + context "when notes contains 'Scope and Contents'" do subject(:notes_value) do document.scope_contents end @@ -135,6 +135,16 @@ end end + context "when notes contains a note with a header matching a localised string literal" do + subject(:notes_value) do + document.extract_notes_by_header("access_strict") + end + + it "returns the notes with the matching header" do + expect(notes_value.join).to include "Copying and publishing of unpublished manuscript material is subject to copyright restrictions." + end + end + context "when notes does not contain a note with a header matching a localised string literal" do subject(:notes_value) do document.extract_notes_by_header("coll_retrieval_adv") @@ -144,5 +154,19 @@ expect(notes_value).to eq [] end end + + context "when header literal contains punctuation" do + subject(:notes_value) do + document = described_class.new( + note_json_ssm: ["{\"head\":\"Biographical / Historical\",\"p\":\"Testing\",\"audience\":\"internal\"}"] + ) + + document.extract_notes_by_header("biog_hist") + end + + it "returns the notes with the matching header" do + expect(notes_value).to eq ["Testing"] + end + end end end From 07cac10cb2a033afe35ad0d8cd29c0d16735495f Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Thu, 6 Jun 2024 16:32:16 +1000 Subject: [PATCH 5/5] feat: refine display and formatting of notes --- app/controllers/catalog_controller.rb | 76 ++++++++------------------- app/models/solr_document.rb | 9 ++-- config/locales/arclight.en.yml | 24 ++++----- config/locales/en.yml | 10 +--- spec/models/solr_document_spec.rb | 16 ++---- 5 files changed, 40 insertions(+), 95 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index f4e21999..1738ed53 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -316,10 +316,7 @@ class CatalogController < ApplicationController values: ->(__field_config, document, _context) { document.extract_notes_by_header("sens_adv_notice") } # Collection Show Page - Background Section - config.add_background_field "scope_content", - label: I18n.t("ead_notes.scope_content"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.scope_contents } + config.add_background_field "scopecontent", field: "scopecontent_html_tesm", helper_method: :render_html_tags config.add_background_field "biog_hist", label: I18n.t("ead_notes.biog_hist"), helper_method: :render_html_tags, @@ -348,22 +345,15 @@ class CatalogController < ApplicationController label: I18n.t("ead_notes.imm_source_acq"), helper_method: :render_html_tags, values: ->(__field_config, document, _context) { document.extract_notes_by_header("imm_source_acq") } + config.add_background_field "references", + label: I18n.t("ead_notes.references"), + helper_method: :render_html_tags, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("references") } config.add_background_field "provenance", label: I18n.t("ead_notes.provenance"), helper_method: :render_html_tags, values: ->(__field_config, document, _context) { document.extract_notes_by_header("provenance") } - config.add_background_field "access_restrict", - label: I18n.t("ead_notes.access_restrict"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("access_restrict") } - config.add_background_field "access_strict", - label: I18n.t("ead_notes.access_strict"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("access_strict") } - config.add_background_field "accruals", - label: I18n.t("ead_notes.accruals"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("accruals") } + config.add_background_field "accruals", field: "accruals_html_tesm", label: I18n.t("ead_notes.accruals"), helper_method: :render_html_tags config.add_background_field "arrangement", label: I18n.t("ead_notes.arrangement"), helper_method: :render_html_tags, @@ -372,44 +362,17 @@ class CatalogController < ApplicationController label: I18n.t("ead_notes.listing_rehousing"), helper_method: :render_html_tags, values: ->(__field_config, document, _context) { document.extract_notes_by_header("listing_rehousing") } - config.add_background_field "custod_hist", - label: I18n.t("ead_notes.custod_hist"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("custod_hist") } - config.add_background_field "dimensions", - label: I18n.t("ead_notes.dimensions"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("dimensions") } - config.add_background_field "material_spec", - label: I18n.t("ead_notes.material_spec"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("material_spec") } - config.add_background_field "phys_desc", - label: I18n.t("ead_notes.phys_desc"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("phys_desc") } + config.add_background_field "custodhist", field: "custodhist_html_tesm", helper_method: :render_html_tags + config.add_background_field "physdesc_dimensions", field: "physdesc_dimensions_ssi", label: I18n.t("ead_notes.dimensions"), helper: :render_html_tags + config.add_background_field "materialspec", field: "meterialspec_tesim", label: I18n.t("ead_notes.material_spec"), helper: :render_html_tags + config.add_background_field "physdesc", field: "physdesc_facet_ssi", label: I18n.t("ead_notes.phys_desc"), helper: :render_html_tags # Collection Show Page - Related Section - config.add_related_field "related_material", - label: I18n.t("ead_notes.related_material"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("related_material") } - config.add_related_field "separated_material", - label: I18n.t("ead_notes.separated_material"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("separated_material") } - config.add_related_field "other_find_aid", - label: I18n.t("ead_notes.other_find_aid"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("other_find_aid") } - config.add_related_field "alt_form_avail", - label: I18n.t("ead_notes.alt_form_avail"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("alt_form_avail") } - config.add_related_field "origs_loc", - label: I18n.t("ead_notes.origs_loc"), - helper_method: :render_html_tags, - values: ->(__field_config, document, _context) { document.extract_notes_by_header("origs_loc") } + config.add_related_field "relatedmaterial", field: "relatedmaterial_html_tesm", helper_method: :render_html_tags + config.add_related_field "separatedmaterial", field: "separatedmaterial_html_tesm", helper_method: :render_html_tags + config.add_related_field "otherfindaid", field: "otherfindaid_html_tesm", helper_method: :render_html_tags + config.add_related_field "altformavail", field: "altformavail_html_tesm", helper_method: :render_html_tags + config.add_related_field "originalsloc", field: "originalsloc_html_tesm", helper_method: :render_html_tags # Collection Show Page - Indexed Terms Section config.add_indexed_terms_field "access_subjects", field: "access_subjects_ssim", link_to_facet: true, separator_options: { @@ -442,19 +405,22 @@ class CatalogController < ApplicationController }, if: lambda { |_context, _field_config, document| document.containers.present? } - config.add_component_field "collectionidentifier", accessor: :collection_identifier, helper_method: :render_html_tags + config.add_component_field "collectionidentifier", field: "collection_identifier", accessor: :collection_identifier, helper_method: :render_html_tags config.add_component_field "abstract", field: "abstract_html_tesm", helper_method: :render_html_tags config.add_component_field "extent", field: "extent_ssm" config.add_component_field "scopecontent", field: "scopecontent_html_tesm", helper_method: :render_html_tags config.add_component_field "acqinfo", field: "acqinfo_ssim", helper_method: :render_html_tags config.add_component_field "appraisal", field: "appraisal_html_tesm", helper_method: :render_html_tags - config.add_component_field "custodhist", field: "custodhist_html_tesm", helper_method: :render_html_tags + config.add_component_field "custodhist", field: "custodhist_html_tesm", label: I18n.t("ead_notes.custod_hist"), helper_method: :render_html_tags config.add_component_field "processinfo", field: "processinfo_html_tesm", helper_method: :render_html_tags config.add_component_field "arrangement", field: "arrangement_html_tesm", helper_method: :render_html_tags config.add_component_field "accruals", field: "accruals_html_tesm", helper_method: :render_html_tags config.add_component_field "phystech", field: "phystech_html_tesm", helper_method: :render_html_tags config.add_component_field "physloc", field: "physloc_html_tesm", helper_method: :render_html_tags - config.add_component_field "extentsinfo", accessor: :extents_information, helper_method: :render_html_tags + config.add_component_field "extentsinfo", field: "extents_information", accessor: :extents_information, helper_method: :render_html_tags + config.add_component_field "physdesc_dimensions", field: "physdesc_dimensions_ssi", label: I18n.t("ead_notes.dimensions"), helper: :render_html_tags + config.add_component_field "materialspec", field: "meterialspec_tesim", label: I18n.t("ead_notes.material_spec"), helper: :render_html_tags + config.add_component_field "physdesc", field: "physdesc_facet_ssi", label: I18n.t("ead_notes.phys_desc"), helper: :render_html_tags # Component Show Page - Indexed Terms Section config.add_component_indexed_terms_field "access_subjects", field: "access_subjects_ssim", link_to_facet: true, separator_options: { diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 252020d8..a1c258c2 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -50,16 +50,13 @@ def extents_information end end - def scope_contents - notes.select { |note| JSON.parse(note)["head"] == "Scope and Contents" } - .map { |note| JSON.parse(note)["p"] } - .flatten - end - def extract_notes_by_header(header) # compares against the parameterized value of the header to ignore case and punctuation + # rubocop:disable Rails/OutputSafety notes.select { |note| JSON.parse(note)["head"].parameterize == I18n.t("ead_notes.#{header}").parameterize } .map { |note| JSON.parse(note)["p"] } .flatten + .map { |para| "

#{para}

".html_safe } + # rubocop:enable Rails/OutputSafety end end diff --git a/config/locales/arclight.en.yml b/config/locales/arclight.en.yml index 403c7efc..6737e188 100644 --- a/config/locales/arclight.en.yml +++ b/config/locales/arclight.en.yml @@ -11,11 +11,11 @@ en: collectionidentifier: Component identifier - scopecontent: Scope and content - bioghist: Biographical / historical + scopecontent: Content Summary + bioghist: Biographical / Historical acqinfo: Immediate source of acquisition appraisal: Appraisal information - custodhist: Custodial history + custodhist: Custodial History processinfo: Processing information arrangement: Arrangement accruals: Accruals @@ -24,11 +24,11 @@ en: descrules: Rules or conventions extentsinfo: Extent information - relatedmaterial: Related material - separatedmaterial: Separated material - otherfindaid: Other finding aids - altformavail: Existence and location of copies - originalsloc: Existence and location of originals + relatedmaterial: Related Material + separatedmaterial: Separated Material + otherfindaid: Other Finding Aids + altformavail: Existence and Location of Copies + originalsloc: Existence and Location of Originals access_subjects: Subjects names_coll: Names @@ -37,10 +37,10 @@ en: containers: Containers names: Names - restrictions: Conditions governing access - terms: Conditions governing use - parent_restrictions: Parent restrictions - parent_terms: Parent terms of access + restrictions: Conditions Governing Access + terms: Conditions Governing Use + parent_restrictions: Parent Restrictions + parent_terms: Parent Terms of Access repository_location: Location of this collection before_you_visit: Before you visit repository_contact: Contact diff --git a/config/locales/en.yml b/config/locales/en.yml index f235b894..a76880d8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,19 +45,11 @@ en: coll_retrieval_adv: "Collection Retrieval Advice" reading_room_access: "Reading Room Access Note" imm_source_acq: "Immediate Source of Acquisition" + references: "References" provenance: "Provenance" - access_restrict: "Conditions Governing Access" - access_strict: "Conditions Governing Use" - accruals: "Accruals" arrangement: "Arrangement" listing_rehousing: "Listing and Rehousing Note" - custod_hist: "Custodial History" dimensions: "Dimensions" - alt_form_avail: "Existence and Location of Copies" - origs_loc: "Existence and Location of Originals" material_spec: "Materials Specific Details" - other_find_aid: "Other Finding Aids" phys_desc: "Physical Description" - related_material: "Related Materials" - separated_material: "Separated Materials" diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index 2e6076da..a2baf5fe 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -125,23 +125,13 @@ ) end - context "when notes contains 'Scope and Contents'" do - subject(:notes_value) do - document.scope_contents - end - - it "returns the notes with the matching header" do - expect(notes_value).to eq ["Includes merchants' promissory notes, Fijian treasury notes and money issued in \"New Australia\", Paraguay."] - end - end - context "when notes contains a note with a header matching a localised string literal" do subject(:notes_value) do - document.extract_notes_by_header("access_strict") + document.extract_notes_by_header("imm_source_acq") end it "returns the notes with the matching header" do - expect(notes_value.join).to include "Copying and publishing of unpublished manuscript material is subject to copyright restrictions." + expect(notes_value.join).to include "Acquired from Tyrrell's Antiquarian Bookshop, Sydney, in 1953." end end @@ -165,7 +155,7 @@ end it "returns the notes with the matching header" do - expect(notes_value).to eq ["Testing"] + expect(notes_value).to eq ["

Testing

"] end end end