Skip to content

Commit

Permalink
[WIP] Explicitly tests for location values propagated from repository…
Browse files Browse the repository at this point in the history
… resources
  • Loading branch information
jrgriffiniii committed Jun 19, 2018
1 parent 342520f commit a8763b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
18 changes: 18 additions & 0 deletions app/values/manifest_metadata.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

# Class for processing and resolving linked metadata for resources
class ManifestMetadata < Spotlight::Resources::IiifManifest::Metadata
# Retrieve the URL for the JSON-LD representation of the resource (i. e. Figgy Resources)
# @return [String] the URL for the JSON-LD
def jsonld_url
return unless @manifest["see_also"]
json_ld_see_also = Array.wrap(@manifest["see_also"]).find { |v| v["format"] == "application/ld+json" }
return unless json_ld_see_also
json_ld_see_also["@id"]
end

# Resolve the JSON-LD URL by requesting it over the HTTP
# @return [String] the string-serialized JSON-LD
def jsonld_response
return unless jsonld_url
response = Faraday.get(jsonld_url)
Expand All @@ -15,16 +21,24 @@ def jsonld_response
Rails.logger.warn("HTTP GET for #{jsonld_url} failed with #{e}")
end

# Resolve the JSON-LD representation of the resource requesting it over the HTTP
# If successfully retrieved, parse the string-serialized JSON-LD into a Hash
# @return [Hash, nil]
def jsonld_metadata
@jsonld_metadata ||= JSON.parse(jsonld_response)
rescue JSON::ParserError, TypeError
@jsonld_metadata = nil
end

# Generate the list of JSON-LD keys which should be filtered during the parsing
# @return [Array<String>]
def jsonld_delete_keys
%w(@context @id)
end

# Retrieve the JSON-LD representation and filter for any unwanted keys
# Then ensure that the keys for the JSON-LD are human-friendly
# @return [Hash]
def jsonld_metadata_hash
jsonld_metadata.delete_if { |k, _v| jsonld_delete_keys.include?(k) }
.transform_keys { |k| k.to_s.humanize }
Expand Down Expand Up @@ -65,6 +79,10 @@ def new_values
end
end
end

# Construct a Hash of Value Objects from JSON-LD values, keyed to the JSON-LD keys
# @param input_hash [Hash]
# @return [Hash]
def process_values(input_hash)
h = Hash[input_hash.map do |key, values|
Value.new(key, values).to_pair
Expand Down
20 changes: 10 additions & 10 deletions spec/cassettes/all_collections.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

solr_doc = nil
resource.document_builder.to_solr { |x| solr_doc = x }

expect(solr_doc["full_title_tesim"]).to eq ['Christopher and his kind, 1929-1939']
expect(solr_doc["readonly_created_tesim"]).to eq ["1976-01-01T00:00:00Z"]
expect(solr_doc["readonly_range-label_tesim"]).to eq ["Chapter 1", "Chapter 2"]
expect(Spotlight::CustomField.last.field_type).to eq 'vocab'
expect(solr_doc["readonly_created_ssim"]).to eq ["1976-01-01T00:00:00Z"]
expect(solr_doc["readonly_description_ssim"]).to eq ["First", "Second"]
expect(solr_doc["readonly_location_ssim"]).to eq ["F PR6017.S5 Z498"]
end
it 'indexes collections' do
exhibit = Spotlight::Exhibit.create title: 'Exhibit A'
Expand Down

0 comments on commit a8763b3

Please sign in to comment.