diff --git a/app/controllers/media_objects_controller.rb b/app/controllers/media_objects_controller.rb index c3136c5ded..78e3d39b20 100644 --- a/app/controllers/media_objects_controller.rb +++ b/app/controllers/media_objects_controller.rb @@ -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 diff --git a/app/models/iiif_manifest_presenter.rb b/app/models/iiif_manifest_presenter.rb index 185b6bad57..cfd95099a9 100644 --- a/app/models/iiif_manifest_presenter.rb +++ b/app/models/iiif_manifest_presenter.rb @@ -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 @@ -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), @@ -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))] diff --git a/spec/models/iiif_manifest_presenter_spec.rb b/spec/models/iiif_manifest_presenter_spec.rb index 882ab2f18b..84882e7182 100644 --- a/spec/models/iiif_manifest_presenter_spec.rb +++ b/spec/models/iiif_manifest_presenter_spec.rb @@ -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 @@ -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