Skip to content

Commit

Permalink
Merge pull request #248 from projecthydra-labs/pass-id
Browse files Browse the repository at this point in the history
Pass id to processors and use to name display vector
  • Loading branch information
Darren Hardy committed Oct 28, 2016
2 parents bc26540 + b4239cc commit 0bd0b2c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Metrics/MethodLength:
Exclude:
- 'Rakefile'
- 'app/models/concerns/geo_concerns/extractors/iso19139_helper.rb'
- 'app/models/concerns/geo_concerns/file_set/derivatives.rb'

Metrics/ClassLength:
Exclude:
Expand Down
7 changes: 5 additions & 2 deletions app/models/concerns/geo_concerns/file_set/derivatives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module FileSet
module Derivatives
extend ActiveSupport::Concern

# rubocop:disable Metrics/MethodLength
def create_derivatives(filename)
content_url = nil
case geo_mime_type
Expand All @@ -23,11 +22,11 @@ def create_derivatives(filename)
# deliver them to external services
DeliveryJob.perform_later(self, content_url) if content_url.present?
end
# rubocop:enable Metrics/MethodLength

def image_derivatives(filename)
Hydra::Derivatives::ImageDerivatives
.create(filename, outputs: [{ label: :thumbnail,
id: id,
format: 'png',
size: '200x150>',
url: derivative_url('thumbnail') }])
Expand All @@ -37,10 +36,12 @@ def raster_derivatives(filename)
GeoConcerns::Runners::RasterDerivatives
.create(filename, outputs: [{ input_format: geo_mime_type,
label: :display_raster,
id: id,
format: 'tif',
url: derivative_url('display_raster') },
{ input_format: geo_mime_type,
label: :thumbnail,
id: id,
format: 'png',
size: '200x150',
url: derivative_url('thumbnail') }])
Expand All @@ -50,10 +51,12 @@ def vector_derivatives(filename)
GeoConcerns::Runners::VectorDerivatives
.create(filename, outputs: [{ input_format: geo_mime_type,
label: :display_vector,
id: id,
format: 'zip',
url: derivative_url('display_vector') },
{ input_format: geo_mime_type,
label: :thumbnail,
id: id,
format: 'png',
size: '200x150',
url: derivative_url('thumbnail') }])
Expand Down
9 changes: 8 additions & 1 deletion app/processors/geo_concerns/processors/base_geo_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def options_for(_format)
label: label,
output_size: output_size,
output_srid: output_srid,
basename: basename
basename: basename,
id: id
}
end

Expand Down Expand Up @@ -69,6 +70,12 @@ def output_srid
def basename
File.basename(source_path, File.extname(source_path))
end

# Gets the fileset id or returns nil.
# @return [String] fileset id
def id
directives.fetch(:id, nil)
end
end
end
end
5 changes: 1 addition & 4 deletions app/processors/geo_concerns/processors/ogr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ module Ogr
# #param options [Hash] creation options
# @param out_path [String] processor output file path
def self.reproject(in_path, out_path, options)
# reset the basename
vector_info = GeoConcerns::Processors::Vector::Info.new(in_path)
options[:basename] = vector_info.name
execute "env SHAPE_ENCODING= ogr2ogr -q -nln #{options[:basename]} -f 'ESRI Shapefile'"\
execute "env SHAPE_ENCODING= ogr2ogr -q -nln #{options[:id]} -f 'ESRI Shapefile'"\
" -t_srs #{options[:output_srid]} -preserve_fid '#{out_path}' '#{in_path}'"
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/processors/geo_concerns/processors/base_geo_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ def source_path
end
end

describe '#id' do
context 'when directives hash has an id value' do
let(:directives) { { id: '123456' } }
it 'returns that value' do
expect(subject.id).to eq('123456')
end
end

context 'when directives hash does not have an id value' do
it 'returns nil' do
expect(subject.id).to be_nil
end
end
end

describe '#basename' do
it 'returns the base file name of the source file' do
expect(subject.basename).to eq('geo')
Expand Down

0 comments on commit 0bd0b2c

Please sign in to comment.