Skip to content

Commit

Permalink
Add access restriction and lending period to iiif metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
masaball committed Sep 7, 2023
1 parent 2cb858e commit 539c69f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/media_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def manifest
stream_info = secure_streams(mf.stream_details, @media_object.id)
IiifCanvasPresenter.new(master_file: mf, stream_info: stream_info)
end
presenter = IiifManifestPresenter.new(media_object: @media_object, master_files: canvas_presenters)
presenter = IiifManifestPresenter.new(media_object: @media_object, master_files: canvas_presenters, lending_enabled: lending_enabled?(@media_object))

manifest = IIIFManifest::V3::ManifestFactory.new(presenter).to_h
# TODO: implement thumbnail in iiif_manifest
Expand Down
14 changes: 11 additions & 3 deletions app/models/iiif_manifest_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class IiifManifestPresenter
IIIF_ALLOWED_TAGS = ['a', 'b', 'br', 'i', 'img', 'p', 'small', 'span', 'sub', 'sup'].freeze
IIIF_ALLOWED_ATTRIBUTES = ['href', 'src', 'alt'].freeze

attr_reader :media_object, :master_files
attr_reader :media_object, :master_files, :lending_enabled

def initialize(media_object:, master_files:)
def initialize(media_object:, master_files:, lending_enabled: false)
@media_object = media_object
@master_files = master_files
@lending_enabled = lending_enabled
end

def file_set_presenters
Expand Down Expand Up @@ -154,6 +155,11 @@ def display_summary(media_object)
media_object.abstract
end

def display_lending_period(media_object)
return nil unless lending_enabled
ActiveSupport::Duration.build(media_object.lending_period).to_day_hour_s
end

def iiif_metadata_fields
fields = [
metadata_field('Title', media_object.title),
Expand All @@ -172,7 +178,9 @@ def iiif_metadata_fields
metadata_field('Rights Statement', display_rights_statement(media_object)),
metadata_field('Terms of Use', media_object.terms_of_use),
metadata_field('Physical Description', media_object.physical_description),
metadata_field('Related Item', display_related_item(media_object))
metadata_field('Related Item', display_related_item(media_object)),
metadata_field('Access Restrictions', media_object.access_text),
metadata_field('Lending Period', display_lending_period(media_object))
]
fields += note_fields(media_object)
fields += [metadata_field('Other Identifier', display_other_identifiers(media_object))]
Expand Down
23 changes: 19 additions & 4 deletions spec/models/iiif_manifest_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2011-2023, The Trustees of Indiana University and Northwestern
# University. Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
#
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
Expand Down Expand Up @@ -47,11 +47,26 @@
end

it 'provides metadata' do
allow_any_instance_of(IiifManifestPresenter).to receive(:lending_enabled).and_return(false)

['Title', 'Date', 'Main contributor', 'Summary', 'Contributor', 'Publisher', 'Genre', 'Subject', 'Time period',
'Location', 'Collection', 'Unit', 'Language', 'Rights Statement', 'Terms of Use', 'Physical Description',
'Related Item', 'Notes', 'Table of Contents', 'Local Note', 'Other Identifiers'].each do |field|
'Related Item', 'Notes', 'Table of Contents', 'Local Note', 'Other Identifiers', 'Access Restrictions'].each do |field|
expect(subject).to include(field)
end
expect(subject).to_not include('Lending Period')
end

context 'when controlled digital lending is enabled' do
it 'provides metadata' do
allow_any_instance_of(IiifManifestPresenter).to receive(:lending_enabled).and_return(true)

['Title', 'Date', 'Main contributor', 'Summary', 'Contributor', 'Publisher', 'Genre', 'Subject', 'Time period',
'Location', 'Collection', 'Unit', 'Language', 'Rights Statement', 'Terms of Use', 'Physical Description',
'Related Item', 'Notes', 'Table of Contents', 'Local Note', 'Other Identifiers', 'Access Restrictions', 'Lending Period'].each do |field|
expect(subject).to include(field)
end
end
end

context 'multiple values' do
Expand Down

0 comments on commit 539c69f

Please sign in to comment.