From 3558acf0938361970b82a3d622d752bdccf1a012 Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Mon, 2 May 2022 11:37:20 -0400 Subject: [PATCH 1/3] Add failing test for annotation id Co-authored-by: Mason Ballengee --- spec/lib/iiif_manifest/v3/manifest_factory_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/iiif_manifest/v3/manifest_factory_spec.rb b/spec/lib/iiif_manifest/v3/manifest_factory_spec.rb index 8bb1fd1..5ae6a0f 100644 --- a/spec/lib/iiif_manifest/v3/manifest_factory_spec.rb +++ b/spec/lib/iiif_manifest/v3/manifest_factory_spec.rb @@ -142,6 +142,7 @@ def display_content expect(result['items'].first['items'].first['id']).not_to be_empty expect(result['items'].first['items'].first['items'].length).to eq 1 expect(result['items'].first['items'].first['items'].first['type']).to eq 'Annotation' + expect(result['items'].first['items'].first['items'].first['id']).not_to be_empty expect(result['items'].first['items'].first['items'].first['motivation']).to eq 'painting' expect(result['items'].first['items'].first['items'].first['target']).to eq result['items'].first['id'] expect(result['items'].first['items'].first['items'].first['body']['type']).to eq 'Image' @@ -185,6 +186,7 @@ def display_content expect(result['items'].first['items'].first['id']).not_to be_empty expect(result['items'].first['items'].first['items'].length).to eq 1 expect(result['items'].first['items'].first['items'].first['type']).to eq 'Annotation' + expect(result['items'].first['items'].first['items'].first['id']).not_to be_empty expect(result['items'].first['items'].first['items'].first['motivation']).to eq 'painting' expect(result['items'].first['items'].first['items'].first['target']).to eq result['items'].first['id'] expect(result['items'].first['items'].first['items'].first['body']['type']).to eq 'Sound' From 1d70a581add81cd9e9dd7869a4eafa88940d08ae Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Tue, 3 May 2022 14:06:57 -0400 Subject: [PATCH 2/3] Add ID property to Annotation --- lib/iiif_manifest/v3/manifest_builder/content_builder.rb | 1 + lib/iiif_manifest/v3/manifest_builder/iiif_service.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/iiif_manifest/v3/manifest_builder/content_builder.rb b/lib/iiif_manifest/v3/manifest_builder/content_builder.rb index 2be7db9..54ee64d 100644 --- a/lib/iiif_manifest/v3/manifest_builder/content_builder.rb +++ b/lib/iiif_manifest/v3/manifest_builder/content_builder.rb @@ -11,6 +11,7 @@ def initialize(display_content, iiif_annotation_factory:, body_builder_factory:) end def apply(canvas) + annotation['id'] = canvas['id'].to_s.gsub(/manifest.*/, "annotation/#{annotation.index}") annotation['target'] = canvas['id'] canvas['width'] = annotation.body['width'] if annotation.body['width'].present? canvas['height'] = annotation.body['height'] if annotation.body['height'].present? diff --git a/lib/iiif_manifest/v3/manifest_builder/iiif_service.rb b/lib/iiif_manifest/v3/manifest_builder/iiif_service.rb index 61ecb79..d4885f5 100644 --- a/lib/iiif_manifest/v3/manifest_builder/iiif_service.rb +++ b/lib/iiif_manifest/v3/manifest_builder/iiif_service.rb @@ -191,6 +191,10 @@ def body inner_hash['body'] end + def index + @index ||= SecureRandom.uuid + end + def initial_attributes { 'type' => 'Annotation', From 087b38f8db6f476d5801a9222d520f584c2055c5 Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Wed, 4 May 2022 14:15:59 -0400 Subject: [PATCH 3/3] Change annotation id URI to match JSON nesting --- lib/iiif_manifest/v3/manifest_builder/content_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/iiif_manifest/v3/manifest_builder/content_builder.rb b/lib/iiif_manifest/v3/manifest_builder/content_builder.rb index 54ee64d..75d5357 100644 --- a/lib/iiif_manifest/v3/manifest_builder/content_builder.rb +++ b/lib/iiif_manifest/v3/manifest_builder/content_builder.rb @@ -11,12 +11,12 @@ def initialize(display_content, iiif_annotation_factory:, body_builder_factory:) end def apply(canvas) - annotation['id'] = canvas['id'].to_s.gsub(/manifest.*/, "annotation/#{annotation.index}") + # Assume first item in canvas is an annotation page + annotation['id'] = "#{canvas.items.first['id']}/annotation/#{annotation.index}" annotation['target'] = canvas['id'] canvas['width'] = annotation.body['width'] if annotation.body['width'].present? canvas['height'] = annotation.body['height'] if annotation.body['height'].present? canvas['duration'] = annotation.body['duration'] if annotation.body['duration'].present? - # Assume first item in canvas is an annotation page canvas.items.first.items += [annotation] end