geoblacklight 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +19 -19
  4. data/app/assets/stylesheets/geoblacklight/_geoblacklight.scss +2 -0
  5. data/app/assets/stylesheets/geoblacklight/modules/coderay.scss +147 -0
  6. data/app/assets/stylesheets/geoblacklight/modules/icon-customization.scss +5 -1
  7. data/app/assets/stylesheets/geoblacklight/modules/metadata.scss +5 -0
  8. data/app/assets/stylesheets/geoblacklight/modules/results.scss +1 -0
  9. data/app/assets/stylesheets/geoblacklight/modules/toolbar.scss +6 -0
  10. data/app/controllers/download_controller.rb +5 -5
  11. data/app/views/catalog/_downloads.html.erb +48 -0
  12. data/app/views/catalog/_home_text.html.erb +6 -6
  13. data/app/views/catalog/_index_split_default.html.erb +2 -2
  14. data/app/views/catalog/_metadata.html.erb +12 -0
  15. data/app/views/catalog/_search_form_no_navbar.html.erb +2 -2
  16. data/app/views/catalog/metadata.html.erb +1 -0
  17. data/app/views/catalog/metadata.js.erb +7 -0
  18. data/app/views/catalog/{web_services.html → web_services.html.erb} +0 -0
  19. data/config/locales/geoblacklight.en.yml +3 -0
  20. data/geoblacklight.gemspec +1 -0
  21. data/lib/generators/geoblacklight/templates/catalog_controller.rb +2 -0
  22. data/lib/generators/geoblacklight/templates/settings.yml +7 -1
  23. data/lib/geoblacklight.rb +1 -0
  24. data/lib/geoblacklight/controller_override.rb +4 -0
  25. data/lib/geoblacklight/download.rb +70 -58
  26. data/lib/geoblacklight/download/geojson_download.rb +19 -17
  27. data/lib/geoblacklight/download/geotiff_download.rb +17 -15
  28. data/lib/geoblacklight/download/hgl_download.rb +15 -13
  29. data/lib/geoblacklight/download/kmz_download.rb +14 -12
  30. data/lib/geoblacklight/download/shapefile_download.rb +14 -12
  31. data/lib/geoblacklight/engine.rb +1 -0
  32. data/lib/geoblacklight/metadata.rb +41 -0
  33. data/lib/geoblacklight/routes.rb +1 -0
  34. data/lib/geoblacklight/solr_document.rb +7 -1
  35. data/lib/geoblacklight/version.rb +1 -1
  36. data/lib/tasks/configure_solr.rake +36 -0
  37. data/lib/tasks/geoblacklight.rake +0 -6
  38. data/spec/controllers/download_controller_spec.rb +1 -1
  39. data/spec/features/download_layer_spec.rb +3 -3
  40. data/spec/features/metadata_panel_spec.rb +22 -0
  41. data/spec/fixtures/solr_documents/actual-papermap1.json +0 -1
  42. data/spec/fixtures/solr_documents/actual-point1.json +0 -1
  43. data/spec/fixtures/solr_documents/actual-polygon1.json +1 -2
  44. data/spec/fixtures/solr_documents/actual-raster1.json +1 -2
  45. data/spec/fixtures/solr_documents/harvard_raster.json +1 -2
  46. data/spec/fixtures/solr_documents/public_iiif_princeton.json +0 -1
  47. data/spec/fixtures/solr_documents/public_polygon_mit.json +1 -6
  48. data/spec/fixtures/solr_documents/restricted-line.json +1 -2
  49. data/spec/lib/geoblacklight/download/geojson_download_spec.rb +9 -4
  50. data/spec/lib/geoblacklight/download/geotiff_download_spec.rb +9 -4
  51. data/spec/lib/geoblacklight/download/hgl_download_spec.rb +8 -3
  52. data/spec/lib/geoblacklight/download/kmz_download_spec.rb +9 -4
  53. data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +9 -4
  54. data/spec/lib/geoblacklight/download_spec.rb +3 -3
  55. data/spec/lib/geoblacklight/metadata_spec.rb +25 -0
  56. metadata +29 -4
  57. data/app/views/catalog/_show_tools.html.erb +0 -63
@@ -0,0 +1 @@
1
+ <%= render :partial => 'metadata' %>
@@ -0,0 +1,7 @@
1
+ <div class="modal-header">
2
+ <button type="button" class="ajax-modal-close close" data-dismiss="modal" aria-hidden="true">×</button>
3
+ <h1 class="modal-title">Metadata</h1>
4
+ <div class="modal-body">
5
+ <%= render partial: 'metadata' %>
6
+ </div>
7
+ </div>
@@ -21,3 +21,6 @@ en:
21
21
  references:
22
22
  wms: 'Web Mapping Service (WMS)'
23
23
  wfs: 'Web Feature Service (WFS)'
24
+ iso19139: 'ISO 19139'
25
+ mods: 'MODS'
26
+ fgdc: 'FGDC'
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'font-awesome-rails', '~> 4.1.0.0'
25
25
  spec.add_dependency 'rails_config'
26
26
  spec.add_dependency 'faraday'
27
+ spec.add_dependency 'coderay'
27
28
 
28
29
  spec.add_development_dependency 'bundler', '~> 1.5'
29
30
  spec.add_development_dependency 'rake', '~> 10.3.2'
@@ -208,6 +208,8 @@ class CatalogController < ApplicationController
208
208
 
209
209
  # Custom tools for GeoBlacklight
210
210
  config.add_show_tools_partial :web_services, if: proc { |_context, _config, options| (Settings.WEBSERVICES_SHOWN & options[:document].references.refs.map(&:type).map(&:to_s)).any? }
211
+ config.add_show_tools_partial :metadata, if: proc { |_context, _config, options| (Settings.METADATA_SHOWN & options[:document].references.refs.map(&:type).map(&:to_s)).any? }
212
+ config.add_show_tools_partial :downloads, partial: 'downloads'
211
213
  end
212
214
 
213
215
 
@@ -1,9 +1,15 @@
1
1
  #Main Solr geometry field used for spatial search and bounding box. Should be type 'rpt'
2
- GEOMETRY_FIELD: 'solr_bbox'
2
+ GEOMETRY_FIELD: 'solr_geom'
3
3
 
4
4
  # Institution deployed at
5
5
  INSTITUTION: 'Stanford'
6
6
 
7
+ # Metadata shown in tool panel
8
+ METADATA_SHOWN:
9
+ - 'fgdc'
10
+ - 'iso19139'
11
+ - 'mods'
12
+
7
13
  # (For external Download) timeout and open_timeout parameters for Faraday
8
14
  TIMEOUT_DOWNLOAD: 16
9
15
 
data/lib/geoblacklight.rb CHANGED
@@ -17,6 +17,7 @@ module Geoblacklight
17
17
  require 'geoblacklight/download/kmz_download'
18
18
  require 'geoblacklight/download/shapefile_download'
19
19
  require 'geoblacklight/download/hgl_download'
20
+ require 'geoblacklight/metadata'
20
21
  require 'geoblacklight/reference'
21
22
  require 'geoblacklight/references'
22
23
  require 'geoblacklight/routes'
@@ -18,5 +18,9 @@ module Geoblacklight
18
18
  def web_services
19
19
  @response, @document = get_solr_response_for_doc_id params[:id]
20
20
  end
21
+
22
+ def metadata
23
+ @response, @document = get_solr_response_for_doc_id params[:id]
24
+ end
21
25
  end
22
26
  end
@@ -1,72 +1,84 @@
1
- class Download
2
- def initialize(document, options = {})
3
- @document = document
4
- @options = options
5
- end
1
+ module Geoblacklight
2
+ class Download
3
+ def initialize(document, options = {})
4
+ @document = document
5
+ @options = options
6
+ end
6
7
 
7
- def downloadable?
8
- @document.downloadable?
9
- end
8
+ def downloadable?
9
+ @document.downloadable?
10
+ end
10
11
 
11
- def file_name
12
- "#{@document[:layer_slug_s]}-#{@options[:type]}.#{@options[:extension]}"
13
- end
12
+ def file_name
13
+ "#{@document[:layer_slug_s]}-#{@options[:type]}.#{@options[:extension]}"
14
+ end
14
15
 
15
- def file_path
16
- "#{Rails.root}/tmp/cache/downloads/#{file_name}"
17
- end
16
+ def file_path
17
+ "#{Rails.root}/tmp/cache/downloads/#{file_name}"
18
+ end
18
19
 
19
- def download_exists?
20
- File.file?(file_path)
21
- end
20
+ def download_exists?
21
+ File.file?(file_path)
22
+ end
22
23
 
23
- def get
24
- if download_exists?
25
- file_name
26
- else
27
- create_download_file
24
+ def get
25
+ if download_exists?
26
+ file_name
27
+ else
28
+ create_download_file
29
+ end
28
30
  end
29
- end
30
31
 
31
- def create_download_file
32
- download = initiate_download
33
- unless download.present?
34
- raise Geoblacklight::Exceptions::ExternalDownloadFailed
32
+ def create_download_file
33
+ download = initiate_download
34
+ unless download.present?
35
+ raise Geoblacklight::Exceptions::ExternalDownloadFailed
36
+ end
37
+ File.open("#{file_path}.tmp", 'wb') do |file|
38
+ if download.headers['content-type'] == @options[:content_type]
39
+ file.write download.body
40
+ else
41
+ fail Geoblacklight::Exceptions::WrongDownloadFormat
42
+ end
43
+ end
44
+ File.rename("#{file_path}.tmp", file_path)
45
+ file_name
46
+ rescue Geoblacklight::Exceptions::ExternalDownloadFailed
47
+ Geoblacklight.logger.error 'Download from external server failed'
48
+ nil
49
+ rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
50
+ Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} received #{download.headers['content-type']}"
51
+ File.delete("#{file_path}.tmp")
52
+ nil
35
53
  end
36
- File.open("#{file_path}.tmp", 'wb') do |file|
37
- if download.headers['content-type'] == @options[:content_type]
38
- file.write download.body
39
- else
40
- fail Geoblacklight::Exceptions::WrongDownloadFormat
54
+
55
+ def initiate_download
56
+ url = @document.references.send(@options[:service_type]).endpoint
57
+ url += '/reflect' if @options[:reflect]
58
+ conn = Faraday.new(url: url)
59
+ conn.get do |request|
60
+ request.params = @options[:request_params]
61
+ request.options = {
62
+ timeout: timeout,
63
+ open_timeout: timeout
64
+ }
41
65
  end
66
+ rescue Faraday::Error::ConnectionFailed => error
67
+ Geoblacklight.logger.error error.inspect
68
+ nil
69
+ rescue Faraday::Error::TimeoutError => error
70
+ Geoblacklight.logger.error error.inspect
71
+ nil
42
72
  end
43
- File.rename("#{file_path}.tmp", file_path)
44
- file_name
45
- rescue Geoblacklight::Exceptions::ExternalDownloadFailed
46
- Geoblacklight.logger.error 'Download from external server failed'
47
- nil
48
- rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
49
- Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} received #{download.headers['content-type']}"
50
- File.delete("#{file_path}.tmp")
51
- nil
52
- end
53
73
 
54
- def initiate_download
55
- url = @document.references.send(@options[:service_type]).endpoint
56
- url += '/reflect' if @options[:reflect]
57
- conn = Faraday.new(url: url)
58
- conn.get do |request|
59
- request.params = @options[:request_params]
60
- request.options = {
61
- timeout: Settings.TIMEOUT_DOWNLOAD,
62
- open_timeout: Settings.TIMEOUT_DOWNLOAD
63
- }
74
+ private
75
+
76
+ ##
77
+ # Returns timeout for the download request. `timeout` passed as an option to
78
+ # the Geoblacklight::Download class
79
+ # @returns [Fixnum] download timeout in seconds
80
+ def timeout
81
+ @options[:timeout] || Settings.TIMEOUT_DOWNLOAD || 20
64
82
  end
65
- rescue Faraday::Error::ConnectionFailed => error
66
- Geoblacklight.logger.error error.inspect
67
- nil
68
- rescue Faraday::Error::TimeoutError => error
69
- Geoblacklight.logger.error error.inspect
70
- nil
71
83
  end
72
84
  end
@@ -1,20 +1,22 @@
1
- class GeojsonDownload < Download
2
- GEOJSON_DOWNLOAD_PARAMS = {
3
- service: 'wfs',
4
- version: '2.0.0',
5
- request: 'GetFeature',
6
- srsName: 'EPSG:4326',
7
- outputformat: 'application/json'
8
- }
1
+ module Geoblacklight
2
+ class GeojsonDownload < Geoblacklight::Download
3
+ GEOJSON_DOWNLOAD_PARAMS = {
4
+ service: 'wfs',
5
+ version: '2.0.0',
6
+ request: 'GetFeature',
7
+ srsName: 'EPSG:4326',
8
+ outputformat: 'application/json'
9
+ }
9
10
 
10
- def initialize(document)
11
- request_params = GEOJSON_DOWNLOAD_PARAMS.merge(typeName: document[:layer_id_s])
12
- super(document, {
13
- type: 'geojson',
14
- extension: 'json',
15
- request_params: request_params,
16
- content_type: 'application/json',
17
- service_type: 'wfs'
18
- })
11
+ def initialize(document, options = {})
12
+ request_params = GEOJSON_DOWNLOAD_PARAMS.merge(typeName: document[:layer_id_s])
13
+ super(document, {
14
+ type: 'geojson',
15
+ extension: 'json',
16
+ request_params: request_params,
17
+ content_type: 'application/json',
18
+ service_type: 'wfs'
19
+ }.merge(options))
20
+ end
19
21
  end
20
22
  end
@@ -1,18 +1,20 @@
1
- class GeotiffDownload < Download
2
- GEOTIFF_DOWNLOAD_PARAMS = {
3
- format: 'image/geotiff',
4
- width: 4096
5
- }
1
+ module Geoblacklight
2
+ class GeotiffDownload < Geoblacklight::Download
3
+ GEOTIFF_DOWNLOAD_PARAMS = {
4
+ format: 'image/geotiff',
5
+ width: 4096
6
+ }
6
7
 
7
- def initialize(document)
8
- request_params = GEOTIFF_DOWNLOAD_PARAMS.merge(layers: document[:layer_id_s])
9
- super(document, {
10
- type: 'geotiff',
11
- extension: 'tif',
12
- request_params: request_params,
13
- content_type: 'image/geotiff',
14
- service_type: 'wms',
15
- reflect: true
16
- })
8
+ def initialize(document, options = {})
9
+ request_params = GEOTIFF_DOWNLOAD_PARAMS.merge(layers: document[:layer_id_s])
10
+ super(document, {
11
+ type: 'geotiff',
12
+ extension: 'tif',
13
+ request_params: request_params,
14
+ content_type: 'image/geotiff',
15
+ service_type: 'wms',
16
+ reflect: true
17
+ }.merge(options))
18
+ end
17
19
  end
18
20
  end
@@ -1,17 +1,19 @@
1
- class HglDownload < Download
2
- def initialize(document, email)
1
+ module Geoblacklight
2
+ class HglDownload < Geoblacklight::Download
3
+ def initialize(document, email, options = {})
3
4
 
4
- request_params = {
5
- "LayerName" => document[:layer_id_s].sub(/^cite:/, ''),
6
- "UserEmail" => email
7
- }
8
- super(document, {
9
- request_params: request_params,
10
- service_type: 'hgl'
11
- })
12
- end
5
+ request_params = {
6
+ "LayerName" => document[:layer_id_s].sub(/^cite:/, ''),
7
+ "UserEmail" => email
8
+ }
9
+ super(document, {
10
+ request_params: request_params,
11
+ service_type: 'hgl'
12
+ }.merge(options))
13
+ end
13
14
 
14
- def get
15
- initiate_download
15
+ def get
16
+ initiate_download
17
+ end
16
18
  end
17
19
  end
@@ -1,14 +1,16 @@
1
- class KmzDownload < Download
2
- KMZ_DOWNLOAD_PARAMS = { service: 'wms', version: '1.1.0', request: 'GetMap', srsName: 'EPSG:900913', format: 'application/vnd.google-earth.kmz', width: 2000, height: 2000 }
3
-
4
- def initialize(document)
5
- request_params = KMZ_DOWNLOAD_PARAMS.merge(layers: document[:layer_id_s], bbox: document.bounding_box_as_wsen.split(' ').join(', '))
6
- super(document, {
7
- type: 'kmz',
8
- extension: 'kmz',
9
- request_params: request_params,
10
- content_type: 'application/vnd.google-earth.kmz',
11
- service_type: 'wms'
12
- })
1
+ module Geoblacklight
2
+ class KmzDownload < Geoblacklight::Download
3
+ KMZ_DOWNLOAD_PARAMS = { service: 'wms', version: '1.1.0', request: 'GetMap', srsName: 'EPSG:900913', format: 'application/vnd.google-earth.kmz', width: 2000, height: 2000 }
4
+
5
+ def initialize(document, options = {})
6
+ request_params = KMZ_DOWNLOAD_PARAMS.merge(layers: document[:layer_id_s], bbox: document.bounding_box_as_wsen.split(' ').join(', '))
7
+ super(document, {
8
+ type: 'kmz',
9
+ extension: 'kmz',
10
+ request_params: request_params,
11
+ content_type: 'application/vnd.google-earth.kmz',
12
+ service_type: 'wms'
13
+ }.merge(options))
14
+ end
13
15
  end
14
16
  end
@@ -1,14 +1,16 @@
1
- class ShapefileDownload < Download
2
- SHAPEFILE_DOWNLOAD_PARAMS = { service: 'wfs', version: '2.0.0', request: 'GetFeature', srsName: 'EPSG:4326', outputformat: 'SHAPE-ZIP' }
3
-
4
- def initialize(document)
5
- request_params = SHAPEFILE_DOWNLOAD_PARAMS.merge(typeName: document[:layer_id_s])
6
- super(document, {
7
- type: 'shapefile',
8
- extension: 'zip',
9
- request_params: request_params,
10
- content_type: 'application/zip',
11
- service_type: 'wfs'
12
- })
1
+ module Geoblacklight
2
+ class ShapefileDownload < Geoblacklight::Download
3
+ SHAPEFILE_DOWNLOAD_PARAMS = { service: 'wfs', version: '2.0.0', request: 'GetFeature', srsName: 'EPSG:4326', outputformat: 'SHAPE-ZIP' }
4
+
5
+ def initialize(document, options = {})
6
+ request_params = SHAPEFILE_DOWNLOAD_PARAMS.merge(typeName: document[:layer_id_s])
7
+ super(document, {
8
+ type: 'shapefile',
9
+ extension: 'zip',
10
+ request_params: request_params,
11
+ content_type: 'application/zip',
12
+ service_type: 'wfs'
13
+ }.merge(options))
14
+ end
13
15
  end
14
16
  end
@@ -5,6 +5,7 @@ require 'rails_config'
5
5
  require 'faraday'
6
6
  require 'blacklight_range_limit'
7
7
  require 'nokogiri'
8
+ require 'coderay'
8
9
 
9
10
  module Geoblacklight
10
11
  class Engine < ::Rails::Engine
@@ -0,0 +1,41 @@
1
+ module Geoblacklight
2
+ class Metadata
3
+
4
+ ##
5
+ # Instantiates a Geoblacklight::Metadata object used for retrieving and
6
+ # formatting metadata
7
+ # @param reference [Geoblacklight::Reference] the reference object
8
+ def initialize(reference)
9
+ @reference = reference
10
+ end
11
+
12
+ ##
13
+ # Handles metadata and returns the retrieved metadata or an error message if
14
+ # something went wrong
15
+ # @return [String] returned metadata string
16
+ def metadata
17
+ response = retrieve_metadata
18
+ if response.nil? || response.status == 404
19
+ Geoblacklight.logger.error "Could not reach #{@reference.endpoint}"
20
+ return "Could not reach #{@reference.endpoint}"
21
+ else
22
+ return response.body
23
+ end
24
+ end
25
+
26
+ ##
27
+ # Retrieves metadata from a url source
28
+ # @return [Faraday::Response, nil] Faraday::Response or nil if there is a
29
+ # connection error
30
+ def retrieve_metadata
31
+ conn = Faraday.new(url: @reference.endpoint)
32
+ conn.get
33
+ rescue Faraday::Error::ConnectionFailed => error
34
+ Geoblacklight.logger.error error.inspect
35
+ nil
36
+ rescue Faraday::Error::TimeoutError => error
37
+ Geoblacklight.logger.error error.inspect
38
+ nil
39
+ end
40
+ end
41
+ end