geoblacklight 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -13
  2. data/.coveralls.yml +1 -0
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +9 -0
  5. data/Gemfile +18 -0
  6. data/README.md +36 -38
  7. data/Rakefile +9 -9
  8. data/app/assets/fonts/geoblacklight.eot +0 -0
  9. data/app/assets/fonts/geoblacklight.svg +117 -0
  10. data/app/assets/fonts/geoblacklight.ttf +0 -0
  11. data/app/assets/fonts/geoblacklight.woff +0 -0
  12. data/app/assets/images/blacklight/logo.png +0 -0
  13. data/app/assets/javascripts/geoblacklight/application.js +1 -0
  14. data/app/assets/javascripts/geoblacklight/geoblacklight.js +86 -2
  15. data/app/assets/javascripts/geoblacklight/modules/collapse.js +6 -0
  16. data/app/assets/javascripts/geoblacklight/modules/download.js +45 -0
  17. data/app/assets/javascripts/geoblacklight/modules/geosearch.js +77 -0
  18. data/app/assets/javascripts/geoblacklight/modules/home.js +10 -0
  19. data/app/assets/javascripts/geoblacklight/modules/item.js +72 -0
  20. data/app/assets/javascripts/geoblacklight/modules/map-view.js +7 -7
  21. data/app/assets/javascripts/geoblacklight/modules/results.js +50 -0
  22. data/app/assets/stylesheets/geoblacklight/_geoblacklight.css.scss +20 -0
  23. data/app/assets/stylesheets/geoblacklight/_styles.css.scss +44 -0
  24. data/app/assets/stylesheets/geoblacklight/application.css.scss +3 -0
  25. data/app/assets/stylesheets/geoblacklight/modules/home.css.scss +3 -0
  26. data/app/assets/stylesheets/geoblacklight/modules/icon-customization.css.scss +10 -0
  27. data/app/assets/stylesheets/geoblacklight/modules/icons.css.scss +77 -0
  28. data/app/assets/stylesheets/geoblacklight/modules/item.css.scss +4 -0
  29. data/app/assets/stylesheets/geoblacklight/modules/results.css.scss +29 -0
  30. data/app/controllers/download_controller.rb +22 -94
  31. data/app/controllers/wms_controller.rb +2 -74
  32. data/app/helpers/geoblacklight_helper.rb +6 -36
  33. data/app/views/catalog/_document_split.html.erb +4 -0
  34. data/app/views/catalog/_home_text.html.erb +2 -39
  35. data/app/views/catalog/_index_split_default.html.erb +24 -0
  36. data/app/views/catalog/_show_default.html.erb +4 -57
  37. data/app/views/catalog/_show_header_default.html.erb +8 -0
  38. data/app/views/catalog/_show_sidebar.html.erb +17 -57
  39. data/app/views/catalog/_upper_metadata.html.erb +38 -0
  40. data/config/initializers/rails_config.rb +3 -0
  41. data/config/jetty.yml +6 -0
  42. data/config/locales/geoblacklight.en.yml +5 -0
  43. data/geoblacklight.gemspec +5 -5
  44. data/lib/generators/geoblacklight/install_generator.rb +45 -15
  45. data/lib/generators/geoblacklight/templates/geoblacklight.css.scss +2 -78
  46. data/lib/generators/geoblacklight/templates/settings.yml +9 -0
  47. data/lib/geoblacklight.rb +13 -0
  48. data/lib/geoblacklight/controller_override.rb +18 -0
  49. data/lib/geoblacklight/download.rb +63 -0
  50. data/lib/geoblacklight/download/kmz_download.rb +14 -0
  51. data/lib/geoblacklight/download/shapefile_download.rb +14 -0
  52. data/lib/geoblacklight/engine.rb +11 -1
  53. data/lib/geoblacklight/solr_document.rb +30 -0
  54. data/lib/geoblacklight/version.rb +1 -1
  55. data/lib/geoblacklight/view_helper_override.rb +17 -0
  56. data/lib/geoblacklight/wms_layer.rb +38 -0
  57. data/lib/geoblacklight/wms_layer/feature_info_response.rb +30 -0
  58. data/lib/tasks/geoblacklight.rake +15 -0
  59. data/spec/features/download_layer_spec.rb +18 -0
  60. data/spec/features/home_page_spec.rb +49 -0
  61. data/spec/features/layer_inspection_spec.rb +9 -0
  62. data/spec/features/layer_preview_spec.rb +16 -0
  63. data/spec/features/split_view.html.erb_spec.rb +35 -0
  64. data/spec/fixtures/test-berkeley-fields.json +44 -0
  65. data/spec/lib/geoblacklight/controller_override_spec.rb +28 -0
  66. data/spec/lib/geoblacklight/download/kmz_download_spec.rb +15 -0
  67. data/spec/lib/geoblacklight/download/shapefile_download_spec.rb +14 -0
  68. data/spec/lib/geoblacklight/download_spec.rb +76 -0
  69. data/spec/lib/geoblacklight/solr_document.rb +52 -0
  70. data/spec/lib/geoblacklight/view_helper_override_spec.rb +23 -0
  71. data/spec/lib/geoblacklight/wms_layer/feature_info_response_spec.rb +43 -0
  72. data/spec/lib/geoblacklight/wms_layer_spec.rb +33 -0
  73. data/spec/spec_helper.rb +3 -6
  74. data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -2
  75. data/spec/views/catalog/_document_split.html.erb_spec.rb +5 -0
  76. data/spec/views/catalog/_index_split.html.erb_spec.rb +5 -0
  77. data/template.rb +10 -0
  78. data/vendor/assets/javascripts/native.history.js +1 -0
  79. metadata +129 -82
  80. data/app/assets/images/geoblacklight/src_berkeley.png +0 -0
  81. data/app/assets/images/geoblacklight/src_cambridge.png +0 -0
  82. data/app/assets/images/geoblacklight/src_harvard.png +0 -0
  83. data/app/assets/images/geoblacklight/src_maryland.png +0 -0
  84. data/app/assets/images/geoblacklight/src_massgis.png +0 -0
  85. data/app/assets/images/geoblacklight/src_mit.png +0 -0
  86. data/app/assets/images/geoblacklight/src_princeton.png +0 -0
  87. data/app/assets/images/geoblacklight/src_stanford.png +0 -0
  88. data/app/assets/images/geoblacklight/src_tufts.png +0 -0
  89. data/app/assets/images/geoblacklight/src_un.png +0 -0
  90. data/app/assets/images/geoblacklight/type_arc.png +0 -0
  91. data/app/assets/images/geoblacklight/type_dot.png +0 -0
  92. data/app/assets/images/geoblacklight/type_library.png +0 -0
  93. data/app/assets/images/geoblacklight/type_map.png +0 -0
  94. data/app/assets/images/geoblacklight/type_polygon.png +0 -0
  95. data/app/assets/images/geoblacklight/type_raster.png +0 -0
  96. data/app/assets/javascripts/geoblacklight/modules/map-home.js +0 -25
  97. data/app/assets/javascripts/geoblacklight/modules/map-results.js +0 -72
  98. data/app/views/catalog/_document_list.html.erb +0 -12
  99. data/app/views/catalog/_index_header_default.html.erb +0 -59
  100. data/spec/fixtures/geoblacklight_schema/transformed.json +0 -53
@@ -0,0 +1,8 @@
1
+ <h2>
2
+ <span itemprop="name"><%= document_heading(document) %></span>
3
+ <small>
4
+ <%= layer_type_image(document['layer_geom_type_s']) %>
5
+ <%= layer_institution_image(document['dct_provenance_s']) %>
6
+ <%= layer_access_image(document['dc_rights_s']) %>
7
+ </small>
8
+ </h2>
@@ -1,12 +1,5 @@
1
- <%-
2
- # Compare with render_document_functions_partial helper, and
3
- # _document_functions partial. BL actually has two groups
4
- # of document-related tools. "document functions" by default
5
- # contains Bookmark functionality shown on both results and
6
- # item view. While "document tools" contains external export type
7
- # functions by default only on detail.
1
+ <% document ||= @document %>
8
2
 
9
- -%>
10
3
  <div id='geoblacklight-tools'>
11
4
  <div class="panel panel-default show-tools">
12
5
  <div class="panel-heading">
@@ -14,10 +7,7 @@
14
7
  </div>
15
8
  <div class="panel-body">
16
9
  <ul class="list-group">
17
- <%= render_show_doc_actions @document %>
18
- <!-- <a href="#" data-no-turbolink class="list-group-item disabled">
19
- <i class="fa fa-li fa-star-o"></i> Bookmark
20
- </a> -->
10
+ <%= render_show_doc_actions @document, wrapping_class: 'list-group-item' %>
21
11
  <% if @document.respond_to?( :to_email_text ) %>
22
12
  <%= link_to email_helper, email_catalog_path(:id => @document), {:id => 'emailLink', :data => {:ajax_modal => "trigger"}, :class => 'list-group-item'} %>
23
13
  <%- end -%>
@@ -25,52 +15,22 @@
25
15
  <%= link_to sms_helper, sms_catalog_path(:id => @document), {:id => 'smsLink', :data => {:ajax_modal => "trigger"}, :class => 'list-group-item'} %>
26
16
  <%- end -%>
27
17
  <a href="#" data-no-turbolink class="list-group-item">
28
- <i class="fa fa-li fa-bookmark"></i>Cite This
29
- </a>
18
+ <i class="fa fa-bookmark fa-fw"></i>&nbsp;Cite This
19
+ </a>
30
20
  </ul>
31
- <ul class="list-group">
32
- <a id="download-metadata" data-no-turbolink class="list-group-item"
33
- <% if @document['dct_provenance_s'] == 'Stanford' %>
34
- href="<%= @document['dc_identifier_s'] %>.mods"
35
- <% else %>
36
- href="#"
37
- <% end %>
38
- >
39
- <i class="fa fa-li fa-download" id="icon-metadata"></i>Metadata
40
- </a>
41
- <% if @document['dc_rights_s'] == 'Restricted' and @document['dct_provenance_s'] != 'Stanford' %>
42
- <a href="#" data-no-turbolink class="list-group-item">
43
- <i class="fa fa-li fa-download" id="icon-request"></i>Request This
44
- </a><br/>
45
- <% else %>
46
- <a href="#" id="download-kml" data-no-turbolink class="list-group-item">
47
- <i class="fa fa-li fa-download" id="icon-kml"></i>KML
48
- </a>
49
- <% if @document['dc_format_s'] == 'Shapefile' %>
50
- <a href="#" id="download-shapefile" data-no-turbolink class="list-group-item">
51
- <i class="fa fa-li fa-download" id="icon-shapefile"></i>Shapefile
52
- </a>
53
- <% end %>
21
+ <% if document.downloadable? %>
22
+ <div class='btn-group'>
23
+ <%= button_tag(type: 'button', class: 'btn btn-default dropdown-toggle', data: { toggle: 'dropdown' }) do %>
24
+ Download <span class='caret'></span>
25
+ <% end %>
26
+ <ul class="dropdown-menu" role="menu">
27
+ <% document.download_types.each do |type| %>
28
+ <%= content_tag(:li) do %>
29
+ <%= link_to(type[:label], '', data: { download_path: "#{download_path(document[:layer_slug_s], type: type[:type])}" }) %>
30
+ <% end %>
31
+ <% end %>
32
+ </ul>
33
+ </div>
54
34
  <% end %>
55
-
56
- </ul>
57
- <% unless @document['dc_rights_s'] == 'Restricted' and @document['dct_provenance_s'] != 'Stanford' %>
58
-
59
- <ul class="list-group">
60
- <a href="<%= @document['solr_wms_url'] %>?request=GetCapabilities" data-no-turbolink class="list-group-item">
61
- <i class="fa fa-li fa-link"></i>WMS Link
62
- </a>
63
- <% if @document['layer_geom_type_s'] == 'Raster' %>
64
- <a href="<%= @document['solr_wcs_url'] %>?request=GetCapabilities" data-no-turbolink class="list-group-item">
65
- <i class="fa fa-li fa-link"></i>WCS Link
66
- </a>
67
- <% else %>
68
- <a href="<%= @document['solr_wfs_url'] %>?request=GetCapabilities" data-no-turbolink class="list-group-item">
69
- <i class="fa fa-li fa-link"></i>WFS Link
70
- </a>
71
- <% end %>
72
- </ul>
73
- <% end %>
74
- </div>
75
35
  </div>
76
36
  </div>
@@ -0,0 +1,38 @@
1
+ <% document ||= @document %>
2
+ <div class="geoblacklight-view-panel">
3
+
4
+ <dl class="dl-horizontal">
5
+ <% unless document['dc_creator_sm'].nil? %>
6
+ <dt>Author</dt>
7
+ <dd itemprop="author"><%= document['dc_creator_sm'].join(', ') %>&nbsp;</dd>
8
+ <% end %>
9
+ <% unless document['dc_publisher_s'].nil? %>
10
+ <dt>Publisher</dt>
11
+ <dd itemprop="publisher"><%= document['dc_publisher_s'] %>&nbsp;</dd>
12
+ <% end %>
13
+ <dt>Year</dt>
14
+ <dd itemprop="dateCreated"><%= document['solr_year_i'] %>&nbsp;</dd>
15
+ <dt>Abstract</dt>
16
+ <dd id="" itemprop="description"><%= abstract_truncator(document['dc_description_s']) %>&nbsp;</dd>
17
+ <% unless document['dct_isPartOf_sm'].nil? %>
18
+ <dt>Collection</dt>
19
+ <dd itemprop="isPartOf"><%= document['dct_isPartOf_sm'].sort.join(', ') %>&nbsp;</dd>
20
+ <% end %>
21
+ <% if document['dct_provenance_s'] == 'Stanford' and not document['dc_identifier_s'].nil? %>
22
+ <dt>Citation</dt>
23
+ <dd itemprop="url"><%= link_to document['dc_identifier_s'], document['dc_identifier_s'] %>&nbsp;</dd>
24
+ <% end %>
25
+ <% unless document['dct_spatial_sm'].nil? %>
26
+ <dt>Places</dt>
27
+ <dd itemprop="spatial"><%= document['dct_spatial_sm'].sort.join(', ') %>&nbsp;</dd>
28
+ <% end %>
29
+ <% unless document['dc_subject_sm'].nil? %>
30
+ <dt>Subjects</dt>
31
+ <dd itemprop="keywords"><%= document['dc_subject_sm'].sort.join(', ') %>&nbsp;</dd>
32
+ <% end %>
33
+ <% unless document['dct_temporal_sm'].nil? %>
34
+ <dt>Years</dt>
35
+ <dd itemprop="temporal"><%= document['dct_temporal_sm'].sort.join(', ') %>&nbsp;</dd>
36
+ <% end %>
37
+ </dl>
38
+ </div>
@@ -0,0 +1,3 @@
1
+ RailsConfig.setup do |config|
2
+ config.const_name = "Settings"
3
+ end
data/config/jetty.yml ADDED
@@ -0,0 +1,6 @@
1
+ default:
2
+ jetty_port: 8983
3
+ test:
4
+ jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
5
+ jetty_home: <%= ENV['TEST_JETTY_PATH'] || File.expand_path(File.join('..', 'jetty'), __FILE__) %>
6
+ startup_wait: 15
@@ -0,0 +1,5 @@
1
+ en:
2
+ geoblacklight:
3
+ download:
4
+ success: 'Your file %{title} is ready for download'
5
+ error: 'Sorry, the requested file could not be downloaded'
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['drh@stanford.edu', 'pjreed@stanford.edu']
11
11
  spec.summary = 'A discovery platform for geospatial holdings'
12
12
  spec.description = 'GeoBlacklight started at Stanford and its goal is to provide a world-class discovery platform for geospatial (GIS) holdings. It is an open collaborative project aiming to build off of the successes of the Blacklight Solr-powered discovery interface and the multi-institutional OpenGeoportal federated metadata sharing communities.'
13
- spec.homepage = 'http://github.com/sul-dlss/geoblacklight'
13
+ spec.homepage = 'http://github.com/geoblacklight/geoblacklight'
14
14
  spec.license = 'Apache 2.0'
15
15
 
16
16
  spec.files = `git ls-files -z`.split(%Q{\x0})
@@ -18,19 +18,19 @@ 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 'rails', '~> 4.0.0' # Rails 4.1.x has Spring on by default
22
- spec.add_dependency 'blacklight', '~> 5.4.0'
23
- spec.add_dependency 'bootstrap-sass', '~> 3.0'
21
+ spec.add_dependency 'blacklight', '~> 5.7.1'
24
22
  spec.add_dependency 'leaflet-rails', '~> 0.7.3'
25
23
  spec.add_dependency 'blacklight_range_limit', '~> 5.0.1'
26
24
  spec.add_dependency 'font-awesome-rails', '~> 4.1.0.0'
27
25
  spec.add_dependency 'httparty', '~> 0.13.1'
26
+ spec.add_dependency 'rails_config'
27
+ spec.add_dependency 'faraday'
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 1.5'
30
30
  spec.add_development_dependency 'rake', '~> 10.3.2'
31
31
  spec.add_development_dependency 'rspec-rails', '~> 3.0.1'
32
32
  spec.add_development_dependency 'jettywrapper', '~> 1.7.0'
33
- spec.add_development_dependency 'engine_cart', '~> 0.3.4'
33
+ spec.add_development_dependency 'engine_cart', '~> 0.4.0'
34
34
  spec.add_development_dependency 'capybara', '~> 2.3.0'
35
35
  spec.add_development_dependency 'poltergeist', '~> 1.5.0'
36
36
  end
@@ -17,9 +17,19 @@ module Geoblacklight
17
17
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
18
18
  end
19
19
 
20
+ def rails_config
21
+ copy_file 'settings.yml', 'config/settings.yml'
22
+ end
23
+
24
+ def include_geoblacklight_solrdocument
25
+ inject_into_file 'app/models/solr_document.rb', after: 'include Blacklight::Solr::Document' do
26
+ "\n include Geoblacklight::SolrDocument"
27
+ end
28
+ end
29
+
20
30
  def fixtures
21
- FileUtils.mkdir_p "spec/fixtures/geoblacklight_schema"
22
- copy_file "../../../../schema/examples/selected.json", "spec/fixtures/geoblacklight_schema/selected.json"
31
+ FileUtils.mkdir_p 'spec/fixtures/geoblacklight_schema'
32
+ system 'curl -L https://raw.githubusercontent.com/geoblacklight/geoblacklight-schema/master/examples/selected.json -o spec/fixtures/geoblacklight_schema/selected.json'
23
33
  end
24
34
 
25
35
  def add_unique_key
@@ -27,20 +37,40 @@ module Geoblacklight
27
37
  "\n self.unique_key = 'layer_slug_s'"
28
38
  end
29
39
  end
30
-
40
+
31
41
  def inject_routes
32
- # route 'devise_for :users'
33
- # route 'constraints(:id => /[0-9A-Za-z\-\.\:\_\/]+/) do
34
- # blacklight_for :catalog
35
- # resources :bookmarks
36
- # end'
37
- # route 'get \'/catalog/facet/:id\' => \'catalog#facet\''
38
- # route 'root :to => "catalog#index"'
39
42
  route 'post "wms/handle"'
40
- route 'post "download/kml"'
41
- route 'post "download/shapefile"'
42
- route 'get "download/file"'
43
- end
44
-
43
+ route 'resources :download, only: [:show, :file]'
44
+ route "get 'download/file/:id' => 'download#file', as: :download_file"
45
+ end
46
+
47
+ def create_downloads_directory
48
+ if !Dir.exists?('tmp/downloads')
49
+ Dir.mkdir('tmp/downloads')
50
+ end
51
+ end
52
+
53
+ # Necessary for bootstrap-sass 3.2
54
+ def inject_sprockets
55
+ blacklight_css = Dir["app/assets/stylesheets/blacklight.css.scss"].first
56
+ if blacklight_css
57
+ insert_into_file blacklight_css, before: "@import 'bootstrap';" do
58
+ "@import 'bootstrap-sprockets';\n"
59
+ end
60
+ else
61
+ say_status "warning", "Can not find blacklight.css.scss, did not insert our require", :red
62
+ end
63
+ end
64
+
65
+ def disable_turbolinks
66
+ gsub_file('app/assets/javascripts/application.js', /\/\/= require turbolinks/, '')
67
+ end
68
+
69
+ def bundle_install
70
+ Bundler.with_clean_env do
71
+ run "bundle install"
72
+ end
73
+ end
74
+
45
75
  end
46
76
  end
@@ -1,79 +1,3 @@
1
1
  /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require leaflet
13
- *= require font-awesome
14
- */
15
-
16
- .docView{
17
-
18
- }
19
-
20
- .text-span{
21
- width:100%;
22
- }
23
-
24
- .hide-overflow {
25
- white-space: nowrap;
26
- overflow: hidden;
27
- text-overflow: ellipsis;
28
- display:block
29
- }
30
-
31
- #map.mapview-map {
32
- height: 440px;
33
- cursor: crosshair;
34
- }
35
-
36
- #map.listview-map {
37
- height: 485px;
38
- }
39
-
40
- #table-container{
41
- overflow:scroll;
42
- max-height: 450px;
43
- }
44
-
45
- #control {
46
- text-align: center;
47
- background: #FFF;
48
- position: absolute;
49
- left: 24px;
50
- top: 120px;
51
- height: 200px;
52
- width: 28px;
53
- border: 1px solid #BBB;
54
- -webkit-border-radius: 3px;
55
- border-radius: 3px;
56
- z-index: 999;
57
- }
58
-
59
- #handle {
60
- background: #000;
61
- position: absolute;
62
- left: -1px;
63
- top: 20px;
64
- width: 28px;
65
- height: 10px;
66
- }
67
-
68
- #bottom {
69
- position: absolute;
70
- bottom:0px;
71
- left: 8px;
72
- text-align: center;
73
- }
74
-
75
- #handle:hover {
76
- cursor: pointer;
77
- background: #444;
78
- cursor: ns-resize;
79
- }
2
+ *= require geoblacklight/application
3
+ */
@@ -0,0 +1,9 @@
1
+ INSTITUTION: 'Stanford'
2
+ WMS_PARAMS:
3
+ :SERVICE: 'WMS'
4
+ :VERSION: '1.1.1'
5
+ :REQUEST: 'GetFeatureInfo'
6
+ :STYLES: ''
7
+ :SRS: 'EPSG:4326'
8
+ :EXCEPTIONS: 'application/json'
9
+ :INFO_FORMAT: 'text/html'
data/lib/geoblacklight.rb CHANGED
@@ -2,4 +2,17 @@ require "geoblacklight/engine"
2
2
 
3
3
  module Geoblacklight
4
4
  require 'geoblacklight/config'
5
+ require 'geoblacklight/controller_override'
6
+ require 'geoblacklight/view_helper_override'
7
+ require 'geoblacklight/solr_document'
8
+ require 'geoblacklight/wms_layer'
9
+ require 'geoblacklight/download'
10
+ require 'geoblacklight/download/shapefile_download'
11
+ require 'geoblacklight/download/kmz_download'
12
+ def self.inject!
13
+ CatalogController.send(:include, Geoblacklight::ControllerOverride)
14
+ CatalogController.send(:include, Geoblacklight::ViewHelperOverride)
15
+ SearchHistoryController.send(:helper, Geoblacklight::ViewHelperOverride) unless
16
+ SearchHistoryController.helpers.is_a?(Geoblacklight::ViewHelperOverride)
17
+ end
5
18
  end
@@ -0,0 +1,18 @@
1
+ module Geoblacklight
2
+ module ControllerOverride
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[:q] ||= "*"
11
+ solr_params[:q] += " solr_bbox:\"IsWithin(#{req_params[:bbox]})\"^10"
12
+ solr_params[:fq] ||= []
13
+ solr_params[:fq] << "solr_bbox:\"Intersects(#{req_params[:bbox]})\""
14
+ end
15
+ solr_params
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ class Download
2
+ def initialize(document, options = {})
3
+ @document = document
4
+ @options = options
5
+ end
6
+
7
+ def downloadable?
8
+ @document.downloadable?
9
+ end
10
+
11
+ def file_name
12
+ "#{@document[:layer_slug_s]}-#{@options[:type]}.#{@options[:extension]}"
13
+ end
14
+
15
+ def file_path
16
+ "#{Rails.root}/tmp/downloads/#{file_name}"
17
+ end
18
+
19
+ def download_exists?
20
+ File.file?(file_path)
21
+ end
22
+
23
+ def get
24
+ if download_exists?
25
+ file_name
26
+ else
27
+ create_download_file
28
+ end
29
+ end
30
+
31
+ def create_download_file
32
+ download = initiate_download
33
+ File.open("#{file_path}.tmp", 'wb') do |file|
34
+ if download.headers['content-type'] == @options[:content_type]
35
+ file.write download.body
36
+ else
37
+ fail 'Wrong type of download'
38
+ end
39
+ end
40
+ File.rename("#{file_path}.tmp", file_path)
41
+ file_name
42
+ rescue
43
+ File.delete("#{file_path}.tmp")
44
+ nil
45
+ end
46
+
47
+ def initiate_download
48
+ conn = Faraday.new(url: @document[@options[:service_type]])
49
+ conn.get do |request|
50
+ request.params = @options[:request_params]
51
+ request.options = {
52
+ timeout: 10,
53
+ open_timeout: 10
54
+ }
55
+ end
56
+ rescue Faraday::Error::ConnectionFailed => error
57
+ puts error
58
+ nil
59
+ rescue Faraday::Error::TimeoutError => error
60
+ puts error
61
+ nil
62
+ end
63
+ end