Skip to content

Commit

Permalink
Merge pull request #5848 from avalonmediasystem/more_json
Browse files Browse the repository at this point in the history
Make media object json response consistent between SpeedyAF proxy and ActiveFedora object
  • Loading branch information
cjcolvar authored Jun 10, 2024
2 parents c149610 + 80cc308 commit aaef4ce
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/media_object_mods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def alternative_title=(value)

# has_attributes :translated_title, datastream: :descMetadata, at: [:translated_title], multiple: true
def translated_title
descMetadata.alternative_title
descMetadata.translated_title
end

def translated_title=(value)
Expand Down
1 change: 1 addition & 0 deletions app/models/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ def to_solr(include_child_fields: false)
solr_doc["creator_ssort"] = Array(self.creator).join(', ')
solr_doc["date_ingested_ssim"] = self.create_date.strftime "%F" if self.create_date.present?
solr_doc['avalon_resource_type_ssim'] = self.avalon_resource_type
# Downcasing identifier allows for case-insensitive searching but has the side effect of causing all identiiers to be lower case in JSON responses
solr_doc['identifier_ssim'] = self.identifier.map(&:downcase)
solr_doc['note_ssm'] = self.note.collect { |n| n.to_json }
solr_doc['other_identifier_ssm'] = self.other_identifier.collect { |oi| oi.to_json }
Expand Down
13 changes: 10 additions & 3 deletions app/models/mods_behaviors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ def to_solr(solr_doc = Hash.new, opts = {})
end
solr_doc['title_addl_sim'] = gather_terms(addl_titles)
solr_doc['heading_sim'] = self.find_by_terms(:main_title).text

solr_doc['uniform_title_ssim'] = gather_terms(self.find_by_terms(:uniform_title))
solr_doc['alternative_title_ssim'] = gather_terms(self.find_by_terms(:alternative_title))
solr_doc['translated_title_ssim'] = gather_terms(self.find_by_terms(:translated_title))

solr_doc['creator_ssim'] = gather_terms(self.find_by_terms(:creator))
# solr_doc['creator_ssi'] = self.find_by_terms(:creator).text
# Individual fields
solr_doc['abstract_ssi'] = self.find_by_terms(:abstract).text
solr_doc['publisher_ssim'] = gather_terms(self.find_by_terms(:publisher))
solr_doc['contributor_ssim'] = gather_terms(self.find_by_terms(:contributor))
solr_doc['subject_ssim'] = gather_terms(self.find_by_terms(:subject))
solr_doc['subject_ssim'] = gather_terms(self.find_by_terms(:topical_subject))
solr_doc['genre_ssim'] = gather_terms(self.find_by_terms(:genre))
# solr_doc['physical_dtl_sim'] = gather_terms(self.find_by_terms(:format))
# solr_doc['contents_sim'] = gather_terms(self.find_by_terms(:parts_list))
Expand All @@ -52,7 +54,7 @@ def to_solr(solr_doc = Hash.new, opts = {})
# solr_doc['collection_sim'] = gather_terms(self.find_by_terms(:archival_collection))
solr_doc['series_ssim'] = gather_terms(self.find_by_terms(:series))
#filter formats based upon whitelist
solr_doc['resource_type_ssim'] = (gather_terms(self.find_by_terms(:resource_type)) & ['moving image', 'sound recording' ]).map(&:titleize)
solr_doc['resource_type_ssim'] = (gather_terms(self.find_by_terms(:resource_type)) & ['moving image', 'sound recording' ])
solr_doc['location_ssim'] = gather_terms(self.find_by_terms(:geographic_subject))

# Blacklight facets - these are the same facet fields used in our Blacklight app
Expand All @@ -78,10 +80,15 @@ def to_solr(solr_doc = Hash.new, opts = {})
solr_doc['terms_of_use_ssi'] = (self.find_by_terms(:terms_of_use) - self.find_by_terms(:rights_statement)).text
solr_doc['rights_statement_ssi'] = self.find_by_terms(:rights_statement).text
solr_doc['other_identifier_sim'] = gather_terms(self.find_by_terms(:other_identifier))
solr_doc['bibliographic_id_ssi'] = self.bibliographic_id.first
solr_doc['bibliographic_id_source_ssi'] = self.bibliographic_id.source.first
solr_doc['statement_of_responsibility_ssi'] = gather_terms(self.find_by_terms(:statement_of_responsibility))
solr_doc['record_identifier_ssim'] = gather_terms(self.find_by_terms(:record_identifier))

# Extract 4-digit year for creation date facet in Hydra and pub_date facet in Blacklight
solr_doc['date_issued_ssi'] = self.find_by_terms(:date_issued).text
solr_doc['date_created_ssi'] = self.find_by_terms(:date_created).text
solr_doc['copyright_date_ssi'] = self.find_by_terms(:copyright_date).text
# Put both publication date and creation date into the date facet
solr_doc['date_sim'] = gather_years(solr_doc['date_issued_ssi'])
solr_doc['date_sim'] += gather_years(solr_doc['date_created_ssi']) if solr_doc['date_created_ssi'].present?
Expand Down
8 changes: 8 additions & 0 deletions app/presenters/speedy_af/proxy/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def language
attrs[:language_code].present? ? attrs[:language_code].map { |code| { code: code, text: LanguageTerm.find(code).text } } : []
end

def bibliographic_id
if attrs[:bibliographic_id].present? && attrs[:bibliographic_id_source].present?
{ id: attrs[:bibliographic_id], source: attrs[:bibliographic_id_source] }
else
nil
end
end

def sections_with_files(tag: '*')
sections.select { |master_file| master_file.supplemental_files(tag: tag).present? }.map(&:id)
end
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/presenter_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
uniform_title: [],
resource_type: [],
record_identifier: [],
series: []
series: [],
format: []
}
include VirtualGroups
include MediaObjectIntercom
Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/media_objects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@
context "with json format" do
subject(:json) { JSON.parse(response.body) }
let(:administrator) { FactoryBot.create(:administrator) }
let!(:media_object) { FactoryBot.create(:media_object) }
let!(:media_object) { FactoryBot.create(:all_fields_media_object) }
let!(:master_file) { FactoryBot.create(:master_file, :with_derivative, media_object: media_object) }

before do
Expand All @@ -1190,6 +1190,8 @@
end

it "should return json for specific media_object" do
# Run indexing job to ensure object isn't reified in this request
perform_enqueued_jobs(only: MediaObjectIndexingJob)
get 'show', params: { id: media_object.id, format:'json' }
expect(json['id']).to eq(media_object.id)
expect(json['title']).to eq(media_object.title)
Expand All @@ -1201,13 +1203,11 @@
expect(json['published']).to eq(media_object.published?)
expect(json['summary']).to eq(media_object.abstract)

# FIXME: https://github.com/avalonmediasystem/avalon/issues/5834
ingest_api_hash = media_object.to_ingest_api_hash(false)
json['fields'].each do |k,v|
if k == "avalon_resource_type"
expect(v.map(&:downcase)).to eq(ingest_api_hash[:fields][k.to_sym])
elsif k == "record_identifier"
# no-op since not indexed
# Known issue: identifiers are downcased when indexing to allow for case-insensitive searching
if k.to_sym == :identifier
expect(v).to eq(ingest_api_hash[:fields][k.to_sym].map(&:downcase))
else
expect(v).to eq(ingest_api_hash[:fields][k.to_sym])
end
Expand Down
12 changes: 12 additions & 0 deletions spec/factories/media_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
terms_of_use { [ 'Terms of Use: Be kind. Rewind.' ] }
series { [Faker::Lorem.word] }
sections { [] }
identifier { [Faker::Alphanumeric.alphanumeric(number: 8, min_alpha: 1, min_numeric: 1).downcase,
Faker::Alphanumeric.alphanumeric(number: 8, min_alpha: 1, min_numeric: 1).upcase,
Faker::Barcode.isbn] }
resource_type { ['moving image'] }
statement_of_responsibility { Faker::Lorem.word }
# after(:create) do |mo|
# mo.update_datastream(:descMetadata, {
# note: {note[Faker::Lorem.paragraph],
Expand All @@ -60,6 +65,13 @@
# })
# mo.save
# end

factory :all_fields_media_object do
uniform_title { [Faker::Lorem.sentence] }
alternative_title { [Faker::Lorem.sentence] }
translated_title { [Faker::Lorem.sentence] }
copyright_date { '2011' }
end
end
end
trait :with_master_file do
Expand Down

0 comments on commit aaef4ce

Please sign in to comment.