geoblacklight 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a76208f38c8360b0a7ac9d53f6bea129aa127c7f
4
- data.tar.gz: cab96dd5acfb95ebb2313061eedb342be66fc086
3
+ metadata.gz: 59d0205c4e07a131e2b5428ed95c147063845cd9
4
+ data.tar.gz: 5b25ed07db81ba2ba79f0a9ba910708883d98c21
5
5
  SHA512:
6
- metadata.gz: 52d058b189f45f3009b8071bf2ea5db8811b1d2965d6995432ebe25897fabe86c79c68068245158388fbd4efc9a6b5658ab8d68fcd3bd1e7a72318b1800e5d88
7
- data.tar.gz: 1deb25f8b97b1954559efa2105d364dd69be7ad8ad69d9c736ddbb0cc9fef2c16c0a882fef063a3b7b8ff507d740f42e75126b0a2ee3c163a10fb72a07ab7dcc
6
+ metadata.gz: 6293951f6b7f5adc3f98d97517f79fd89c8f0be0178276820db43c0f74552253f4ee4df0c49418739bbb0659cda9702bd01e0d937a04534feabe37b501e0a6a6
7
+ data.tar.gz: 1c399c1039db4db32a724e1d76730e7b9932ca279a5220d0af7f3e85b638c9a1313e62e393a9d7b15bdd4eb222fcee48ddaf610ae5b3112a9cacf144bd9e47ba
@@ -1,5 +1,5 @@
1
1
  class DownloadController < ApplicationController
2
- include Blacklight::SolrHelper
2
+ include Blacklight::SearchHelper
3
3
 
4
4
  rescue_from Geoblacklight::Exceptions::ExternalDownloadFailed do |exception|
5
5
  Geoblacklight.logger.error exception.message + ' ' + exception.url
@@ -18,7 +18,7 @@ class DownloadController < ApplicationController
18
18
  end
19
19
 
20
20
  def show
21
- @response, @document = get_solr_response_for_doc_id params[:id]
21
+ @response, @document = fetch params[:id]
22
22
  restricted_should_authenticate
23
23
  response = check_type
24
24
  validate response
@@ -30,13 +30,13 @@ class DownloadController < ApplicationController
30
30
 
31
31
  def file
32
32
  # Grab the solr document to check if it should be public or not
33
- @response, @document = get_solr_response_for_doc_id(file_name_to_id(params[:id]))
33
+ @response, @document = fetch(file_name_to_id(params[:id]))
34
34
  restricted_should_authenticate
35
35
  send_file "tmp/cache/downloads/#{params[:id]}.#{params[:format]}", type: 'application/zip', x_sendfile: true
36
36
  end
37
37
 
38
38
  def hgl
39
- @response, @document = get_solr_response_for_doc_id params[:id]
39
+ @response, @document = fetch params[:id]
40
40
  if params[:email]
41
41
  response = Geoblacklight::HglDownload.new(@document, params[:email]).get
42
42
  if response.nil?
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'blacklight', '~> 5.9'
21
+ spec.add_dependency 'blacklight', '~> 5.12.0'
22
22
  spec.add_dependency 'leaflet-rails', '~> 0.7.3'
23
23
  spec.add_dependency 'blacklight_range_limit', '~> 5.0.3'
24
24
  spec.add_dependency 'font-awesome-rails', '~> 4.1.0.0'
@@ -21,6 +21,8 @@ class CatalogController < ApplicationController
21
21
  :q => '{!raw f=layer_slug_s v=$id}'
22
22
  }
23
23
 
24
+ config.search_builder_class = Geoblacklight::SearchBuilder
25
+
24
26
  # solr field configuration for search results/index views
25
27
  # config.index.show_link = 'title_display'
26
28
  # config.index.record_display_type = 'format'
@@ -1,3 +1,6 @@
1
+ # Download path can be configured using this setting
2
+ #DOWNLOAD_PATH: "./tmp/cache/downloads"
3
+
1
4
  #Main Solr geometry field used for spatial search and bounding box. Should be type 'rpt'
2
5
  GEOMETRY_FIELD: 'solr_geom'
3
6
 
data/lib/geoblacklight.rb CHANGED
@@ -21,6 +21,7 @@ module Geoblacklight
21
21
  require 'geoblacklight/reference'
22
22
  require 'geoblacklight/references'
23
23
  require 'geoblacklight/routes'
24
+ require 'geoblacklight/search_builder'
24
25
 
25
26
  def self.inject!
26
27
  CatalogController.send(:include, Geoblacklight::ControllerOverride)
@@ -1,26 +1,12 @@
1
1
  module Geoblacklight
2
2
  module ControllerOverride
3
3
  extend ActiveSupport::Concern
4
- included do
5
- solr_search_params_logic << :add_spatial_params
6
- end
7
-
8
- def add_spatial_params(solr_params, req_params)
9
- if req_params[:bbox]
10
- solr_params[:bq] ||= []
11
- solr_params[:bq] = ["#{Settings.GEOMETRY_FIELD}:\"IsWithin(#{req_params[:bbox]})\"^10"]
12
- solr_params[:fq] ||= []
13
- solr_params[:fq] << "#{Settings.GEOMETRY_FIELD}:\"Intersects(#{req_params[:bbox]})\""
14
- end
15
- solr_params
16
- end
17
-
18
4
  def web_services
19
- @response, @document = get_solr_response_for_doc_id params[:id]
5
+ @response, @document = fetch params[:id]
20
6
  end
21
7
 
22
8
  def metadata
23
- @response, @document = get_solr_response_for_doc_id params[:id]
9
+ @response, @document = fetch params[:id]
24
10
  end
25
11
  end
26
- end
12
+ end
@@ -14,7 +14,7 @@ module Geoblacklight
14
14
  end
15
15
 
16
16
  def file_path
17
- "#{Rails.root}/tmp/cache/downloads/#{file_name}"
17
+ Settings.DOWNLOAD_PATH || "#{Rails.root}/tmp/cache/downloads"
18
18
  end
19
19
 
20
20
  def download_exists?
@@ -35,18 +35,18 @@ module Geoblacklight
35
35
  # @return [String] filename of the completed download
36
36
  def create_download_file
37
37
  download = initiate_download
38
- File.open("#{file_path}.tmp", 'wb') do |file|
38
+ File.open("#{file_path}/#{file_name}.tmp", 'wb') do |file|
39
39
  if download.headers['content-type'] == @options[:content_type]
40
40
  file.write download.body
41
41
  else
42
42
  fail Geoblacklight::Exceptions::WrongDownloadFormat
43
43
  end
44
44
  end
45
- File.rename("#{file_path}.tmp", file_path)
45
+ File.rename("#{file_path}/#{file_name}.tmp", "#{file_path}/#{file_name}")
46
46
  file_name
47
47
  rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
48
48
  Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} received #{download.headers['content-type']}"
49
- File.delete("#{file_path}.tmp")
49
+ File.delete("#{file_path}/#{file_name}.tmp")
50
50
  raise Geoblacklight::Exceptions::ExternalDownloadFailed, message: 'Wrong download type'
51
51
  end
52
52
 
@@ -0,0 +1,18 @@
1
+ module Geoblacklight
2
+ class SearchBuilder < Blacklight::Solr::SearchBuilder
3
+ def initialize(processor_chain, scope)
4
+ super(processor_chain, scope)
5
+ processor_chain << :add_spatial_params
6
+ end
7
+
8
+ def add_spatial_params(solr_params)
9
+ if blacklight_params[:bbox]
10
+ solr_params[:bq] ||= []
11
+ solr_params[:bq] = ["#{Settings.GEOMETRY_FIELD}:\"IsWithin(#{blacklight_params[:bbox]})\"^10"]
12
+ solr_params[:fq] ||= []
13
+ solr_params[:fq] << "#{Settings.GEOMETRY_FIELD}:\"Intersects(#{blacklight_params[:bbox]})\""
14
+ end
15
+ solr_params
16
+ end
17
+ end
18
+ end
@@ -12,11 +12,11 @@ module Geoblacklight
12
12
  end
13
13
 
14
14
  def public?
15
- get(:dc_rights_s).downcase == 'public'
15
+ fetch(:dc_rights_s).downcase == 'public'
16
16
  end
17
17
 
18
18
  def restricted?
19
- get(:dc_rights_s).downcase == 'restricted'
19
+ fetch(:dc_rights_s).downcase == 'restricted'
20
20
  end
21
21
 
22
22
  def downloadable?
@@ -40,7 +40,7 @@ module Geoblacklight
40
40
  end
41
41
 
42
42
  def same_institution?
43
- get(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
43
+ fetch(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
44
44
  end
45
45
 
46
46
  def item_viewer
@@ -52,7 +52,7 @@ module Geoblacklight
52
52
  end
53
53
 
54
54
  def bounding_box_as_wsen
55
- s = get(Settings.GEOMETRY_FIELD.to_sym)
55
+ s = fetch(Settings.GEOMETRY_FIELD.to_sym)
56
56
  if s =~ /^\s*ENVELOPE\(\s*([-\.\d]+)\s*,\s*([-\.\d]+)\s*,\s*([-\.\d]+)\s*,\s*([-\.\d]+)\s*\)\s*$/
57
57
  w, s, e, n = $1, $4, $2, $3
58
58
  return "#{w} #{s} #{e} #{n}"
@@ -1,3 +1,3 @@
1
1
  module Geoblacklight
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -6,16 +6,16 @@ namespace :geoblacklight do
6
6
  desc "Put sample data into solr"
7
7
  task :seed => :environment do
8
8
  docs = Dir['spec/fixtures/solr_documents/*.json'].map { |f| JSON.parse File.read(f) }.flatten
9
- Blacklight.solr.add docs
10
- Blacklight.solr.commit
9
+ Blacklight.default_index.connection.add docs
10
+ Blacklight.default_index.connection.commit
11
11
  end
12
12
 
13
13
  desc "Ingests a GeoHydra transformed.json"
14
14
  task :ingest_all => :environment do
15
15
  docs = JSON::parse(File.read("#{Rails.root}/tmp/transformed.json"))
16
16
  docs.each do |doc|
17
- Blacklight.solr.add doc
18
- Blacklight.solr.commit
17
+ Blacklight.default_index.connection.add doc
18
+ Blacklight.default_index.connection.commit
19
19
  end
20
20
  end
21
21
  end
@@ -1,28 +1 @@
1
- require 'spec_helper'
2
-
3
- describe Geoblacklight::ControllerOverride do
4
- class GeoblacklightControllerTestClass
5
- end
6
-
7
- before(:each) do
8
- @fake_controller = GeoblacklightControllerTestClass.new
9
- @fake_controller.extend(Geoblacklight::ControllerOverride)
10
- end
11
-
12
- let(:solr_params) { OpenStruct.new }
13
- let(:req_params) { OpenStruct.new }
14
-
15
- describe 'add_spatial_params' do
16
- it 'should return the solr_params when no bbox is given' do
17
- expect(@fake_controller.add_spatial_params(solr_params, req_params)).to eq solr_params
18
- end
19
- it 'should return a spatial search if bbox is given' do
20
- req_params.bbox = '123'
21
- expect(has_spatial_query(solr_params, req_params)).to be_truthy
22
- end
23
- end
24
- end
25
-
26
- def has_spatial_query(solr_params, req_params)
27
- /Intersects/ =~ @fake_controller.add_spatial_params(solr_params, req_params).fq.first
28
- end
1
+ require 'spec_helper'
@@ -20,7 +20,11 @@ describe Geoblacklight::Download do
20
20
  end
21
21
  describe '#file_path' do
22
22
  it 'should return the path with name and extension' do
23
- expect(download.file_path).to eq "#{Rails.root}/tmp/cache/downloads/#{download.file_name}"
23
+ expect(download.file_path).to eq "#{Rails.root}/tmp/cache/downloads"
24
+ end
25
+ it 'should be configurable' do
26
+ expect(Settings).to receive(:DOWNLOAD_PATH).and_return('configured/path')
27
+ expect(download.file_path).to eq 'configured/path'
24
28
  end
25
29
  end
26
30
  describe '#download_exists?' do
@@ -41,7 +45,7 @@ describe Geoblacklight::Download do
41
45
  it 'should call create_download_file if it does not exist' do
42
46
  expect(download).to receive(:download_exists?).and_return(false)
43
47
  expect(download).to receive(:initiate_download).and_return(object: 'file')
44
- expect(File).to receive(:open).with("#{download.file_path}.tmp", 'wb').and_return('')
48
+ expect(File).to receive(:open).with("#{download.file_path}/#{download.file_name}.tmp", 'wb').and_return('')
45
49
  expect(File).to receive(:rename)
46
50
  expect(download.get).to eq 'test-shapefile.zip'
47
51
  end
@@ -50,13 +54,13 @@ describe Geoblacklight::Download do
50
54
  it 'should create the file in fs and delete it if the content headers are not correct' do
51
55
  bad_file = OpenStruct.new(headers: { 'content-type' => 'bad/file' })
52
56
  expect(download).to receive(:initiate_download).and_return(bad_file)
53
- expect(File).to receive(:delete).with("#{download.file_path}.tmp").and_return(nil)
57
+ expect(File).to receive(:delete).with("#{download.file_path}/#{download.file_name}.tmp").and_return(nil)
54
58
  expect { download.create_download_file }.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed, 'Wrong download type')
55
59
  end
56
60
  it 'should create the file, write it, and then rename from tmp if everything is ok' do
57
61
  shapefile = OpenStruct.new(headers: {'content-type' => 'application/zip'})
58
62
  expect(download).to receive(:initiate_download).and_return(shapefile)
59
- expect(File).to receive(:open).with("#{download.file_path}.tmp", 'wb').and_return('')
63
+ expect(File).to receive(:open).with("#{download.file_path}/#{download.file_name}.tmp", 'wb').and_return('')
60
64
  expect(File).to receive(:rename)
61
65
  expect(download.create_download_file).to eq download.file_name
62
66
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geoblacklight::SearchBuilder do
4
+ let(:method_chain) { CatalogController.search_params_logic }
5
+ let(:user_params) { Hash.new }
6
+ let(:solr_params) { Hash.new }
7
+ let(:context) { CatalogController.new }
8
+
9
+ let(:search_builder) { described_class.new(method_chain, context) }
10
+
11
+ subject { search_builder.with(user_params) }
12
+
13
+ describe '#add_spatial_params' do
14
+ it 'should return the solr_params when no bbox is given' do
15
+ expect(subject.add_spatial_params(solr_params)).to eq solr_params
16
+ end
17
+
18
+ it 'should return a spatial search if bbox is given' do
19
+ params = { :bbox => '123' }
20
+ subject.with(params)
21
+ expect(subject.add_spatial_params(solr_params)[:fq].to_s).to include("Intersects")
22
+ end
23
+ end
24
+ end
25
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoblacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Graves
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-03-04 00:00:00.000000000 Z
14
+ date: 2015-04-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: blacklight
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.9'
22
+ version: 5.12.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '5.9'
29
+ version: 5.12.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: leaflet-rails
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -350,6 +350,7 @@ files:
350
350
  - lib/geoblacklight/reference.rb
351
351
  - lib/geoblacklight/references.rb
352
352
  - lib/geoblacklight/routes.rb
353
+ - lib/geoblacklight/search_builder.rb
353
354
  - lib/geoblacklight/solr_document.rb
354
355
  - lib/geoblacklight/version.rb
355
356
  - lib/geoblacklight/view_helper_override.rb
@@ -392,6 +393,7 @@ files:
392
393
  - spec/lib/geoblacklight/item_viewer_spec.rb
393
394
  - spec/lib/geoblacklight/metadata_spec.rb
394
395
  - spec/lib/geoblacklight/references_spec.rb
396
+ - spec/lib/geoblacklight/search_builder_spec.rb
395
397
  - spec/lib/geoblacklight/solr_document_spec.rb
396
398
  - spec/lib/geoblacklight/view_helper_override_spec.rb
397
399
  - spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb
@@ -426,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
426
428
  version: '0'
427
429
  requirements: []
428
430
  rubyforge_project:
429
- rubygems_version: 2.4.5
431
+ rubygems_version: 2.4.6
430
432
  signing_key:
431
433
  specification_version: 4
432
434
  summary: A discovery platform for geospatial holdings
@@ -466,6 +468,7 @@ test_files:
466
468
  - spec/lib/geoblacklight/item_viewer_spec.rb
467
469
  - spec/lib/geoblacklight/metadata_spec.rb
468
470
  - spec/lib/geoblacklight/references_spec.rb
471
+ - spec/lib/geoblacklight/search_builder_spec.rb
469
472
  - spec/lib/geoblacklight/solr_document_spec.rb
470
473
  - spec/lib/geoblacklight/view_helper_override_spec.rb
471
474
  - spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb