geoblacklight_sidecar_images 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +69 -0
  3. data/.gitignore +1 -0
  4. data/.solr_wrapper.yml +2 -0
  5. data/.standard.yml +1 -0
  6. data/Gemfile +22 -13
  7. data/README.md +6 -7
  8. data/Rakefile +52 -16
  9. data/app/jobs/geoblacklight_sidecar_images/store_image_job.rb +2 -2
  10. data/app/mailers/geoblacklight_sidecar_images/application_mailer.rb +2 -2
  11. data/app/models/concerns/wms_rewrite_concern.rb +1 -1
  12. data/app/models/sidecar_image_state_machine.rb +6 -6
  13. data/app/models/sidecar_image_transition.rb +1 -1
  14. data/app/services/geoblacklight_sidecar_images/image_service/iiif.rb +1 -1
  15. data/app/services/geoblacklight_sidecar_images/image_service/wms.rb +4 -4
  16. data/app/services/geoblacklight_sidecar_images/image_service.rb +46 -46
  17. data/db/migrate/20180118203155_create_solr_document_sidecars.rb +1 -1
  18. data/db/migrate/20180118203519_create_sidecar_image_transitions.rb +6 -6
  19. data/geoblacklight_sidecar_images.gemspec +30 -31
  20. data/lib/generators/geoblacklight_sidecar_images/config_generator.rb +13 -4
  21. data/lib/generators/geoblacklight_sidecar_images/example_docs_generator.rb +3 -3
  22. data/lib/generators/geoblacklight_sidecar_images/install_generator.rb +14 -14
  23. data/lib/generators/geoblacklight_sidecar_images/jobs_generator.rb +3 -3
  24. data/lib/generators/geoblacklight_sidecar_images/models_generator.rb +7 -7
  25. data/lib/generators/geoblacklight_sidecar_images/templates/config/initializers/statesman.rb +1 -1
  26. data/lib/generators/geoblacklight_sidecar_images/views_generator.rb +4 -4
  27. data/lib/geoblacklight_sidecar_images/version.rb +1 -1
  28. data/lib/geoblacklight_sidecar_images.rb +1 -1
  29. data/lib/tasks/geoblacklight_sidecar_images_tasks.rake +61 -68
  30. data/solr/conf/schema.xml +4 -6
  31. data/spec/fixtures/files/umn_solr_thumb.json +1 -1
  32. data/spec/jobs/store_image_job_spec.rb +4 -4
  33. data/spec/lib/tasks/geoblacklight_sidecar_images_spec.rb +33 -0
  34. data/spec/models/solr_document_sidecar_spec.rb +4 -4
  35. data/spec/models/solr_document_spec.rb +5 -5
  36. data/spec/rails_helper.rb +10 -12
  37. data/spec/services/image_service_spec.rb +24 -18
  38. data/spec/spec_helper.rb +32 -0
  39. data/spec/test_app_templates/Gemfile.extra +1 -0
  40. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -12
  41. data/template.rb +9 -9
  42. metadata +59 -106
  43. data/.coveralls.yml +0 -1
  44. data/.rubocop.yml +0 -81
  45. data/.travis.yml +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65f48652a713c5542469d6de4abe02385e821303f0393feaa15b3198c041a8bc
4
- data.tar.gz: ebc3d1bf2b4b7aa8feb6e2ceb9932ef4330ee14c09ab54c57d904a405b02e36b
3
+ metadata.gz: b80ac6e8ded571d024d3b299500c905b4f357309e16158aaaeac49ae8301b38b
4
+ data.tar.gz: '09fff8a81169c51b7d2af25b935da6d6f5f2db58636b75cdce7d3d386e41eff2'
5
5
  SHA512:
6
- metadata.gz: 0b82873f4f53d32f225b6f1dd51e7c0f48616ede7f9023db89918414bcc14994e8b25314f13eef5c5da66d768a2f4ec1fce10e359d3e5d5ae7ce69cba4603310
7
- data.tar.gz: 715b8fc09e049231f4606f246aa22ae299e79b478a37185b56038264d58081f42b1c3d4ebe130a0627ed41cc77bc91cd8b646f1565ca55991e2035906c4a9e74
6
+ metadata.gz: 52cb834ba4bddb62e298239b218afb71e931d90989c26af79e41388e6989f9d2c02e080b1ca9cfa5f8d6aa21fd5e8a13c5b2b1359560bf2eeae61f7e073ddc5a
7
+ data.tar.gz: '0043110884ccd6e21f6f3cdcaf72977db1a7013967be8b433153bc0bce27bdf6e21d480cc42d38f41ff35c2e38c5438363146f6090c8af268bdad2b6bddca9a8'
@@ -0,0 +1,69 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - feature/github-actions
8
+ pull_request:
9
+
10
+ jobs:
11
+ linter:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.7
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run linter
22
+ run: bundle exec standardrb
23
+
24
+ test:
25
+ runs-on: ubuntu-latest
26
+ strategy:
27
+ matrix:
28
+ ruby_version: ["3.0","2.7"]
29
+ rails_version: [7.0.4.2, 6.1.7.2]
30
+ bundler_version: [2.1.1]
31
+ faraday_version: ['>= 2', '~> 1.0']
32
+
33
+ name: test ruby ${{ matrix.ruby_version }} / rails ${{ matrix.rails_version }} / faraday ${{ matrix.faraday_version }}
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby_version }}
40
+ - name: Create Solr container
41
+ run: docker run -d -p 8983:8983 geoblacklight/solr:8.9-v1.0.0 server/scripts/ci-start.sh
42
+ - name: Install bundler
43
+ run: gem install bundler -v ${{ matrix.bundler_version }}
44
+ - name: Install dependencies
45
+ run: bundle _${{ matrix.bundler_version }}_ install
46
+ env:
47
+ RAILS_VERSION: ${{ matrix.rails_version }}
48
+ FARADAY_VERSION: ${{ matrix.faraday_version }}
49
+ - name: Setup Yarn
50
+ run: exec "yarnpkg"
51
+ - name: Load config into solr
52
+ run: |
53
+ cd solr/conf
54
+ zip -1 -r solr_config.zip ./*
55
+ curl -H "Content-type:application/octet-stream" --data-binary @solr_config.zip "http://solr:SolrRocks@127.0.0.1:8983/solr/admin/configs?action=UPLOAD&name=blacklight"
56
+ curl -H 'Content-type: application/json' http://solr:SolrRocks@127.0.0.1:8983/api/collections/ -d '{create: {name: blacklight-core, config: blacklight, numShards: 1}}'
57
+ - name: Run tests
58
+ run: bundle exec rake ci
59
+ env:
60
+ RAILS_VERSION: ${{ matrix.rails_version }}
61
+ FARADAY_VERSION: ${{ matrix.faraday_version }}
62
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
63
+ SOLR_URL: http://solr:SolrRocks@localhost:8983/solr/blacklight-core
64
+ - name: Upload coverage artifacts
65
+ uses: actions/upload-artifact@v2
66
+ if: always()
67
+ with:
68
+ name: coverage
69
+ path: coverage/
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ spec/test_app/storage/
17
17
  spec/test_app/tmp/
18
18
  .internal_test_app
19
19
  .ruby-version
20
+ .byebug_history
data/.solr_wrapper.yml CHANGED
@@ -1,4 +1,6 @@
1
+ url: https://archive.apache.org/dist/lucene/solr/8.11.1/solr-8.11.1.tgz
1
2
  validate: false
3
+ instance_dir: tmp/solr
2
4
  download_dir: tmp/solr
3
5
  collection:
4
6
  dir: solr/conf/
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ format: progress
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Declare your gem's dependencies in geoblacklight_sidecar_images.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -13,10 +13,6 @@ gemspec
13
13
  # your gem to rubygems.org.
14
14
 
15
15
  group :development, :test do
16
- # Peg simplecov to < 0.8 until this is resolved:
17
- # https://github.com/colszowka/simplecov/issues/281
18
- gem 'coveralls', require: false
19
- gem 'rubocop', '~> 1.9', require: false
20
16
  end
21
17
 
22
18
  # To use a debugger
@@ -26,22 +22,35 @@ end
26
22
  # engine_cart: 1.2.0
27
23
  # engine_cart stanza: 0.10.0
28
24
  # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
29
- file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
25
+ file = File.expand_path("Gemfile", ENV["ENGINE_CART_DESTINATION"] || ENV["RAILS_ROOT"] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
30
26
 
31
27
  if File.exist?(file)
32
28
  begin
33
29
  eval_gemfile file
34
30
  rescue Bundler::GemfileError => e
35
- Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
31
+ Bundler.ui.warn "[EngineCart] Skipping Rails application dependencies:"
36
32
  Bundler.ui.warn e.message
37
33
  end
38
34
  else
39
35
  Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
40
- gem 'geoblacklight', '>= 2.0'
41
- gem 'mini_magick', '~> 4.9.4'
42
- gem 'image_processing', '~> 1.6'
43
- gem 'statesman', '>= 3.4'
44
- gem 'marcel', '>= 1.0'
45
- gem 'rails', '>= 5.2.5', '< 6.2'
36
+ gem "geoblacklight", ">= 2.0"
37
+ gem "mini_magick", "~> 4.9.4"
38
+ gem "image_processing", "~> 1.6"
39
+ gem "statesman", ">= 3.4"
40
+ gem "marcel", ">= 1.0"
41
+ if ENV["RAILS_VERSION"]
42
+ if ENV["RAILS_VERSION"] == "edge"
43
+ gem "rails", github: "rails/rails"
44
+ ENV["ENGINE_CART_RAILS_OPTIONS"] = "--edge --skip-turbolinks"
45
+ else
46
+ gem "rails", ENV["RAILS_VERSION"]
47
+ end
48
+ end
49
+ end
50
+
51
+ if File.exist?("spec/test_app_templates/Gemfile.extra")
52
+ # rubocop:disable Security/Eval
53
+ eval File.read("spec/test_app_templates/Gemfile.extra"), nil, "spec/test_app_templates/Gemfile.extra"
54
+ # rubocop:enable Security/Eval
46
55
  end
47
56
  # END ENGINE_CART BLOCK
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # GeoBlacklight Sidecar Images
2
2
 
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
- [![rubygem](https://badgen.net/rubygems/v/geoblacklight_sidecar_images)](https://badgen.net/rubygems/v/geoblacklight_sidecar_images)
3
+ ![CI](https://github.com/geoblacklight/geoblacklight_sidecar_images/actions/workflows/ruby.yml/badge.svg)
4
+ [![Gem Version](https://img.shields.io/gem/v/geoblacklight_sidecar_images.svg)](https://github.com/geoblacklight/geoblacklight_sidecar_images/releases)
7
5
 
8
6
  Store local copies of remote imagery in GeoBlacklight.
9
7
 
@@ -105,10 +103,10 @@ bundle exec rake gblsci:images:harvest_all
105
103
 
106
104
  #### Harvest an individual image
107
105
 
108
- Allows you to add images one document id at a time.
106
+ Allows you to add images one document id at a time. Pass a DOC_ID env var.
109
107
 
110
108
  ```bash
111
- bundle exec rake gblsci:images:harvest_doc_id['stanford-cz128vq0535']
109
+ DOC_ID='stanford-cz128vq0535' bundle exec rake gblsci:images:harvest_doc_id
112
110
  ```
113
111
 
114
112
  #### Harvest all incomplete states
@@ -163,7 +161,7 @@ bundle exec rake gblsci:images:harvest_purge_orphans
163
161
  Remove sidecar objects and attached images via a CSV file of document ids
164
162
 
165
163
  ```bash
166
- bundle exec rake gblsci:images:harvest_purge_orphans
164
+ bundle exec rake gblsci:images:harvest_destroy_batch
167
165
  ```
168
166
 
169
167
  ### Troubleshooting
@@ -278,5 +276,6 @@ tail -f log/image_service_development.log
278
276
  * ~~0.3.0 - Add Statesman (state machine library)~~
279
277
  * ~~0.4.0 - Rails 5.2 branch / Switch to ActionStorage~~
280
278
  * ~~0.7.0 - Rails 5.2+ and 6+ / GeoBlacklight 2+ and 3+ support~~
279
+ * ~~0.8.0 - GeoBlacklight Aardvark support~~
281
280
  * 0.7.0 to 0.9.0 - Feedback; Improve test coverage; Collect additional real-world issues
282
281
  * 1.0.0 - Final release
data/Rakefile CHANGED
@@ -1,33 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails'
3
+ require "rails"
4
4
  begin
5
- require 'bundler/setup'
6
- require 'bundler/gem_tasks'
5
+ require "bundler/setup"
6
+ require "bundler/gem_tasks"
7
7
  rescue LoadError
8
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
9
9
  end
10
10
 
11
11
  Bundler::GemHelper.install_tasks
12
12
 
13
- require 'solr_wrapper'
13
+ require "solr_wrapper"
14
14
 
15
- require 'rspec/core/rake_task'
15
+ require "rspec/core/rake_task"
16
16
  RSpec::Core::RakeTask.new(:spec)
17
17
 
18
- require 'rubocop/rake_task'
18
+ require "rubocop/rake_task"
19
19
  RuboCop::RakeTask.new(:rubocop)
20
20
 
21
- require 'solr_wrapper/rake_task'
22
- require 'engine_cart/rake_task'
23
- require 'geoblacklight_sidecar_images/version'
21
+ require "solr_wrapper/rake_task"
22
+ require "engine_cart/rake_task"
23
+ require "geoblacklight_sidecar_images/version"
24
24
 
25
- task ci: ['engine_cart:generate'] do
26
- ENV['environment'] = 'test'
27
- SolrWrapper.wrap do |solr|
28
- solr.with_collection(name: 'blacklight-core', dir: File.join(__dir__, 'solr', 'conf')) do
29
- # run the tests
30
- Rake::Task['spec'].invoke
25
+ desc "Run test suite"
26
+ task ci: ["engine_cart:generate"] do
27
+ ENV["environment"] = "test"
28
+ # run the tests
29
+ Rake::Task["spec"].invoke
30
+ end
31
+
32
+ namespace :geoblacklight do
33
+ namespace :internal do
34
+ task seed: ["engine_cart:generate"] do
35
+ within_test_app do
36
+ system "bundle exec rake gblsci:sample_data:seed"
37
+ system "bundle exec rake geoblacklight:downloads:mkdir"
38
+ end
39
+ end
40
+ end
41
+
42
+ desc "Run Solr and seed with sample data"
43
+ task :solr do
44
+ if File.exist? EngineCart.destination
45
+ within_test_app do
46
+ system "bundle update"
47
+ end
48
+ else
49
+ Rake::Task["engine_cart:generate"].invoke
50
+ end
51
+
52
+ SolrWrapper.wrap(port: "8983") do |solr|
53
+ solr.with_collection(name: "blacklight-core", dir: File.join(File.expand_path(".", File.dirname(__FILE__)), "solr", "conf")) do
54
+ Rake::Task["geoblacklight:internal:seed"].invoke
55
+
56
+ within_test_app do
57
+ puts "\nSolr server running: http://localhost:#{solr.port}/solr/#/blacklight-core"
58
+ puts "\n^C to stop"
59
+ puts " "
60
+ begin
61
+ sleep
62
+ rescue Interrupt
63
+ puts "Shutting down..."
64
+ end
65
+ end
66
+ end
31
67
  end
32
68
  end
33
69
  end
@@ -8,8 +8,8 @@ module GeoblacklightSidecarImages
8
8
  document = Geoblacklight::SolrDocument.find(solr_document_id)
9
9
 
10
10
  metadata = {}
11
- metadata['solr_doc_id'] = document.id
12
- metadata['solr_version'] = document.sidecar.version
11
+ metadata["solr_doc_id"] = document.id
12
+ metadata["solr_version"] = document.sidecar.version
13
13
 
14
14
  document.sidecar.image_state.transition_to!(:queued, metadata)
15
15
  GeoblacklightSidecarImages::ImageService.new(document).store
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GeoblacklightSidecarImages
4
4
  class ApplicationMailer < ActionMailer::Base
5
- default from: 'from@example.com'
6
- layout 'mailer'
5
+ default from: "from@example.com"
6
+ layout "mailer"
7
7
  end
8
8
  end
@@ -17,6 +17,6 @@ module WmsRewriteConcern
17
17
  end
18
18
 
19
19
  def local?
20
- fetch(:dct_provenance_s, '').casecmp(Settings.INSTITUTION_LOCAL_NAME).zero?
20
+ fetch(Settings.FIELDS.PROVENANCE, "").casecmp(Settings.INSTITUTION_LOCAL_NAME).zero?
21
21
  end
22
22
  end
@@ -12,10 +12,10 @@ class SidecarImageStateMachine
12
12
 
13
13
  # Queued => Background Job Init
14
14
  # Processing => Failed, Placeheld, Succeeded
15
- transition from: :initialized, to: %i[queued processing]
16
- transition from: :queued, to: %i[queued processing]
17
- transition from: :processing, to: %i[queued processing placeheld succeeded failed]
18
- transition from: :placeheld, to: %i[queued processing failed]
19
- transition from: :failed, to: %i[queued processing]
20
- transition from: :succeeded, to: %i[queued processing]
15
+ transition from: :initialized, to: %i[queued processing]
16
+ transition from: :queued, to: %i[queued processing]
17
+ transition from: :processing, to: %i[queued processing placeheld succeeded failed]
18
+ transition from: :placeheld, to: %i[queued processing failed]
19
+ transition from: :failed, to: %i[queued processing]
20
+ transition from: :succeeded, to: %i[queued processing]
21
21
  end
@@ -3,7 +3,7 @@
3
3
  class SidecarImageTransition < ApplicationRecord
4
4
  include Statesman::Adapters::ActiveRecordTransition
5
5
 
6
- validates :to_state, inclusion: { in: SidecarImageStateMachine.states }
6
+ validates :to_state, inclusion: {in: SidecarImageStateMachine.states}
7
7
 
8
8
  belongs_to :solr_document_sidecar, inverse_of: :sidecar_image_transitions
9
9
  end
@@ -10,7 +10,7 @@ module GeoblacklightSidecarImages
10
10
  # @param [Integer] thumbnail size
11
11
  # @return [String] iiif thumbnail url
12
12
  def self.image_url(document, size)
13
- "#{document.viewer_endpoint.gsub('info.json', '')}full/#{size},/0/default.jpg"
13
+ "#{document.viewer_endpoint.gsub("info.json", "")}full/#{size},/0/default.jpg"
14
14
  end
15
15
  end
16
16
  end
@@ -15,11 +15,11 @@ module GeoblacklightSidecarImages
15
15
  # Swap proxy url with princeton geoserver url.
16
16
  # Thumbnail requests send geoserver auth.
17
17
  endpoint = document.viewer_endpoint.gsub(Settings.PROXY_GEOSERVER_URL,
18
- Settings.INSTITUTION_GEOSERVER_URL)
18
+ Settings.INSTITUTION_GEOSERVER_URL)
19
19
  "#{endpoint}/reflect?" \
20
- '&FORMAT=image%2Fpng' \
21
- '&TRANSPARENT=TRUE' \
22
- "&LAYERS=#{document['layer_id_s']}" \
20
+ "&FORMAT=image%2Fpng" \
21
+ "&TRANSPARENT=TRUE" \
22
+ "&LAYERS=#{document["layer_id_s"]}" \
23
23
  "&WIDTH=#{size}" \
24
24
  "&HEIGHT=#{size}"
25
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'addressable/uri'
4
- require 'mimemagic'
3
+ require "addressable/uri"
4
+ require "mimemagic"
5
5
 
6
6
  module GeoblacklightSidecarImages
7
7
  class ImageService
@@ -12,15 +12,15 @@ module GeoblacklightSidecarImages
12
12
  @document = document
13
13
 
14
14
  @metadata = {}
15
- @metadata['solr_doc_id'] = document.id
16
- @metadata['solr_version'] = @document.sidecar.version
17
- @metadata['placeheld'] = false
15
+ @metadata["solr_doc_id"] = document.id
16
+ @metadata["solr_version"] = @document.sidecar.version
17
+ @metadata["placeheld"] = false
18
18
 
19
19
  @document.sidecar.image_state.transition_to!(:processing, @metadata)
20
20
 
21
21
  @logger ||= ActiveSupport::TaggedLogging.new(
22
22
  Logger.new(
23
- Rails.root.join('log', "image_service_#{Rails.env}.log")
23
+ Rails.root.join("log", "image_service_#{Rails.env}.log")
24
24
  )
25
25
  )
26
26
  end
@@ -34,15 +34,15 @@ module GeoblacklightSidecarImages
34
34
 
35
35
  io_file = image_tempfile(@document.id)
36
36
 
37
- if io_file.nil? || @metadata['placeheld'] == true
37
+ if io_file.nil? || @metadata["placeheld"] == true
38
38
  @document.sidecar.image_state.transition_to!(:placeheld, @metadata)
39
39
  else
40
40
  attach_io(io_file)
41
41
  end
42
42
 
43
43
  log_output
44
- rescue Exception => e
45
- @metadata['exception'] = e.inspect
44
+ rescue => e
45
+ @metadata["exception"] = e.inspect
46
46
  @document.sidecar.image_state.transition_to!(:failed, @metadata)
47
47
 
48
48
  log_output
@@ -51,18 +51,18 @@ module GeoblacklightSidecarImages
51
51
  private
52
52
 
53
53
  def image_tempfile(document_id)
54
- @metadata['viewer_protocol'] = @document.viewer_protocol
55
- @metadata['image_url'] = image_url
56
- @metadata['gblsi_thumbnail_uri'] = gblsi_thumbnail_uri
54
+ @metadata["viewer_protocol"] = @document.viewer_protocol
55
+ @metadata["image_url"] = image_url
56
+ @metadata["gblsi_thumbnail_uri"] = gblsi_thumbnail_uri
57
57
 
58
- return nil unless image_data && @metadata['placeheld'] == false
58
+ return nil unless image_data && @metadata["placeheld"] == false
59
59
 
60
- temp_file = Tempfile.new([document_id, '.tmp'])
60
+ temp_file = Tempfile.new("#{document_id}.tmp")
61
61
  temp_file.binmode
62
62
  temp_file.write(image_data)
63
63
  temp_file.rewind
64
64
 
65
- @metadata['image_tempfile'] = temp_file.inspect
65
+ @metadata["image_tempfile"] = temp_file.inspect
66
66
  temp_file
67
67
  end
68
68
 
@@ -71,11 +71,11 @@ module GeoblacklightSidecarImages
71
71
  # Pull the mimetype and file extension via MimeMagic
72
72
  mm = MimeMagic.by_magic(File.open(io))
73
73
 
74
- @metadata['MimeMagic_type'] = mm.type
75
- @metadata['MimeMagic_mediatype'] = mm.mediatype
76
- @metadata['MimeMagic_subtype'] = mm.subtype
74
+ @metadata["MimeMagic_type"] = mm.type
75
+ @metadata["MimeMagic_mediatype"] = mm.mediatype
76
+ @metadata["MimeMagic_subtype"] = mm.subtype
77
77
 
78
- if mm.mediatype == 'image'
78
+ if mm.mediatype == "image"
79
79
  @document.sidecar.image.attach(
80
80
  io: io,
81
81
  filename: "#{@document.id}.#{mm.subtype}",
@@ -91,12 +91,12 @@ module GeoblacklightSidecarImages
91
91
  def geoserver_credentials
92
92
  return unless restricted_wms_layer?
93
93
 
94
- Settings.PROXY_GEOSERVER_AUTH.gsub('Basic ', '')
94
+ Settings.PROXY_GEOSERVER_AUTH.gsub("Basic ", "")
95
95
  end
96
96
 
97
97
  # Tests if geoserver credentials are set beyond the default.
98
98
  def geoserver_credentials_valid?
99
- Settings.PROXY_GEOSERVER_AUTH != 'Basic base64encodedusername:password'
99
+ Settings.PROXY_GEOSERVER_AUTH != "Basic base64encodedusername:password"
100
100
  end
101
101
 
102
102
  # Tests if local thumbnail method is configured
@@ -125,23 +125,23 @@ module GeoblacklightSidecarImages
125
125
 
126
126
  uri = Addressable::URI.parse(image_url)
127
127
 
128
- return nil unless uri.scheme.include?('http')
128
+ return nil unless uri.scheme.include?("http")
129
129
 
130
130
  conn = Faraday.new(url: uri.normalize.to_s) do |b|
131
- b.use FaradayMiddleware::FollowRedirects
131
+ b.use Geoblacklight::FaradayMiddleware::FollowRedirects
132
132
  b.adapter :net_http
133
133
  end
134
134
 
135
135
  conn.options.timeout = timeout
136
136
  conn.authorization :Basic, auth if auth
137
137
  conn.get.body
138
- rescue Faraday::Error::ConnectionFailed
139
- @metadata['error'] = 'Faraday::Error::ConnectionFailed'
140
- @metadata['placeheld'] = true
138
+ rescue Faraday::ConnectionFailed
139
+ @metadata["error"] = "Faraday::ConnectionFailed"
140
+ @metadata["placeheld"] = true
141
141
  nil
142
- rescue Faraday::Error::TimeoutError
143
- @metadata['error'] = 'Faraday::Error::TimeoutError'
144
- @metadata['placeheld'] = true
142
+ rescue Faraday::TimeoutError
143
+ @metadata["error"] = "Faraday::TimeoutError"
144
+ @metadata["placeheld"] = true
145
145
  nil
146
146
  end
147
147
 
@@ -151,24 +151,24 @@ module GeoblacklightSidecarImages
151
151
  # dct references is used instead.
152
152
  def image_url
153
153
  @image_url ||= if gblsi_thumbnail_uri
154
- gblsi_thumbnail_uri
155
- elsif restricted_scanned_map?
156
- image_reference
157
- elsif restricted_wms_layer? && !geoserver_credentials_valid?
158
- image_reference
159
- else
160
- service_url || image_reference
161
- end
154
+ gblsi_thumbnail_uri
155
+ elsif restricted_scanned_map?
156
+ image_reference
157
+ elsif restricted_wms_layer? && !geoserver_credentials_valid?
158
+ image_reference
159
+ else
160
+ service_url || image_reference
161
+ end
162
162
  end
163
163
 
164
164
  # Checks if the document is Local restriced access and is a scanned map.
165
165
  def restricted_scanned_map?
166
- @document.local_restricted? && @document['layer_geom_type_s'] == 'Image'
166
+ @document.local_restricted? && @document["layer_geom_type_s"] == "Image"
167
167
  end
168
168
 
169
169
  # Checks if the document is Local restriced access and is a wms layer.
170
170
  def restricted_wms_layer?
171
- @document.local_restricted? && @document.viewer_protocol == 'wms'
171
+ @document.local_restricted? && @document.viewer_protocol == "wms"
172
172
  end
173
173
 
174
174
  # Gets the url for a specific service endpoint if the item is
@@ -186,15 +186,15 @@ module GeoblacklightSidecarImages
186
186
 
187
187
  protocol = @document.viewer_protocol
188
188
 
189
- if protocol == 'map' || protocol.nil?
190
- @metadata['error'] = 'Unsupported viewer protocol'
191
- @metadata['placeheld'] = true
189
+ if protocol == "map" || protocol.nil?
190
+ @metadata["error"] = "Unsupported viewer protocol"
191
+ @metadata["placeheld"] = true
192
192
  return nil
193
193
  end
194
194
  "GeoblacklightSidecarImages::ImageService::#{protocol.camelcase}".constantize.image_url(@document, image_size)
195
195
  rescue NameError
196
- @metadata['error'] = 'service_url NameError'
197
- @metadata['placeheld'] = true
196
+ @metadata["error"] = "service_url NameError"
197
+ @metadata["placeheld"] = true
198
198
  return nil
199
199
  end
200
200
  end
@@ -203,7 +203,7 @@ module GeoblacklightSidecarImages
203
203
  def image_reference
204
204
  return nil if @document[@document.references.reference_field].nil?
205
205
 
206
- JSON.parse(@document[@document.references.reference_field])['http://schema.org/thumbnailUrl']
206
+ JSON.parse(@document[@document.references.reference_field])["http://schema.org/thumbnailUrl"]
207
207
  end
208
208
 
209
209
  # Default image size.
@@ -218,7 +218,7 @@ module GeoblacklightSidecarImages
218
218
 
219
219
  # Capture metadata within image harvest log
220
220
  def log_output
221
- @metadata['state'] = @document.sidecar.image_state.current_state
221
+ @metadata["state"] = @document.sidecar.image_state.current_state
222
222
  @metadata.each do |key, value|
223
223
  @logger.tagged(@document.id, key.to_s) { @logger.info value }
224
224
  end
@@ -4,7 +4,7 @@ class CreateSolrDocumentSidecars < ActiveRecord::Migration[5.2]
4
4
  t.string "document_id"
5
5
  t.string "document_type"
6
6
  t.string "image"
7
- t.integer "version", :limit => 8
7
+ t.integer "version", limit: 8
8
8
 
9
9
  t.index ["document_type", "document_id"], name: "sidecars_solr_document"
10
10
 
@@ -17,13 +17,13 @@ class CreateSidecarImageTransitions < ActiveRecord::Migration[5.2]
17
17
  add_foreign_key :sidecar_image_transitions, :solr_document_sidecars
18
18
 
19
19
  add_index(:sidecar_image_transitions,
20
- [:solr_document_sidecar_id, :sort_key],
21
- unique: true,
22
- name: "index_sidecar_image_transitions_parent_sort")
20
+ [:solr_document_sidecar_id, :sort_key],
21
+ unique: true,
22
+ name: "index_sidecar_image_transitions_parent_sort")
23
23
  add_index(:sidecar_image_transitions,
24
- [:solr_document_sidecar_id, :most_recent],
25
- unique: true,
24
+ [:solr_document_sidecar_id, :most_recent],
25
+ unique: true,
26
26
 
27
- name: "index_sidecar_image_transitions_parent_most_recent")
27
+ name: "index_sidecar_image_transitions_parent_most_recent")
28
28
  end
29
29
  end