Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
create seperate geo derivatives path
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Dec 9, 2016
1 parent dcda022 commit 55c849b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/indexers/file_set_indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class FileSetIndexer < CurationConcerns::FileSetIndexer
self.thumbnail_path_service = ThumbnailPathService
end
15 changes: 15 additions & 0 deletions app/models/file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class FileSet < ActiveFedora::Base

validates_with ViewingHintValidator

# Use local indexer
self.indexer = FileSetIndexer

def self.image_mime_types
[]
end
Expand Down Expand Up @@ -79,6 +82,18 @@ def ocr_text
ocr_document.try(:text).try(:strip)
end

# Override the geo_concerns path factory
def derivative_path_factory
PairtreeDerivativePath
end

# Remove files as well as shapefile directories
def cleanup_derivatives
derivative_path_factory.derivatives_for_reference(self).each do |path|
FileUtils.rm_rf(path)
end
end

# The destination_name parameter has to match up with the file parameter
# passed to the DownloadsController
def derivative_url(destination_name)
Expand Down
7 changes: 7 additions & 0 deletions app/services/thumbnail_path_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ThumbnailPathService < CurationConcerns::ThumbnailPathService
class << self
def thumbnail_filepath(thumb)
PairtreeDerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
end
end
end
20 changes: 20 additions & 0 deletions app/values/pairtree_derivative_path.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
class PairtreeDerivativePath < CurationConcerns::DerivativePath
def initialize(object, destination_name = nil)
@object = object
@id = object.is_a?(String) ? object : object.id
@destination_name = destination_name.gsub(/^original_file_/, '') if destination_name
end

def path_prefix
geo_path_prefix || derivatives_path_prefix
end

def geo_path_prefix
return unless @object.respond_to?(:geo_mime_type)
return if @object.geo_mime_type.nil? || @object.geo_mime_type.empty?
Pathname.new(Plum.config[:geo_derivatives_path]).join(pair_path)
end

def derivatives_path_prefix
Pathname.new(CurationConcerns.config.derivatives_path).join(pair_path)
end

def file_name
return unless destination_name
if extension == ".pdf"
Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defaults: &defaults
events:
server: 'amqp://localhost:5672'
exchange: 'plum_events'
geo_derivatives_path: <%= File.join(Rails.root, 'tmp', 'geo-derivatives') %>

development:
<<: *defaults
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/file_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
after(:build) do |file, evaluator|
file.apply_depositor_metadata(evaluator.user.user_key)
end

factory :geo_file_set do
geo_mime_type 'application/vnd.geo+json'
end
end
end
3 changes: 3 additions & 0 deletions spec/fixtures/files/mercer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"type":"FeatureCollection","properties":{"kind":"state","state":"NJ"},"features":[
{"type":"Feature","properties":{"kind":"county","name":"Mercer","state":"NJ"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-74.8007,40.4179],[-74.7459,40.4234],[-74.7240,40.3741],[-74.6199,40.3741],[-74.6199,40.3248],[-74.4830,40.2536],[-74.6145,40.1824],[-74.5871,40.1385],[-74.7021,40.1824],[-74.7240,40.1495],[-74.9431,40.3412],[-74.8554,40.3467],[-74.8719,40.3795],[-74.8007,40.3850]]]]}}
]}
9 changes: 9 additions & 0 deletions spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
FileUtils.rm_rf(path.parent) if path.exist?
FileUtils.rm_rf(ocr_path.parent) if ocr_path.exist?
end
it "creates a vector thumbnail and indexes the path" do
allow_any_instance_of(described_class).to receive(:warn) # suppress virus check warnings
subject.geo_mime_type = 'application/vnd.geo+json'
file = File.open(Rails.root.join("spec", "fixtures", "files", "mercer.json"))
Hydra::Works::UploadFileToFileSet.call(subject, file)
subject.create_derivatives(file.path)

expect(subject.to_solr['thumbnail_path_ss']).to match(/file=thumbnail/)
end
end

describe '#where' do
Expand Down
7 changes: 7 additions & 0 deletions spec/values/pairtree_derivative_path_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require 'rails_helper'

describe PairtreeDerivativePath do
let(:plum_config) { { geo_derivatives_path: 'geo-derivatives' } }

before do
allow(CurationConcerns.config).to receive(:derivatives_path).and_return('tmp')
allow(Plum).to receive(:config).and_return(plum_config)
end

describe '.derivative_path_for_reference' do
Expand Down Expand Up @@ -57,5 +60,9 @@
let(:destination_name) { 'display_vector' }
it { is_expected.to eq 'tmp/08/61/2n/57/q-display_vector.zip' }
end
context 'when given a geo filset' do
let(:object) { double(id: '08612n57q', geo_mime_type: 'application/vnd.geo+json') }
it { is_expected.to eq 'geo-derivatives/08/61/2n/57/q-thumbnail.jpeg' }
end
end
end

0 comments on commit 55c849b

Please sign in to comment.