Skip to content

Commit

Permalink
Ensuring that the license and rendering properties are exposed within…
Browse files Browse the repository at this point in the history
… the IIIF Manifest
  • Loading branch information
jrgriffiniii committed Oct 20, 2017
1 parent cfb0563 commit c066ba4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/services/manifest_builder/license_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(resource)
end

##
# Append the metadata to the IIIF Manifest
# Append the license to the IIIF Manifest
# @param [IIIF::Presentation::Manifest] manifest the IIIF manifest being
# @return [IIIF::Presentation::Manifest]
def apply(manifest)
Expand All @@ -21,7 +21,7 @@ def apply(manifest)
private

def license
statements = @resource.decorate.rights_statement.map(&:value)
statements = resource.decorate.rights_statement.map(&:value)
statements.empty? ? nil : statements.first
rescue
nil
Expand Down
8 changes: 8 additions & 0 deletions app/services/manifest_builder/manifest_service_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def license_builder
ManifestBuilder::LicenseBuilder
end

##
# Class accessor for the rendering builder
# @return [Class]
def rendering_builder
ManifestBuilder::RenderingBuilder
end

def child_manifest_builder
ConditionalCollectionManifest.new(manifest_builder: real_child_manifest_builder, collection_builder: child_collection_builder)
end
Expand Down Expand Up @@ -139,6 +146,7 @@ def manifest_builders
metadata_manifest_builder,
see_also_builder,
license_builder,
rendering_builder,
composite_builder: composite_builder
)
end
Expand Down
38 changes: 38 additions & 0 deletions app/services/manifest_builder/rendering_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true
class ManifestBuilder
class RenderingBuilder
attr_reader :resource

##
# @param [Valhalla::Resource] resource the Resource being viewed
def initialize(resource)
@resource = RootNode.new(resource)
end

##
# Append the license to the IIIF Manifest
# @param [IIIF::Presentation::Manifest] manifest the IIIF manifest being
# @return [IIIF::Presentation::Manifest]
def apply(manifest)
manifest.rendering = rendering_hash if identifier?
manifest
end

private

def identifier?
resource.decorate.identifier.present?
end

def identifier
Array.wrap(resource.decorate.identifier).first
end

def rendering_hash
{
"@id" => "http://arks.princeton.edu/#{identifier}",
"format" => "text/html"
}
end
end
end
5 changes: 4 additions & 1 deletion spec/services/manifest_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def logical_structure(file_set_id)
end
end
context "when given a nested child" do
let(:scanned_resource) { FactoryGirl.create_for_repository(:scanned_resource, member_ids: child.id) }
let(:scanned_resource) { FactoryGirl.create_for_repository(:scanned_resource, member_ids: child.id, identifier: '5m60qr98h') }
let(:child) { FactoryGirl.create_for_repository(:scanned_resource, files: [file]) }
it "builds a IIIF collection" do
output = manifest_builder.build
Expand All @@ -142,6 +142,9 @@ def logical_structure(file_set_id)
expect(output["manifests"].length).to eq 1
expect(output["manifests"][0]["@id"]).to eq "http://www.example.com/concern/scanned_resources/#{child.id}/manifest"
expect(output["manifests"][0]["viewingHint"]).to be_nil
expect(output["seeAlso"]).to include "@id" => "http://www.example.com/catalog/#{scanned_resource.id}.jsonld", "format" => "application/ld+json"
expect(output["rendering"]).to eq "http://arks.princeton.edu/ark:/88435/5m60qr98h"
expect(output["license"]).to eq "http://rightsstatements.org/vocab/NKC/1.0/"
end
end
context "when given a scanned map" do
Expand Down

0 comments on commit c066ba4

Please sign in to comment.