to_spotlight 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/to_spotlight/spotlight_transfer_controller.rb +19 -29
- 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/to_spotlight/engine.rb +18 -2
- data/lib/to_spotlight/version.rb +1 -1
- metadata +2 -5
- data/app/views/to_spotlight/spotlight_transfer/_tabs.html.erb +0 -5
- data/app/views/to_spotlight/spotlight_transfer/approve.html.erb +0 -5
- 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,12 +1,12 @@
|
|
1
1
|
module ToSpotlight
|
2
2
|
class SpotlightTransferController < ApplicationController
|
3
3
|
protect_from_forgery with: :exception
|
4
|
-
before_action :authenticate_user
|
4
|
+
before_action :authenticate_user!, except: [:api, :receive]
|
5
5
|
skip_before_action :verify_authenticity_token, only: :receive
|
6
6
|
helper_method :default_page_title, :admin_host?, :available_translations, :available_works
|
7
7
|
include ActionView::Helpers::UrlHelper
|
8
8
|
layout 'hyrax/dashboard' if Hyrax
|
9
|
-
before_action :authenticate, except: :index
|
9
|
+
before_action :authenticate, except: [:index, :api, :receive]
|
10
10
|
require 'json'
|
11
11
|
require 'net/http'
|
12
12
|
|
@@ -26,7 +26,7 @@ module ToSpotlight
|
|
26
26
|
|
27
27
|
def receive
|
28
28
|
return unless params[:token] == token
|
29
|
-
@transfer
|
29
|
+
@transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
|
30
30
|
@transfer.mappings = params[:mappings]
|
31
31
|
if @transfer.save
|
32
32
|
render plain: 'Transfer Request Received'
|
@@ -40,9 +40,9 @@ module ToSpotlight
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def approve
|
43
|
-
now
|
43
|
+
now = params[:commit].downcase.include?('now')
|
44
44
|
transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
|
45
|
-
works
|
45
|
+
works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
|
46
46
|
mappings = mapping_invert transfer.mappings
|
47
47
|
if now
|
48
48
|
SpotlightTransferJob.perform_later(works.to_a, mappings, transfer)
|
@@ -50,7 +50,7 @@ module ToSpotlight
|
|
50
50
|
SpotlightTransferJob.set(wait_until: Date.today.end_of_day)
|
51
51
|
.perform_later(works.to_a, mappings, transfer)
|
52
52
|
end
|
53
|
-
|
53
|
+
redirect_to spotlight_transfer_index_path
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
@@ -61,7 +61,7 @@ module ToSpotlight
|
|
61
61
|
|
62
62
|
def mapping_invert(hash)
|
63
63
|
result = []
|
64
|
-
test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
|
64
|
+
test = hash.map { |h| { h['hyrax'] => h['spotlight'].values } }
|
65
65
|
test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result << a2 } }
|
66
66
|
Hash[result]
|
67
67
|
end
|
@@ -75,31 +75,21 @@ module ToSpotlight
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def curated_fields
|
78
|
-
{
|
78
|
+
{
|
79
|
+
common_fields: (work_fields - excluded_fields - field_differences),
|
80
|
+
differences: field_differences
|
81
|
+
}
|
79
82
|
end
|
80
83
|
|
81
84
|
def work_fields
|
82
|
-
curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
|
83
|
-
#%w[id head tail depositor title date_uploaded date_modified state
|
84
|
-
# proxy_depositor on_behalf_of arkivo_checksum owner alternative_title
|
85
|
-
# edition geographic_coverage coordinates chronological_coverage extent
|
86
|
-
# additional_physical_characteristics has_format physical_repository
|
87
|
-
# collection provenance provider sponsor genre format
|
88
|
-
# archival_item_identifier fonds_title fonds_creator fonds_description
|
89
|
-
# fonds_identifier is_referenced_by date_digitized transcript
|
90
|
-
# technical_note year label relative_path import_url creator part_of
|
91
|
-
# resource_type contributor description keyword license rights_statement
|
92
|
-
# publisher date_created subject language identifier based_near
|
93
|
-
# related_url bibliographic_citation source access_control_id
|
94
|
-
# representative_id thumbnail_id rendering_ids admin_set_id
|
95
|
-
# embargo_id lease_id]
|
85
|
+
@work_fields ||= curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
|
96
86
|
end
|
97
87
|
|
98
88
|
def excluded_fields
|
99
89
|
%w[id title head tail state proxy_depositor on_behalf_of arkivo_checksum label
|
100
|
-
|
101
|
-
|
102
|
-
|
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]
|
103
93
|
end
|
104
94
|
|
105
95
|
def field_differences
|
@@ -117,7 +107,7 @@ module ToSpotlight
|
|
117
107
|
end
|
118
108
|
|
119
109
|
def intersect a_of_a
|
120
|
-
eval a_of_a.map{|a| a.inspect}.join(' & ')
|
110
|
+
eval a_of_a.map { |a| a.inspect }.join(' & ')
|
121
111
|
end
|
122
112
|
|
123
113
|
def get_transfer_attributes
|
@@ -127,7 +117,7 @@ module ToSpotlight
|
|
127
117
|
:spotlight_url)
|
128
118
|
end
|
129
119
|
|
130
|
-
|
120
|
+
#helpers
|
131
121
|
def available_works
|
132
122
|
@available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
|
133
123
|
end
|
@@ -142,8 +132,8 @@ module ToSpotlight
|
|
142
132
|
|
143
133
|
def available_translations
|
144
134
|
{
|
145
|
-
|
146
|
-
|
135
|
+
'en' => 'English',
|
136
|
+
'fr' => 'French'
|
147
137
|
}
|
148
138
|
end
|
149
139
|
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
|
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,12 +64,9 @@ 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
|
75
72
|
- lib/generators/install/install_generator.rb
|
data/config/application.rb
DELETED