geoblacklight 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +19 -19
- data/app/assets/stylesheets/geoblacklight/_geoblacklight.scss +2 -0
- data/app/assets/stylesheets/geoblacklight/modules/coderay.scss +147 -0
- data/app/assets/stylesheets/geoblacklight/modules/icon-customization.scss +5 -1
- data/app/assets/stylesheets/geoblacklight/modules/metadata.scss +5 -0
- data/app/assets/stylesheets/geoblacklight/modules/results.scss +1 -0
- data/app/assets/stylesheets/geoblacklight/modules/toolbar.scss +6 -0
- data/app/controllers/download_controller.rb +5 -5
- data/app/views/catalog/_downloads.html.erb +48 -0
- data/app/views/catalog/_home_text.html.erb +6 -6
- data/app/views/catalog/_index_split_default.html.erb +2 -2
- data/app/views/catalog/_metadata.html.erb +12 -0
- data/app/views/catalog/_search_form_no_navbar.html.erb +2 -2
- data/app/views/catalog/metadata.html.erb +1 -0
- data/app/views/catalog/metadata.js.erb +7 -0
- data/app/views/catalog/{web_services.html → web_services.html.erb} +0 -0
- data/config/locales/geoblacklight.en.yml +3 -0
- data/geoblacklight.gemspec +1 -0
- data/lib/generators/geoblacklight/templates/catalog_controller.rb +2 -0
- data/lib/generators/geoblacklight/templates/settings.yml +7 -1
- data/lib/geoblacklight.rb +1 -0
- data/lib/geoblacklight/controller_override.rb +4 -0
- data/lib/geoblacklight/download.rb +70 -58
- data/lib/geoblacklight/download/geojson_download.rb +19 -17
- data/lib/geoblacklight/download/geotiff_download.rb +17 -15
- data/lib/geoblacklight/download/hgl_download.rb +15 -13
- data/lib/geoblacklight/download/kmz_download.rb +14 -12
- data/lib/geoblacklight/download/shapefile_download.rb +14 -12
- data/lib/geoblacklight/engine.rb +1 -0
- data/lib/geoblacklight/metadata.rb +41 -0
- data/lib/geoblacklight/routes.rb +1 -0
- data/lib/geoblacklight/solr_document.rb +7 -1
- data/lib/geoblacklight/version.rb +1 -1
- data/lib/tasks/configure_solr.rake +36 -0
- data/lib/tasks/geoblacklight.rake +0 -6
- data/spec/controllers/download_controller_spec.rb +1 -1
- data/spec/features/download_layer_spec.rb +3 -3
- data/spec/features/metadata_panel_spec.rb +22 -0
- data/spec/fixtures/solr_documents/actual-papermap1.json +0 -1
- data/spec/fixtures/solr_documents/actual-point1.json +0 -1
- data/spec/fixtures/solr_documents/actual-polygon1.json +1 -2
- data/spec/fixtures/solr_documents/actual-raster1.json +1 -2
- data/spec/fixtures/solr_documents/harvard_raster.json +1 -2
- data/spec/fixtures/solr_documents/public_iiif_princeton.json +0 -1
- data/spec/fixtures/solr_documents/public_polygon_mit.json +1 -6
- data/spec/fixtures/solr_documents/restricted-line.json +1 -2
- data/spec/lib/geoblacklight/download/geojson_download_spec.rb +9 -4
- data/spec/lib/geoblacklight/download/geotiff_download_spec.rb +9 -4
- data/spec/lib/geoblacklight/download/hgl_download_spec.rb +8 -3
- data/spec/lib/geoblacklight/download/kmz_download_spec.rb +9 -4
- data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +9 -4
- data/spec/lib/geoblacklight/download_spec.rb +3 -3
- data/spec/lib/geoblacklight/metadata_spec.rb +25 -0
- metadata +29 -4
- data/app/views/catalog/_show_tools.html.erb +0 -63
@@ -0,0 +1 @@
|
|
1
|
+
<%= render :partial => 'metadata' %>
|
File without changes
|
data/geoblacklight.gemspec
CHANGED
@@ -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: '
|
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'
|
@@ -1,72 +1,84 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Geoblacklight
|
2
|
+
class Download
|
3
|
+
def initialize(document, options = {})
|
4
|
+
@document = document
|
5
|
+
@options = options
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def downloadable?
|
9
|
+
@document.downloadable?
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def file_name
|
13
|
+
"#{@document[:layer_slug_s]}-#{@options[:type]}.#{@options[:extension]}"
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def file_path
|
17
|
+
"#{Rails.root}/tmp/cache/downloads/#{file_name}"
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def download_exists?
|
21
|
+
File.file?(file_path)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Geoblacklight
|
2
|
+
class GeotiffDownload < Geoblacklight::Download
|
3
|
+
GEOTIFF_DOWNLOAD_PARAMS = {
|
4
|
+
format: 'image/geotiff',
|
5
|
+
width: 4096
|
6
|
+
}
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
2
|
-
|
1
|
+
module Geoblacklight
|
2
|
+
class HglDownload < Geoblacklight::Download
|
3
|
+
def initialize(document, email, options = {})
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
15
|
+
def get
|
16
|
+
initiate_download
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
data/lib/geoblacklight/engine.rb
CHANGED
@@ -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
|