Skip to content

Commit

Permalink
Changes to the collection indexer to make it aware of IIIF
Browse files Browse the repository at this point in the history
Previously when you selected a collection thumbnail it did not know to
use a IIIF url
  • Loading branch information
jcoyne committed Jun 24, 2017
1 parent 24e7c4f commit 6f43576
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Expand Up @@ -36,7 +36,8 @@ Metrics/LineLength:
Exclude:
- 'app/controllers/catalog_controller.rb'
- 'spec/controllers/curation_concerns/generic_works_controller_spec.rb'
- 'spec/services/iiif_thumbnail_path_service_spec.rb'
- 'spec/services/iiif_collection_thumbnail_path_service_spec.rb'
- 'spec/services/iiif_work_thumbnail_path_service_spec.rb'
- 'spec/routing/proprietor/accounts_routing_spec.rb'

Style/IndentationConsistency:
Expand Down
15 changes: 15 additions & 0 deletions app/indexers/collection_indexer.rb
@@ -0,0 +1,15 @@
class CollectionIndexer < Hyrax::CollectionIndexer
# This indexes the default metadata. You can remove it if you want to
# provide your own metadata and indexing.
include Hyrax::IndexesBasicMetadata

# Use thumbnails served by RIIIF
self.thumbnail_path_service = IIIFCollectionThumbnailPathService

# Uncomment this block if you want to add custom indexing behavior:
# def generate_solr_document
# super.tap do |solr_doc|
# solr_doc['my_custom_field_ssim'] = object.my_custom_property
# end
# end
end
2 changes: 1 addition & 1 deletion app/indexers/file_set_indexer.rb
@@ -1,3 +1,3 @@
class FileSetIndexer < Hyrax::FileSetIndexer
self.thumbnail_path_service = IIIFThumbnailPathService
self.thumbnail_path_service = IIIFWorkThumbnailPathService
end
2 changes: 1 addition & 1 deletion app/indexers/image_indexer.rb
Expand Up @@ -10,7 +10,7 @@ class ImageIndexer < Hyrax::WorkIndexer
include Hyrax::IndexesLinkedMetadata

# Use thumbnails served by RIIIF
self.thumbnail_path_service = IIIFThumbnailPathService
self.thumbnail_path_service = IIIFWorkThumbnailPathService

# Uncomment this block if you want to add custom indexing behavior:
# def generate_solr_document
Expand Down
2 changes: 1 addition & 1 deletion app/indexers/work_indexer.rb
Expand Up @@ -8,7 +8,7 @@ class WorkIndexer < Hyrax::WorkIndexer
include Hyrax::IndexesLinkedMetadata

# Use thumbnails served by RIIIF
self.thumbnail_path_service = IIIFThumbnailPathService
self.thumbnail_path_service = IIIFWorkThumbnailPathService

# Uncomment this block if you want to add custom indexing behavior:
# def generate_solr_document
Expand Down
2 changes: 1 addition & 1 deletion app/models/collection.rb
Expand Up @@ -3,5 +3,5 @@ class Collection < ActiveFedora::Base
include ::Hyrax::CollectionBehavior
# You can replace these metadata if they're not suitable
include Hyrax::BasicMetadata
self.indexer = Hyrax::CollectionWithBasicMetadataIndexer
self.indexer = CollectionIndexer
end
29 changes: 29 additions & 0 deletions app/services/concerns/iiif_thumbnail_paths.rb
@@ -0,0 +1,29 @@
module IIIFThumbnailPaths
extend ActiveSupport::Concern

class_methods do
# @param [FileSet] file_set
# @param [String] size ('!150,300') an IIIF image size defaults to an image no
# wider than 150px and no taller than 300px
# @return the IIIF url for the thumbnail if it's an image, otherwise gives
# the thumbnail download path
def thumbnail_path(file_set, size = '!150,300'.freeze)
return super(file_set) unless file_set.image?
iiif_thumbnail_path(file_set, size)
end

# @private
def iiif_thumbnail_path(file_set, size)
file = file_set.original_file
return unless file
Riiif::Engine.routes.url_helpers.image_path(
file.id,
size: size
)
end

def thumbnail?(_thumbnail)
true
end
end
end
8 changes: 8 additions & 0 deletions app/services/iiif_collection_thumbnail_path_service.rb
@@ -0,0 +1,8 @@
class IIIFCollectionThumbnailPathService < Hyrax::CollectionThumbnailPathService
include IIIFThumbnailPaths

# The image to use if no thumbnail has been selected
def self.default_image
ActionController::Base.helpers.image_path 'collection.png'
end
end
30 changes: 0 additions & 30 deletions app/services/iiif_thumbnail_path_service.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/services/iiif_work_thumbnail_path_service.rb
@@ -0,0 +1,3 @@
class IIIFWorkThumbnailPathService < Hyrax::WorkThumbnailPathService
include IIIFThumbnailPaths
end
9 changes: 9 additions & 0 deletions spec/indexers/collection_indexer_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'

RSpec.describe CollectionIndexer do
describe ".thumbnail_path_service" do
subject { described_class.thumbnail_path_service }

it { is_expected.to eq IIIFCollectionThumbnailPathService }
end
end
2 changes: 1 addition & 1 deletion spec/indexers/file_set_indexer_spec.rb
@@ -1,6 +1,6 @@
RSpec.describe FileSetIndexer do
describe 'thumbnail_path_service' do
subject { described_class.thumbnail_path_service }
it { is_expected.to eq IIIFThumbnailPathService }
it { is_expected.to eq IIIFWorkThumbnailPathService }
end
end
2 changes: 1 addition & 1 deletion spec/indexers/work_indexer_spec.rb
@@ -1,7 +1,7 @@
RSpec.describe WorkIndexer do
describe 'thumbnail_path_service' do
subject { described_class.thumbnail_path_service }
it { is_expected.to eq IIIFThumbnailPathService }
it { is_expected.to eq IIIFWorkThumbnailPathService }
end

describe 'rdf_service' do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/collection_spec.rb
Expand Up @@ -4,4 +4,10 @@
it "is a hyrax collection" do
expect(described_class.ancestors).to include Hyrax::CollectionBehavior
end

describe ".indexer" do
subject { described_class.indexer }

it { is_expected.to eq CollectionIndexer }
end
end
38 changes: 38 additions & 0 deletions spec/services/iiif_collection_thumbnail_path_service_spec.rb
@@ -0,0 +1,38 @@
RSpec.describe IIIFCollectionThumbnailPathService do
let(:file_set) { FileSet.new }
let(:file) do
double(id: 's1/78/4k/72/s1784k724/files/6185235a-79b2-4c29-8c24-4d6ad9b11470',
mime_type: 'image/jpeg')
end

before do
allow(ActiveFedora::Base).to receive(:find).with('s1784k724').and_return(file_set)
allow(file_set).to receive_messages(original_file: file, id: 's1784k724')
# https://github.com/projecthydra/active_fedora/issues/1251
allow(file_set).to receive(:persisted?).and_return(true)
end

context "on a collection" do
subject { described_class.call(collection) }

context "with a thumbnail" do
let(:collection) { build(:collection, thumbnail_id: 's1784k724') }

it { is_expected.to eq '/images/s1%2F78%2F4k%2F72%2Fs1784k724%2Ffiles%2F6185235a-79b2-4c29-8c24-4d6ad9b11470/full/!150,300/0/default.jpg' }
end

context "without a thumbnail" do
let(:collection) { build(:collection) }

it { is_expected.to start_with '/assets/collection-' }
end
end

context "on a file set" do
subject { described_class.call(file_set) }

context "with an image" do
it { is_expected.to eq '/images/s1%2F78%2F4k%2F72%2Fs1784k724%2Ffiles%2F6185235a-79b2-4c29-8c24-4d6ad9b11470/full/!150,300/0/default.jpg' }
end
end
end
@@ -1,4 +1,4 @@
RSpec.describe IIIFThumbnailPathService do
RSpec.describe IIIFWorkThumbnailPathService do
let(:file_set) { FileSet.new }
let(:file) do
double(id: 's1/78/4k/72/s1784k724/files/6185235a-79b2-4c29-8c24-4d6ad9b11470',
Expand Down

0 comments on commit 6f43576

Please sign in to comment.