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

Commit

Permalink
Merge pull request #1061 from pulibrary/1022-fix-geoserver-hyrax
Browse files Browse the repository at this point in the history
Fixes geoserver delivery in hyrax
  • Loading branch information
Trey Pendragon committed Mar 1, 2017
2 parents ce34a94 + a411766 commit ff32052
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/jobs/delivery_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'uri'

##
# Delivers derivatives to external services, like GeoServer
##
class DeliveryJob < ActiveJob::Base
queue_as Hyrax.config.ingest_queue_name

attr_reader :file_set

##
# Precondition is that all derivatives are created and saved.
# @param [FileSet] file_set
# @param [String] content_url contains the display copy to deliver
def perform(message)
@file_set = ActiveFedora::Base.find(message['id'])
uri = URI.parse(content_url)
return if uri.path == ''
GeoWorks::DeliveryService.new(file_set, uri.path).publish
end

def content_url
case file_set.geo_mime_type
when *GeoWorks::RasterFormatService.select_options.map(&:last)
return derivatives_service.send(:derivative_url, 'display_raster')
when *GeoWorks::VectorFormatService.select_options.map(&:last)
return derivatives_service.send(:derivative_url, 'display_vector')
else
return ''
end
end

def derivatives_service
GeoDerivativesService.new(file_set)
end
end
33 changes: 33 additions & 0 deletions spec/jobs/delivery_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'

describe DeliveryJob do
let(:id) { 'ab' }
let(:file_set) { instance_double(FileSet, id: id, geo_mime_type: file_format) }

before do
allow(subject).to receive(:file_set).and_return(file_set)
end

describe '#content_url' do
context 'with a vector file' do
let(:file_format) { 'application/zip; ogr-format="ESRI Shapefile"' }
it 'returns a path to the vector file' do
expect(subject.content_url).to include('ab-display_vector.zip')
end
end

context 'with a raster file' do
let(:file_format) { 'image/tiff; gdal-format=GTiff' }
it 'returns a path to the raster file' do
expect(subject.content_url).to include('ab-display_raster.tif')
end
end

context 'with a non-geospatial file' do
let(:file_format) { 'image/jpeg' }
it 'returns an empty path' do
expect(subject.content_url).to eq('')
end
end
end
end

0 comments on commit ff32052

Please sign in to comment.