Skip to content

Commit

Permalink
Merge pull request #1193 from sul-dlss/geo-metadata
Browse files Browse the repository at this point in the history
Create IIIF manifests for geo objects
  • Loading branch information
dnoneill authored Feb 10, 2025
2 parents 3183147 + 4be6399 commit cc65fd6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ GEM
ast (2.4.2)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
benchmark (0.4.0)
bigdecimal (3.1.9)
bindex (0.8.1)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/iiif_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def manifest

return unless stale?(last_modified: @version.updated_at.utc, etag: "#{@version.cache_key}/#{iiif_version}/#{@version.updated_at.utc}")

# Avoid trying to create a manifest for geo objects, because we don't yet have a way of knowing which file is a primary.
# See ContentMetadata::GroupedResource#primary
return head :not_found if @version.type == 'geo'

manifest = Rails.cache.fetch(cache_key('manifest', iiif_version), expires_in: Settings.resource_cache.lifetime) do
iiif_manifest.body.to_ordered_hash
end
Expand Down
24 changes: 20 additions & 4 deletions app/models/iiif3_presentation_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,29 @@ def body

manifest.thumbnail = [thumbnail_resource] if thumbnail_resource?

# for each resource sequence(SDR term), create a canvas
content_metadata.grouped_resources.each do |resource_group|
manifest.items << canvas_for_resource(resource_group)
end
build_canvases(manifest)

manifest
end

def build_canvases(manifest)
# for each resource sequence (SDR term), create a canvas
if type == 'geo'
# Geo can't determine "primary", so we just create a "dummy" canvas here.
# IIIF v3 requires Manifests to have at least one canvas. https://iiif.io/api/presentation/3.0/#34-structural-properties
resource = content_metadata.grouped_resources.first
file = resource.files.first
manifest.items << IIIF::V3::Presentation::Canvas.new(
'id' => canvas_url(resource_id: file.id),
'label' => file.label
)
else
content_metadata.grouped_resources.each do |resource_group|
manifest.items << canvas_for_resource(resource_group)
end
end
end

def attribution
[copyright || 'Provided by the Stanford University Libraries'].flatten
end
Expand All @@ -85,6 +100,7 @@ def canvas_for_resource(resource_group)
else
resource_group
end

canv = IIIF::V3::Presentation::Canvas.new
canv['id'] = canvas_url(resource_id: resource.id)
canv.label = {
Expand Down
11 changes: 11 additions & 0 deletions spec/requests/iiif3_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@
end
end

context 'with a geo object' do
let(:druid) { 'cg357zz0321' }

it 'only generates metadata' do
get "/#{druid}/iiif3/manifest"
expect(response).to have_http_status(:ok)
expect(json['label']['en'].first).to eq '10 Meter Contours: Russian River Basin, California'
expect(json['metadata'].size).to eq 14
end
end

context 'with a 3D object as obj' do
let(:druid) { 'bg387kw8222' }

Expand Down

0 comments on commit cc65fd6

Please sign in to comment.