Skip to content

Commit

Permalink
update publication_presenter/solr_document to use solr std/local ids
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Nov 18, 2019
1 parent 8e7dc73 commit f62ba34
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 38 deletions.
2 changes: 2 additions & 0 deletions app/models/concerns/spot/solr_document_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module SolrDocumentAttributes
attribute :language, ::Blacklight::Types::Array, 'language_ssim'
attribute :language_label, ::Blacklight::Types::Array, 'language_label_ssim'
attribute :license, ::Blacklight::Types::Array, 'license_ssim'
attribute :local_identifier, ::Blacklight::Types::Array, 'identifier_local_ssim'
attribute :location, ::Blacklight::Types::Array, 'location_ssim'
attribute :location_label, ::Blacklight::Types::Array, 'location_label_ssim'
attribute :note, ::Blacklight::Types::Array, 'note_tesim'
Expand All @@ -54,6 +55,7 @@ module SolrDocumentAttributes
attribute :rights_statement_label, ::Blacklight::Types::Array, 'rights_statement_label_ssim'
attribute :source, ::Blacklight::Types::Array, 'source_tesim'
attribute :sponsor, ::Blacklight::Types::Array, 'sponsor_tesim'
attribute :standard_identifier, ::Blacklight::Types::Array, 'identifier_standard_ssim'
attribute :subject, ::Blacklight::Types::Array, 'subject_tesim'
attribute :subtitle, ::Blacklight::Types::Array, 'subtitle_tesim'
attribute :title, ::Blacklight::Types::Array, 'title_tesim'
Expand Down
15 changes: 4 additions & 11 deletions app/presenters/hyrax/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class PublicationPresenter < Hyrax::WorkShowPresenter
delegate :abstract, :academic_department, :bibliographic_citation,
:contributor, :creator, :date_issued, :date_available,
:division, :editor, :keyword, :language, :language_label,
:organization, :permalink, :publisher, :resource_type,
:source, :subject, :subtitle, :title_alternative,
:organization, :permalink, :publisher, :resource_type, :source,
:subject, :subtitle, :title_alternative,
to: :solr_document

# @return [String]
Expand All @@ -23,16 +23,9 @@ def export_formats
%i[csv ttl nt jsonld]
end

# Our document's identifiers mapped to Spot::Identifier objects
#
# @return [Array<Spot::Identifier>]
def identifier
@identifier ||= solr_document.identifier.map { |str| Spot::Identifier.from_string(str) }
end

# @return [Array<Spot::Identifier>]
def local_identifier
@local_identifier ||= identifier.select(&:local?)
@local_identifier ||= solr_document.local_identifier.map { |id| Spot::Identifier.from_string(id) }
end

# location values + labels zipped into tuples.
Expand Down Expand Up @@ -73,7 +66,7 @@ def rights_statement_merged

# @return [Array<Spot::Identifier>]
def standard_identifier
@standard_identifier ||= identifier.select(&:standard?)
@standard_identifier ||= solr_document.standard_identifier.map { |id| Spot::Identifier.from_string(id) }
end

# For now, overriding the ability to feature individual works
Expand Down
15 changes: 0 additions & 15 deletions app/views/shared/metadata/_identifiers.html.erb

This file was deleted.

8 changes: 5 additions & 3 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
editor: { type: Array, suffix: 'tesim' },
file_set_ids: { type: Array, suffix: 'ssim', value: ['abc123', 'def456'] },
file_size: { type: String, suffix: 'lts' },
identifier: { type: Array, suffix: 'ssim' },
keyword: { type: Array, suffix: 'tesim' },
language: { type: Array, suffix: 'ssim' },
language_label: { type: Array, suffix: 'ssim' },
license: { type: Array, suffix: 'ssim' },
local_identifier: { type: Array, key: 'identifier_local_ssim' },
location: { type: Array, suffix: 'ssim' },
location_label: { type: Array, suffix: 'ssim' },
note: { type: Array, suffix: 'tesim' },
Expand All @@ -47,6 +47,7 @@
rights_statement_label: { type: Array, suffix: 'ssim' },
source: { type: Array, suffix: 'tesim' },
sponsor: { type: Array, suffix: 'tesim' },
standard_identifier: { type: Array, key: 'identifier_standard_ssim' },
subject: { type: Array, suffix: 'tesim' },
subtitle: { type: Array, suffix: 'tesim' },
title: { type: Array, suffix: 'tesim' },
Expand All @@ -59,9 +60,10 @@
config[:expected] || (config[:type] == Array ? Array(value) : Array(value).first)
end

let(:doc_key) { config[:key] || "#{key}_#{config[:suffix]}" }
let(:_value) { config[:value] || 'a test value' }
let(:value) { config[:suffix].ends_with?('m') ? Array(_value) : _value }
let(:metadata) { { "#{key}_#{config[:suffix]}" => value } }
let(:value) { doc_key.ends_with?('m') ? Array(_value) : _value }
let(:metadata) { { doc_key => value } }

it { is_expected.to be_a config[:type] }
it { is_expected.to eq expected }
Expand Down
16 changes: 8 additions & 8 deletions spec/presenters/hyrax/publication_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,16 @@
let(:raw_ids) { ['issn:1234-5678', 'abc:123'] }
let(:object) { build(:publication, identifier: raw_ids) }

describe '#identifier' do
subject(:ids) { presenter.identifier }

it 'maps identifiers to Spot::Identifier objects' do
expect(ids.all? { |id| id.is_a? Spot::Identifier }).to be true
end
end

describe '#local_identifier' do
subject(:ids) { presenter.local_identifier }

it 'returns only the identifiers that return true to #local?' do
expect(ids.map(&:to_s)).to eq ['abc:123']
end

it 'maps identifiers to Spot::Identifier objects' do
expect(ids.all? { |id| id.is_a? Spot::Identifier }).to be true
end
end

describe '#standard_identifier' do
Expand All @@ -57,6 +53,10 @@
it 'returns only the identifiers that return true to #standard?' do
expect(ids.map(&:to_s)).to eq ['issn:1234-5678']
end

it 'maps identifiers to Spot::Identifier objects' do
expect(ids.all? { |id| id.is_a? Spot::Identifier }).to be true
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
RSpec.shared_examples 'it indexes standard and local identifiers' do
subject(:solr_doc) { indexer.generate_solr_document }

let(:indexer) { described_class.new(work)}
let(:indexer) { described_class.new(work) }
let(:work_klass) { described_class.name.gsub(/Indexer$/, '').downcase.to_sym }
let(:work) { build(work_klass, identifier: identifier) }

Expand Down

0 comments on commit f62ba34

Please sign in to comment.