geoblacklight_sidecar_images 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +4 -4
  3. data/.travis.yml +4 -4
  4. data/Gemfile +2 -2
  5. data/README.md +8 -7
  6. data/Rakefile +0 -3
  7. data/app/assets/stylesheets/geoblacklight_sidecar_images/_gblsci.scss +13 -0
  8. data/app/assets/stylesheets/geoblacklight_sidecar_images/application.scss +10 -0
  9. data/app/assets/stylesheets/geoblacklight_sidecar_images/modules/_results.scss +10 -0
  10. data/app/jobs/geoblacklight_sidecar_images/store_image_job.rb +18 -0
  11. data/app/models/{geoblacklight_sidecar_images/application_record.rb → application_record.rb} +0 -0
  12. data/{lib/generators/geoblacklight_sidecar_images/templates → app}/models/concerns/wms_rewrite_concern.rb +0 -0
  13. data/{lib/generators/geoblacklight_sidecar_images/templates → app}/models/sidecar_image_state_machine.rb +1 -1
  14. data/{lib/generators/geoblacklight_sidecar_images/templates → app}/models/sidecar_image_transition.rb +0 -0
  15. data/{lib/generators/geoblacklight_sidecar_images/templates → app}/models/solr_document_sidecar.rb +3 -3
  16. data/app/services/geoblacklight_sidecar_images/image_service.rb +226 -0
  17. data/app/services/geoblacklight_sidecar_images/image_service/dynamic_map_layer.rb +15 -0
  18. data/app/services/geoblacklight_sidecar_images/image_service/iiif.rb +17 -0
  19. data/app/services/geoblacklight_sidecar_images/image_service/image_map_layer.rb +17 -0
  20. data/app/services/geoblacklight_sidecar_images/image_service/tiled_map_layer.rb +15 -0
  21. data/app/services/geoblacklight_sidecar_images/image_service/wms.rb +28 -0
  22. data/geoblacklight_sidecar_images.gemspec +5 -5
  23. data/lib/generators/geoblacklight_sidecar_images/install_generator.rb +9 -9
  24. data/lib/generators/geoblacklight_sidecar_images/jobs_generator.rb +1 -6
  25. data/lib/generators/geoblacklight_sidecar_images/models_generator.rb +0 -28
  26. data/lib/generators/geoblacklight_sidecar_images/templates/gblsci.scss +3 -0
  27. data/lib/generators/geoblacklight_sidecar_images/templates/views/catalog/_index_split_default.html.erb +28 -28
  28. data/lib/geoblacklight_sidecar_images/version.rb +1 -1
  29. data/lib/tasks/geoblacklight_sidecar_images_tasks.rake +10 -13
  30. data/solr/conf/schema.xml +11 -3
  31. data/solr/conf/solrconfig.xml +4 -4
  32. data/spec/fixtures/files/README.md +40 -0
  33. data/spec/fixtures/files/actual-papermap1.json +1 -1
  34. data/spec/fixtures/files/actual-point1.json +26 -13
  35. data/spec/fixtures/files/actual-polygon1.json +1 -1
  36. data/spec/fixtures/files/actual-raster1.json +6 -5
  37. data/spec/fixtures/files/bbox-spans-180.json +20 -0
  38. data/spec/fixtures/files/cornell_html_metadata.json +42 -0
  39. data/spec/fixtures/files/esri-dynamic-layer-all-layers.json +36 -34
  40. data/spec/fixtures/files/esri-dynamic-layer-single-layer.json +30 -27
  41. data/spec/fixtures/files/esri-feature-layer.json +37 -24
  42. data/spec/fixtures/files/esri-image-map-layer.json +39 -18
  43. data/spec/fixtures/files/iiif-eastern-hemisphere.json +30 -0
  44. data/spec/fixtures/files/index-map-polygon-no-downloadurl.json +37 -0
  45. data/spec/fixtures/files/index-map-polygon.json +37 -0
  46. data/spec/fixtures/files/index-map-stanford.json +37 -0
  47. data/spec/fixtures/files/index_map_point.json +27 -0
  48. data/spec/fixtures/files/princeton-child1.json +30 -0
  49. data/spec/fixtures/files/princeton-child2.json +30 -0
  50. data/spec/fixtures/files/princeton-child3.json +30 -0
  51. data/spec/fixtures/files/princeton-child4.json +30 -0
  52. data/spec/fixtures/files/princeton-parent.json +25 -0
  53. data/spec/fixtures/files/public_direct_download.json +13 -7
  54. data/spec/fixtures/files/public_polygon_mit.json +15 -27
  55. data/spec/fixtures/files/restricted-line.json +7 -6
  56. data/spec/fixtures/files/umn_iiif_jpg.json +1 -2
  57. data/spec/fixtures/files/umn_metro_result1.json +30 -26
  58. data/spec/fixtures/files/umn_state_result1.json +25 -18
  59. data/spec/fixtures/files/umn_state_result2.json +27 -25
  60. data/spec/fixtures/files/uva_slug_colon.json +25 -0
  61. data/spec/jobs/store_image_job_spec.rb +2 -2
  62. data/spec/models/solr_document_sidecar_spec.rb +1 -1
  63. data/spec/services/image_service_spec.rb +1 -1
  64. data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -2
  65. data/template.rb +3 -3
  66. metadata +55 -30
  67. data/app/assets/config/geoblacklight_sidecar_images_manifest.js +0 -2
  68. data/app/assets/images/geoblacklight_sidecar_images/.keep +0 -0
  69. data/app/assets/javascripts/geoblacklight_sidecar_images/application.js +0 -13
  70. data/app/assets/stylesheets/geoblacklight_sidecar_images/application.css +0 -15
  71. data/lib/generators/geoblacklight_sidecar_images/services_generator.rb +0 -19
  72. data/lib/generators/geoblacklight_sidecar_images/templates/assets/javascripts/geoblacklight.js +0 -9
  73. data/lib/generators/geoblacklight_sidecar_images/templates/assets/stylesheets/geoblacklight.scss +0 -3
  74. data/lib/generators/geoblacklight_sidecar_images/templates/jobs/store_image_job.rb +0 -17
  75. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb +0 -224
  76. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/dynamic_map_layer.rb +0 -13
  77. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/iiif.rb +0 -15
  78. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/image_map_layer.rb +0 -15
  79. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/tiled_map_layer.rb +0 -13
  80. data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/wms.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a8eb8793e9bc01499aa73ada433ccd2b545c4381
4
- data.tar.gz: b62ea3956e24e52f58fc82d5ae0bc6122ec1fd63
2
+ SHA256:
3
+ metadata.gz: c72cc3fac516c465122adca9f440104db7d2012588d4562de7c467134208d758
4
+ data.tar.gz: 3c6ab484395eb53f804d1c6f916de049be21d3d18f09c9201055a87dcc226009
5
5
  SHA512:
6
- metadata.gz: e7e1f1a1084046921f213aac5c1a9ae73cb2e3ef5112455a33bf36dd5f66871a06f456d3fabb0c19e967676e2bfd155fb11832cfcc3e446355487d437fc34301
7
- data.tar.gz: 1cb4ced8521c6e4778379d784901196a832b2c5989f0523c2ca092f8d22c495f0a7c66e20ec5e97f2d0f40d75addcd2ca27713567ee12b65d50e3674e5805a4c
6
+ metadata.gz: 3ce1fe5b78fa81dac0c70f09e73d7cdcdddb06136ccff8c4b75ab80a42dabc205800ddd59ce320f2ac62d8c7916be0b6713f46199d4a8a9f1ca2dba973896dc3
7
+ data.tar.gz: cd1e00e5b1781c95a409cbdfd8c73ef62c48c3ada88eda5a640c4cac4e0209627f40aee71a5d178ac9a4e0796f902af10dacf7f44212c9c860c7fa630a5c1d32
data/.rubocop.yml CHANGED
@@ -18,7 +18,7 @@ AllCops:
18
18
 
19
19
  Lint/RescueException:
20
20
  Exclude:
21
- - 'lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb'
21
+ - 'app/services/geoblacklight_sidecar_images/image_service.rb'
22
22
 
23
23
  Metrics/BlockLength:
24
24
  Exclude:
@@ -29,12 +29,12 @@ Metrics/LineLength:
29
29
  Exclude:
30
30
  - 'spec/**/*'
31
31
  - 'Rakefile'
32
- - 'lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb'
32
+ - 'app/services/geoblacklight_sidecar_images/image_service.rb'
33
33
 
34
34
  # TODO: Refactor large methods.
35
35
  Metrics/ClassLength:
36
36
  Exclude:
37
- - 'lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb'
37
+ - 'app/services/geoblacklight_sidecar_images/image_service.rb'
38
38
 
39
39
  Metrics/AbcSize:
40
40
  Max: 28
@@ -44,7 +44,7 @@ Metrics/MethodLength:
44
44
  Exclude:
45
45
  - 'spec/**/*'
46
46
  - 'Rakefile'
47
- - 'lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb'
47
+ - 'app/services/geoblacklight_sidecar_images/image_service.rb'
48
48
 
49
49
  # TODO: Add top-level class and module documentation.
50
50
  Style/Documentation:
data/.travis.yml CHANGED
@@ -8,12 +8,12 @@ notifications:
8
8
  email: false
9
9
 
10
10
  rvm:
11
- - 2.4.5
11
+ - 2.5.3
12
12
 
13
13
  matrix:
14
14
  include:
15
- - rvm: 2.4.5
16
- env: "RAILS_VERSION=5.2.1"
15
+ - rvm: 2.5.3
16
+ env: "RAILS_VERSION=5.2.2"
17
17
 
18
18
  before_install:
19
19
  - gem update --system
@@ -21,7 +21,7 @@ before_install:
21
21
  - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
22
22
 
23
23
  env:
24
- - "RAILS_VERSION=5.2.1 "
24
+ - "RAILS_VERSION=5.2.2"
25
25
 
26
26
  global_env:
27
27
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/Gemfile CHANGED
@@ -37,8 +37,8 @@ if File.exist?(file)
37
37
  end
38
38
  else
39
39
  Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
40
- gem 'geoblacklight', '~> 1.9'
41
- gem 'mini_magick'
40
+ gem 'geoblacklight', '~> 2.0'
41
+ gem 'mini_magick', '~> 4.9.4'
42
42
  gem 'image_processing', '~> 1.6'
43
43
  gem 'mimemagic', '~> 0.3'
44
44
  gem 'statesman', '~> 3.4'
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # GeoBlacklight Sidecar Images
2
2
 
3
- [![Build Status](https://travis-ci.org/ewlarson/geoblacklight_sidecar_images.svg?branch=master)](https://travis-ci.org/ewlarson/geoblacklight_sidecar_images)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/88c14165af5459963011/maintainability)](https://codeclimate.com/github/ewlarson/geoblacklight_sidecar_images/maintainability)
5
- [![Coverage Status](https://coveralls.io/repos/github/ewlarson/geoblacklight_sidecar_images/badge.svg?branch=master)](https://coveralls.io/github/ewlarson/geoblacklight_sidecar_images?branch=master)
3
+ [![Build Status](https://travis-ci.org/geoblacklight/geoblacklight_sidecar_images.svg?branch=master)](https://travis-ci.org/geoblacklight/geoblacklight_sidecar_images)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/88c14165af5459963011/maintainability)](https://codeclimate.com/github/geoblacklight/geoblacklight_sidecar_images/maintainability)
5
+ [![Coverage Status](https://coveralls.io/repos/github/geoblacklight/geoblacklight_sidecar_images/badge.svg?branch=master)](https://coveralls.io/github/geoblacklight/geoblacklight_sidecar_images?branch=master)
6
6
  [![Gem Version](https://badge.fury.io/rb/geoblacklight_sidecar_images.svg)](https://badge.fury.io/rb/geoblacklight_sidecar_images)
7
7
 
8
8
  Store local copies of remote imagery in GeoBlacklight.
@@ -52,7 +52,7 @@ $ bin/rails db:migrate
52
52
  Create a new GeoBlacklight instance with the GBLSI code
53
53
 
54
54
  ```bash
55
- $ rails new app-name -m https://raw.githubusercontent.com/ewlarson/geoblacklight_sidecar_images/master/template.rb
55
+ $ rails new app-name -m https://raw.githubusercontent.com/geoblacklight/geoblacklight_sidecar_images/master/template.rb
56
56
 
57
57
  ```
58
58
 
@@ -64,7 +64,8 @@ $ rails new app-name -m https://raw.githubusercontent.com/ewlarson/geoblacklight
64
64
  ```
65
65
 
66
66
  ```bash
67
- bundle exec rake gblsci:sample_data:ingest['<FULL_LOCAL_PATH_TO>/geoblacklight_sidecar_images/spec/fixtures/files']
67
+ # Index the GBL test fixtures
68
+ bundle exec rake gblsci:sample_data:seed
68
69
  ```
69
70
 
70
71
  ## Rake tasks
@@ -206,10 +207,10 @@ bundle exec rake ci
206
207
 
207
208
  # Launch test app server
208
209
  cd .internal_test_app/
209
- rake geoblacklight:server
210
+ bundle exec rake geoblacklight:server
210
211
 
211
212
  # Load test fixtures
212
- bundle exec rake gblsci:sample_data:ingest['<FULL_LOCAL_PATH_TO>/geoblacklight_sidecar_images/spec/fixtures/files']
213
+ bundle exec rake gblsci:sample_data:seed
213
214
 
214
215
  # Run harvest
215
216
  bundle exec rake gblsci:images:harvest_all
data/Rakefile CHANGED
@@ -17,11 +17,8 @@ require 'rubocop/rake_task'
17
17
  RuboCop::RakeTask.new(:rubocop)
18
18
 
19
19
  require 'engine_cart/rake_task'
20
- EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
21
20
  require 'geoblacklight_sidecar_images/version'
22
21
 
23
- EngineCart.fingerprint_proc = EngineCart.rails_fingerprint_proc
24
-
25
22
  task ci: ['engine_cart:generate'] do
26
23
  ENV['environment'] = 'test'
27
24
 
@@ -0,0 +1,13 @@
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
+ */
12
+
13
+ @import 'modules/results';
@@ -0,0 +1,10 @@
1
+ // GBLSCI results
2
+ .media {
3
+ img,span {
4
+ min-width: 100px;
5
+ text-align: center;
6
+ }
7
+ span.icon.square {
8
+ font-size:3rem;
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ // GBLSCI results
2
+ .media {
3
+ img,span {
4
+ min-width: 100px;
5
+ text-align: center;
6
+ }
7
+ span.icon.square {
8
+ font-size:3rem;
9
+ }
10
+ }
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GeoblacklightSidecarImages
4
+ class StoreImageJob < ApplicationJob
5
+ queue_as :default
6
+
7
+ def perform(solr_document_id)
8
+ document = Geoblacklight::SolrDocument.find(solr_document_id)
9
+
10
+ metadata = {}
11
+ metadata['solr_doc_id'] = document.id
12
+ metadata['solr_version'] = document.sidecar.version
13
+
14
+ document.sidecar.image_state.transition_to!(:queued, metadata)
15
+ GeoblacklightSidecarImages::ImageService.new(document).store
16
+ end
17
+ end
18
+ end
@@ -15,7 +15,7 @@ class SidecarImageStateMachine
15
15
  transition from: :initialized, to: %i[queued processing]
16
16
  transition from: :queued, to: %i[queued processing]
17
17
  transition from: :processing, to: %i[queued processing placeheld succeeded failed]
18
- transition from: :placeheld, to: %i[queued processing]
18
+ transition from: :placeheld, to: %i[queued processing failed]
19
19
  transition from: :failed, to: %i[queued processing]
20
20
  transition from: :succeeded, to: %i[queued processing]
21
21
  end
@@ -5,8 +5,8 @@
5
5
  class SolrDocumentSidecar < ApplicationRecord
6
6
  include Statesman::Adapters::ActiveRecordQueries
7
7
 
8
- belongs_to :document, required: true, polymorphic: true
9
- has_many :sidecar_image_transitions, autosave: false
8
+ belongs_to :document, optional: false, polymorphic: true
9
+ has_many :sidecar_image_transitions, autosave: false, dependent: :destroy
10
10
  has_one_attached :image
11
11
 
12
12
  # If the sidecar solr document is updated, re-fetch thumbnail image
@@ -45,6 +45,6 @@ class SolrDocumentSidecar < ApplicationRecord
45
45
 
46
46
  def reimage
47
47
  image.purge if image.attached?
48
- StoreImageJob.perform_later(document.id)
48
+ GeoblacklightSidecarImages::StoreImageJob.perform_later(document.id)
49
49
  end
50
50
  end
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable/uri'
4
+ require 'mimemagic'
5
+
6
+ module GeoblacklightSidecarImages
7
+ class ImageService
8
+ attr_reader :document
9
+ attr_writer :metadata, :logger
10
+
11
+ def initialize(document)
12
+ @document = document
13
+
14
+ @metadata = {}
15
+ @metadata['solr_doc_id'] = document.id
16
+ @metadata['solr_version'] = @document.sidecar.version
17
+ @metadata['placeheld'] = false
18
+
19
+ @document.sidecar.image_state.transition_to!(:processing, @metadata)
20
+
21
+ @logger ||= ActiveSupport::TaggedLogging.new(
22
+ Logger.new(
23
+ Rails.root.join('log', "image_service_#{Rails.env}.log")
24
+ )
25
+ )
26
+ end
27
+
28
+ # Stores the document's image in ActiveStorage
29
+ # @return [Boolean]
30
+ #
31
+ def store
32
+ # Gentle hands
33
+ sleep(1)
34
+
35
+ io_file = image_tempfile(@document.id)
36
+
37
+ if io_file.nil? || @metadata['placeheld'] == true
38
+ @document.sidecar.image_state.transition_to!(:placeheld, @metadata)
39
+ else
40
+ attach_io(io_file)
41
+ end
42
+
43
+ log_output
44
+ rescue Exception => invalid
45
+ @metadata['exception'] = invalid.inspect
46
+ @document.sidecar.image_state.transition_to!(:failed, @metadata)
47
+
48
+ log_output
49
+ end
50
+
51
+ private
52
+
53
+ def image_tempfile(document_id)
54
+ @metadata['viewer_protocol'] = @document.viewer_protocol
55
+ @metadata['image_url'] = image_url
56
+ @metadata['service_url'] = service_url
57
+ @metadata['gblsi_thumbnail_uri'] = gblsi_thumbnail_uri
58
+
59
+ return nil unless image_data && @metadata['placeheld'] == false
60
+
61
+ temp_file = Tempfile.new([document_id, '.tmp'])
62
+ temp_file.binmode
63
+ temp_file.write(image_data)
64
+ temp_file.rewind
65
+
66
+ @metadata['image_tempfile'] = temp_file.inspect
67
+ temp_file
68
+ end
69
+
70
+ def attach_io(io)
71
+ # Remote content-type headers are untrustworthy
72
+ # Pull the mimetype and file extension via MimeMagic
73
+ mm = MimeMagic.by_magic(File.open(io))
74
+
75
+ @metadata['MimeMagic_type'] = mm.type
76
+ @metadata['MimeMagic_mediatype'] = mm.mediatype
77
+ @metadata['MimeMagic_subtype'] = mm.subtype
78
+
79
+ if mm.mediatype == 'image'
80
+ @document.sidecar.image.attach(
81
+ io: io,
82
+ filename: "#{@document.id}.#{mm.subtype}",
83
+ content_type: mm.type
84
+ )
85
+ @document.sidecar.image_state.transition_to!(:succeeded, @metadata)
86
+ else
87
+ @document.sidecar.image_state.transition_to!(:placeheld, @metadata)
88
+ end
89
+ end
90
+
91
+ # Returns geoserver auth credentials if the document is a restriced Local WMS layer.
92
+ def geoserver_credentials
93
+ return unless restricted_wms_layer?
94
+
95
+ Settings.PROXY_GEOSERVER_AUTH.gsub('Basic ', '')
96
+ end
97
+
98
+ # Tests if geoserver credentials are set beyond the default.
99
+ def geoserver_credentials_valid?
100
+ Settings.PROXY_GEOSERVER_AUTH != 'Basic base64encodedusername:password'
101
+ end
102
+
103
+ # Tests if local thumbnail method is configured
104
+ def gblsi_thumbnail_field?
105
+ Settings.GBLSI_THUMBNAIL_FIELD
106
+ end
107
+
108
+ def gblsi_thumbnail_uri
109
+ if gblsi_thumbnail_field? && @document[Settings.GBLSI_THUMBNAIL_FIELD]
110
+ @document[Settings.GBLSI_THUMBNAIL_FIELD]
111
+ else
112
+ false
113
+ end
114
+ end
115
+
116
+ # Generates hash containing thumbnail mime_type and image.
117
+ def image_data
118
+ return nil unless image_url
119
+
120
+ remote_image
121
+ end
122
+
123
+ # Gets thumbnail image from URL. On error, placehold image.
124
+ def remote_image
125
+ auth = geoserver_credentials
126
+
127
+ uri = Addressable::URI.parse(image_url)
128
+
129
+ return nil unless uri.scheme.include?('http')
130
+
131
+ conn = Faraday.new(url: uri.normalize.to_s) do |b|
132
+ b.use FaradayMiddleware::FollowRedirects
133
+ b.adapter :net_http
134
+ end
135
+
136
+ conn.options.timeout = timeout
137
+ conn.authorization :Basic, auth if auth
138
+ conn.get.body
139
+ rescue Faraday::Error::ConnectionFailed
140
+ @metadata['error'] = 'Faraday::Error::ConnectionFailed'
141
+ @metadata['placeheld'] = true
142
+ nil
143
+ rescue Faraday::Error::TimeoutError
144
+ @metadata['error'] = 'Faraday::Error::TimeoutError'
145
+ @metadata['placeheld'] = true
146
+ nil
147
+ end
148
+
149
+ # Returns the thumbnail url.
150
+ # If the layer is restriced Local WMS, and the geoserver credentials
151
+ # have not been set beyond the default, then a thumbnail url from
152
+ # dct references is used instead.
153
+ def image_url
154
+ @image_url ||= begin
155
+ if gblsi_thumbnail_uri
156
+ gblsi_thumbnail_uri
157
+ elsif restricted_scanned_map?
158
+ image_reference
159
+ elsif restricted_wms_layer? && !geoserver_credentials_valid?
160
+ image_reference
161
+ else
162
+ service_url || image_reference
163
+ end
164
+ end
165
+ end
166
+
167
+ # Checks if the document is Local restriced access and is a scanned map.
168
+ def restricted_scanned_map?
169
+ @document.local_restricted? && @document['layer_geom_type_s'] == 'Image'
170
+ end
171
+
172
+ # Checks if the document is Local restriced access and is a wms layer.
173
+ def restricted_wms_layer?
174
+ @document.local_restricted? && @document.viewer_protocol == 'wms'
175
+ end
176
+
177
+ # Gets the url for a specific service endpoint if the item is
178
+ # public, has the same institution as the GBL instance, and the viewer
179
+ # protocol is not 'map' or nil. A module name is then dynamically generated
180
+ # from the viewer protocol, and if it's loaded, the image_url
181
+ # method is called.
182
+ def service_url
183
+ @service_url ||=
184
+ begin
185
+ return unless @document.available?
186
+
187
+ protocol = @document.viewer_protocol
188
+ if protocol == 'map' || protocol.nil?
189
+ @metadata['error'] = 'Unsupported viewer protocol'
190
+ @metadata['placeheld'] = true
191
+ return nil
192
+ end
193
+ "GeoblacklightSidecarImages::ImageService::#{protocol.camelcase}".constantize.image_url(@document, image_size)
194
+ rescue NameError
195
+ @metadata['error'] = 'service_url NameError'
196
+ @metadata['placeheld'] = true
197
+ return nil
198
+ end
199
+ end
200
+
201
+ # Retreives a url to a static thumbnail from the document's dct_references field, if it exists.
202
+ def image_reference
203
+ return nil if @document[@document.references.reference_field].nil?
204
+
205
+ JSON.parse(@document[@document.references.reference_field])['http://schema.org/thumbnailUrl']
206
+ end
207
+
208
+ # Default image size.
209
+ def image_size
210
+ 1500
211
+ end
212
+
213
+ # Faraday timeout value.
214
+ def timeout
215
+ 30
216
+ end
217
+
218
+ # Capture metadata within image harvest log
219
+ def log_output
220
+ @metadata['state'] = @document.sidecar.image_state.current_state
221
+ @metadata.each do |key, value|
222
+ @logger.tagged(@document.id, key.to_s) { @logger.info value }
223
+ end
224
+ end
225
+ end
226
+ end