to_spotlight 0.2.1 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/to_spotlight/spotlight_transfer_controller.rb +44 -26
- data/app/jobs/to_spotlight/spotlight_transfer_job.rb +15 -15
- data/app/views/to_spotlight/spotlight_transfer/_default_group.html.erb +1 -1
- data/app/views/to_spotlight/spotlight_transfer/_list_transfers.html.erb +2 -2
- data/app/views/to_spotlight/spotlight_transfer/_transfers_list.html.erb +1 -1
- data/config/routes.rb +5 -5
- data/lib/generators/install/install_generator.rb +7 -0
- data/lib/generators/install/templates/config/to_spotlight.yml +1 -0
- data/lib/to_spotlight/engine.rb +18 -2
- data/lib/to_spotlight/version.rb +1 -1
- metadata +4 -5
- data/app/views/to_spotlight/spotlight_transfer/_tabs.html.erb +0 -5
- data/app/views/to_spotlight/spotlight_transfer/approve.html.erb +0 -7
- data/config/application.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0396d6c1545a7b42c6bc1598868019d0ff55e8a51c423e0657cbcfc6829902bd'
|
4
|
+
data.tar.gz: 0eee8724658d6492ef2ae51f4b5ec4462555b1bf448f2f8087e9ae35d0af5603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b74723ef303d5eaea2c5ca9953a88a88679048d1fdea86f759768b9bcf274a1c1ae35a55ca7625549767c018ff66ba18a856441ac057d2c133f52e845e885b4d
|
7
|
+
data.tar.gz: 0c41425fae0466f948a186426f732952308396fdbe572aef830a61bbffe7025c75ad1a736e30f8f3f1cdaa8ad45cbaa3464af020271f6af80052a88f50e7caeb
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module ToSpotlight
|
2
|
-
class SpotlightTransferController <
|
2
|
+
class SpotlightTransferController < ApplicationController
|
3
3
|
protect_from_forgery with: :exception
|
4
|
+
before_action :authenticate_user!, except: [:api, :receive]
|
4
5
|
skip_before_action :verify_authenticity_token, only: :receive
|
6
|
+
helper_method :default_page_title, :admin_host?, :available_translations, :available_works
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
layout 'hyrax/dashboard' if Hyrax
|
9
|
+
before_action :authenticate, except: [:index, :api, :receive]
|
5
10
|
require 'json'
|
6
11
|
require 'net/http'
|
7
12
|
|
@@ -20,8 +25,8 @@ module ToSpotlight
|
|
20
25
|
end
|
21
26
|
|
22
27
|
def receive
|
23
|
-
return unless params[:token]
|
24
|
-
@transfer
|
28
|
+
return unless params[:token] == token
|
29
|
+
@transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
|
25
30
|
@transfer.mappings = params[:mappings]
|
26
31
|
if @transfer.save
|
27
32
|
render plain: 'Transfer Request Received'
|
@@ -35,9 +40,9 @@ module ToSpotlight
|
|
35
40
|
end
|
36
41
|
|
37
42
|
def approve
|
38
|
-
now
|
43
|
+
now = params[:commit].downcase.include?('now')
|
39
44
|
transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
|
40
|
-
works
|
45
|
+
works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
|
41
46
|
mappings = mapping_invert transfer.mappings
|
42
47
|
if now
|
43
48
|
SpotlightTransferJob.perform_later(works.to_a, mappings, transfer)
|
@@ -45,14 +50,18 @@ module ToSpotlight
|
|
45
50
|
SpotlightTransferJob.set(wait_until: Date.today.end_of_day)
|
46
51
|
.perform_later(works.to_a, mappings, transfer)
|
47
52
|
end
|
48
|
-
|
53
|
+
redirect_to spotlight_transfer_index_path
|
49
54
|
end
|
50
55
|
|
51
56
|
private
|
52
57
|
|
58
|
+
def token
|
59
|
+
ToSpotlight::Engine.config['hyrax_instances']
|
60
|
+
end
|
61
|
+
|
53
62
|
def mapping_invert(hash)
|
54
63
|
result = []
|
55
|
-
test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
|
64
|
+
test = hash.map { |h| { h['hyrax'] => h['spotlight'].values } }
|
56
65
|
test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result << a2 } }
|
57
66
|
Hash[result]
|
58
67
|
end
|
@@ -66,31 +75,21 @@ module ToSpotlight
|
|
66
75
|
end
|
67
76
|
|
68
77
|
def curated_fields
|
69
|
-
{
|
78
|
+
{
|
79
|
+
common_fields: (work_fields - excluded_fields - field_differences),
|
80
|
+
differences: field_differences
|
81
|
+
}
|
70
82
|
end
|
71
83
|
|
72
84
|
def work_fields
|
73
|
-
curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
|
74
|
-
#%w[id head tail depositor title date_uploaded date_modified state
|
75
|
-
# proxy_depositor on_behalf_of arkivo_checksum owner alternative_title
|
76
|
-
# edition geographic_coverage coordinates chronological_coverage extent
|
77
|
-
# additional_physical_characteristics has_format physical_repository
|
78
|
-
# collection provenance provider sponsor genre format
|
79
|
-
# archival_item_identifier fonds_title fonds_creator fonds_description
|
80
|
-
# fonds_identifier is_referenced_by date_digitized transcript
|
81
|
-
# technical_note year label relative_path import_url creator part_of
|
82
|
-
# resource_type contributor description keyword license rights_statement
|
83
|
-
# publisher date_created subject language identifier based_near
|
84
|
-
# related_url bibliographic_citation source access_control_id
|
85
|
-
# representative_id thumbnail_id rendering_ids admin_set_id
|
86
|
-
# embargo_id lease_id]
|
85
|
+
@work_fields ||= curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
|
87
86
|
end
|
88
87
|
|
89
88
|
def excluded_fields
|
90
89
|
%w[id title head tail state proxy_depositor on_behalf_of arkivo_checksum label
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
relative_path import_url part_of resource_type access_control_id
|
91
|
+
representative_id thumbnail_id rendering_ids admin_set_id embargo_id
|
92
|
+
lease_id]
|
94
93
|
end
|
95
94
|
|
96
95
|
def field_differences
|
@@ -108,7 +107,7 @@ module ToSpotlight
|
|
108
107
|
end
|
109
108
|
|
110
109
|
def intersect a_of_a
|
111
|
-
eval a_of_a.map{|a| a.inspect}.join(' & ')
|
110
|
+
eval a_of_a.map { |a| a.inspect }.join(' & ')
|
112
111
|
end
|
113
112
|
|
114
113
|
def get_transfer_attributes
|
@@ -118,5 +117,24 @@ module ToSpotlight
|
|
118
117
|
:spotlight_url)
|
119
118
|
end
|
120
119
|
|
120
|
+
#helpers
|
121
|
+
def available_works
|
122
|
+
@available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_page_title
|
126
|
+
'Spotlight Transfer'
|
127
|
+
end
|
128
|
+
|
129
|
+
def admin_host?
|
130
|
+
false unless Settings.multitenancy.enabled rescue nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def available_translations
|
134
|
+
{
|
135
|
+
'en' => 'English',
|
136
|
+
'fr' => 'French'
|
137
|
+
}
|
138
|
+
end
|
121
139
|
end
|
122
140
|
end
|
@@ -3,9 +3,9 @@ module ToSpotlight
|
|
3
3
|
queue_as :default
|
4
4
|
|
5
5
|
def perform(works, mappings, transfer)
|
6
|
-
base_url
|
6
|
+
base_url = ::Account.where(tenant: Apartment::Tenant.current).first.cname
|
7
7
|
csv_headers = %w[url full_title_tesim] + mappings.keys + %w[children]
|
8
|
-
csv_array
|
8
|
+
csv_array = [csv_headers.join(',')]
|
9
9
|
#items = []
|
10
10
|
works.each do |wk|
|
11
11
|
#if comp
|
@@ -16,7 +16,7 @@ module ToSpotlight
|
|
16
16
|
# next if wk.file_set_ids.length>1
|
17
17
|
#end
|
18
18
|
#index += 1
|
19
|
-
comp
|
19
|
+
comp = false #wk.file_set_ids.length > 1
|
20
20
|
children = []
|
21
21
|
if comp
|
22
22
|
index = wk.ordered_file_set_ids.length * -1
|
@@ -29,8 +29,8 @@ module ToSpotlight
|
|
29
29
|
|
30
30
|
doc = ::SolrDocument.find wk.id
|
31
31
|
|
32
|
-
line_hash
|
33
|
-
line_hash['url']
|
32
|
+
line_hash = {}
|
33
|
+
line_hash['url'] = "http://#{base_url}/concern/#{underscore_name(wk)}/#{wk.id}/manifest.json" #url
|
34
34
|
line_hash['full_title_tesim'] = (doc.title.length > 1 ? doc.title.join('; ') : doc.title.first) #full_title_tesim
|
35
35
|
|
36
36
|
mappings.each do |skey, field|
|
@@ -39,30 +39,30 @@ module ToSpotlight
|
|
39
39
|
|
40
40
|
line_hash['children'] = children.join('|')
|
41
41
|
|
42
|
-
csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"","\"\"")}\"" }.join(',')
|
42
|
+
csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"", "\"\"")}\"" }.join(',')
|
43
43
|
|
44
44
|
end
|
45
45
|
|
46
46
|
dir = Rails.root.join('public', 'uploads', 'csvs')
|
47
47
|
Dir.mkdir(dir) unless Dir.exist?(dir)
|
48
|
-
time
|
48
|
+
time = DateTime.now.strftime('%s')
|
49
49
|
filename = "spotlight_export-#{time}.csv"
|
50
50
|
File.open(dir.join(filename), 'wb') do |file|
|
51
51
|
file.write(csv_array.join("\n"))
|
52
52
|
end
|
53
53
|
res = post_response URI("#{transfer.spotlight_url}/from_hyrax/receive"),
|
54
|
-
csv_url:
|
55
|
-
transfer:
|
56
|
-
token:
|
54
|
+
csv_url: "https://#{base_url}/uploads/csvs/#{filename}",
|
55
|
+
transfer: transfer.attributes.slice(:user, :exhibit), #only allow user+exhibit
|
56
|
+
token: 'secret_token'
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
def post_response uri, options={}
|
61
|
-
http
|
62
|
-
http.use_ssl
|
60
|
+
def post_response uri, options = {}
|
61
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
+
http.use_ssl = true
|
63
63
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
64
|
-
request
|
65
|
-
request.body
|
64
|
+
request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
|
65
|
+
request.body = options.to_json
|
66
66
|
http.request(request)
|
67
67
|
end
|
68
68
|
|
@@ -7,10 +7,10 @@
|
|
7
7
|
<td><%= transfer.collection_title %></td>
|
8
8
|
|
9
9
|
<td>
|
10
|
-
<%= form_tag
|
10
|
+
<%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
|
11
11
|
<%= hidden_field_tag 'transfer_id', transfer.id %>
|
12
12
|
<%= submit_tag "Run Tonight", class: 'btn btn-primary' %>
|
13
|
-
<% end %><%= form_tag
|
13
|
+
<% end %><%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
|
14
14
|
<%= hidden_field_tag 'transfer_id', transfer.id %>
|
15
15
|
<%= submit_tag "Run Now", class: 'btn btn-primary' %>
|
16
16
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
get 'api/:request_type' => 'spotlight_transfer#api'
|
3
|
-
post 'receive' => 'spotlight_transfer#receive'
|
4
|
-
get '
|
5
|
-
post 'approve' => 'spotlight_transfer#approve'
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
get '/to_spotlight/api/:request_type' => 'to_spotlight/spotlight_transfer#api', as: 'to_spotlight_api'
|
3
|
+
post '/to_spotlight/receive' => 'to_spotlight/spotlight_transfer#receive'
|
4
|
+
get '/to_spotlight' => 'to_spotlight/spotlight_transfer#index'
|
5
|
+
post '/to_spotlight/approve' => 'to_spotlight/spotlight_transfer#approve'
|
6
6
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class CdmMigrator::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def inject_content_dm_yml
|
5
|
+
copy_file('config/to_spotlight.yml', 'config/to_spotlight.yml') unless File.file?('config/to_spotlight.yml')
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
secret_token: 'rftvgyuhwefhcgyvuryweudijxoschdufygvebhqwdijloschvugbeiofhqdijlcnhqeljcmjioeql328r9hdfec3h'
|
data/lib/to_spotlight/engine.rb
CHANGED
@@ -3,10 +3,26 @@ module ToSpotlight
|
|
3
3
|
isolate_namespace ToSpotlight
|
4
4
|
initializer :append_migrations do |app|
|
5
5
|
unless app.root.to_s.match root.to_s
|
6
|
-
config.paths[
|
7
|
-
app.config.paths[
|
6
|
+
config.paths['db/migrate'].expanded.each do |expanded_path|
|
7
|
+
app.config.paths['db/migrate'] << expanded_path
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def config
|
15
|
+
file = File.open(File.join(::Rails.root, '/config/from_hyrax.yml'))
|
16
|
+
@config ||= YAML.safe_load(file)
|
17
|
+
end
|
18
|
+
|
19
|
+
# loads a yml file with the configuration options
|
20
|
+
#
|
21
|
+
# @param file [String] path to the yml file
|
22
|
+
#
|
23
|
+
def load_config(file)
|
24
|
+
@config = YAML.load_file(file)
|
25
|
+
end
|
26
|
+
end
|
11
27
|
end
|
12
28
|
end
|
data/lib/to_spotlight/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_spotlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sephirothkod
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -64,14 +64,13 @@ files:
|
|
64
64
|
- app/views/to_spotlight/spotlight_transfer/_default_group.html.erb
|
65
65
|
- app/views/to_spotlight/spotlight_transfer/_list_transfers.html.erb
|
66
66
|
- app/views/to_spotlight/spotlight_transfer/_select.html.erb
|
67
|
-
- app/views/to_spotlight/spotlight_transfer/_tabs.html.erb
|
68
67
|
- app/views/to_spotlight/spotlight_transfer/_transfers_list.html.erb
|
69
|
-
- app/views/to_spotlight/spotlight_transfer/approve.html.erb
|
70
68
|
- app/views/to_spotlight/spotlight_transfer/index.html.erb
|
71
69
|
- app/views/to_spotlight/spotlight_transfer/receive.html.erb
|
72
|
-
- config/application.rb
|
73
70
|
- config/routes.rb
|
74
71
|
- db/migrate/20200310153953_create_to_spotlight_spotlight_transfers.rb
|
72
|
+
- lib/generators/install/install_generator.rb
|
73
|
+
- lib/generators/install/templates/config/to_spotlight.yml
|
75
74
|
- lib/tasks/to_spotlight_tasks.rake
|
76
75
|
- lib/to_spotlight.rb
|
77
76
|
- lib/to_spotlight/engine.rb
|
data/config/application.rb
DELETED