to_spotlight 0.1 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dc3e37bf423a699fa57b0be84458a76c686728ba2a03e9c77568038e23f5182
4
- data.tar.gz: f7afd69a08db348741e5bdfed68a600bfadfc7538af0334417efabacf8618578
3
+ metadata.gz: 3ea6f68b05d7d4f9b057547c061f87662e11035f57221224981405b1bbf8fa39
4
+ data.tar.gz: ae68623ec486dec854761be782e34294b84c4c6c26aa644f0a3fabef531b98f2
5
5
  SHA512:
6
- metadata.gz: d4bf67bc61638150beb70abc78e6a2f91575824e777c7c983a5eda3ce07ef2617544ef03c38c05d51fbb19d9894d3ecce29496f028877d51b4bd8e3a305ab3ae
7
- data.tar.gz: b8f4385cd08ed6a9de0afa4598c966665e85d9c287e3162c08c9bd05260c3eefadb3d5aee52f9f99e9563eda600a52dc9869aa84796accc7e320577834796b8b
6
+ metadata.gz: b23903e78b1729da5ea57ddfa59e9f9da96a6ae6df269d60b962af53425489f6083712b3c92b12be5533705dbc9d889a34742e9282fe96509e3d123e30fede43
7
+ data.tar.gz: 349dacb9846d0a657e57b7c7df14add4211daf7d76f7a0ae0319c028e76799b699d8be663e0400241a8565e066009699541445d44498e99a598e5cb60f863ade
@@ -1,7 +1,12 @@
1
1
  module ToSpotlight
2
2
  class SpotlightTransferController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
+ before_action :authenticate_user!
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
5
10
  require 'json'
6
11
  require 'net/http'
7
12
 
@@ -20,15 +25,9 @@ module ToSpotlight
20
25
  end
21
26
 
22
27
  def receive
23
- return unless params[:token]
24
- user = params.permit!.to_h[:user]
25
- mappings = params.permit!.to_h[:mappings]
26
- collection_id = params.permit!.to_h[:collection_id]
27
- exhibit_id = params.permit!.to_h[:exhibit_id]
28
- @transfer = ToSpotlight::SpotlightTransfer.new user: user,
29
- mappings: mappings,
30
- collection_id: collection_id,
31
- exhibit_id: exhibit_id
28
+ return unless params[:token] == token
29
+ @transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
30
+ @transfer.mappings = params[:mappings]
32
31
  if @transfer.save
33
32
  render plain: 'Transfer Request Received'
34
33
  else
@@ -45,18 +44,21 @@ module ToSpotlight
45
44
  transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
46
45
  works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
47
46
  mappings = mapping_invert transfer.mappings
48
- SpotlightTransferJob.perform_later(works.to_a, mappings) if now
49
- SpotlightTransferJob.set(wait_until: Date.today.end_of_day).perform_later(works.to_a, mappings) unless now
50
- #@res = ::Net::HTTP.post URI('http://localhost:3000/from_hyrax/receive'),
51
- # { transfer: transfer.attributes,
52
- # now: now,
53
- # token: 'secret_token' }.to_json,
54
- # 'Content-Type' => 'application/json'
47
+ if now
48
+ SpotlightTransferJob.perform_later(works.to_a, mappings, transfer)
49
+ else
50
+ SpotlightTransferJob.set(wait_until: Date.today.end_of_day)
51
+ .perform_later(works.to_a, mappings, transfer)
52
+ end
55
53
 
56
54
  end
57
55
 
58
56
  private
59
57
 
58
+ def token
59
+ ToSpotlight::Engine.config['hyrax_instances']
60
+ end
61
+
60
62
  def mapping_invert(hash)
61
63
  result = []
62
64
  test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
@@ -118,5 +120,12 @@ module ToSpotlight
118
120
  eval a_of_a.map{|a| a.inspect}.join(' & ')
119
121
  end
120
122
 
123
+ def get_transfer_attributes
124
+ params.require(:transfer).permit(:user,
125
+ :exhibit_id,
126
+ :collection_id,
127
+ :spotlight_url)
128
+ end
129
+
121
130
  end
122
131
  end
@@ -2,7 +2,7 @@ module ToSpotlight
2
2
  class SpotlightTransferJob < ActiveJob::Base
3
3
  queue_as :default
4
4
 
5
- def perform(works, mappings)
5
+ def perform(works, mappings, transfer)
6
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
8
  csv_array = [csv_headers.join(',')]
@@ -16,21 +16,21 @@ module ToSpotlight
16
16
  # next if wk.file_set_ids.length>1
17
17
  #end
18
18
  #index += 1
19
- comp = wk.file_set_ids.any?
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
23
23
  wk.ordered_file_set_ids.each do |f_id|
24
- csv_array << empty_fs_line(f_id, csv_headers.length-1)
24
+ csv_array << empty_fs_line(f_id, csv_headers.length - 1)
25
25
  children << index
26
26
  index += 1
27
27
  end
28
28
  end
29
-
29
+
30
30
  doc = ::SolrDocument.find wk.id
31
-
31
+
32
32
  line_hash = {}
33
- line_hash['url'] = "http://#{base_url}/downloads/#{wk.file_sets.first.id}?locale=en" #url
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|
@@ -50,6 +50,20 @@ module ToSpotlight
50
50
  File.open(dir.join(filename), 'wb') do |file|
51
51
  file.write(csv_array.join("\n"))
52
52
  end
53
+ res = post_response URI("#{transfer.spotlight_url}/from_hyrax/receive"),
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
+
58
+ end
59
+
60
+ def post_response uri, options={}
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.use_ssl = true
63
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
65
+ request.body = options.to_json
66
+ http.request(request)
53
67
  end
54
68
 
55
69
  def base_url
@@ -57,7 +71,7 @@ module ToSpotlight
57
71
  end
58
72
 
59
73
  def empty_fs_line fs_id, commas
60
- "http://#{base_url}downloads/#{fs_id}?locale=en" + (',' * commas)
74
+ "http://#{base_url}/downloads/#{fs_id}?locale=en" + (',' * commas)
61
75
  end
62
76
 
63
77
  def create_cell w, field
@@ -72,6 +86,10 @@ module ToSpotlight
72
86
  end
73
87
  end
74
88
 
89
+ def underscore_name work
90
+ work.class.to_s.underscore + 's'
91
+ end
92
+
75
93
  def get_location list
76
94
  output = []
77
95
  list.each do |loc|
@@ -83,11 +101,11 @@ module ToSpotlight
83
101
  def get_resource list
84
102
  output = []
85
103
  list.each do |url|
86
- if url.include? 'http'
87
- output << Hyrax::ResourceTypesService.label(url)
88
- else
89
- output << url
90
- end
104
+ output << if url.include? 'http'
105
+ Hyrax::ResourceTypesService.label(url)
106
+ else
107
+ url
108
+ end
91
109
  end
92
110
  output.join('; ')
93
111
  end
@@ -95,11 +113,11 @@ module ToSpotlight
95
113
  def get_rights list
96
114
  output = []
97
115
  list.each do |url|
98
- if url.include? 'http'
99
- output << ::VaultRightsStatementsService.label(url)
100
- else
101
- output << url
102
- end
116
+ output << if url.include? 'http'
117
+ ::VaultRightsStatementsService.label(url)
118
+ else
119
+ url
120
+ end
103
121
  end
104
122
  #output = list.map { |url| url.include? "http" ? IaffRightsStatementService.label(url) : url }
105
123
  output.join('; ')
@@ -1,5 +1,3 @@
1
- <h1>ToSpotlight#approve</h1>
2
- <p>Find me in app/views/to_spotlight/to_spotlight/approve.html.erb</p>
3
1
  <%= params.inspect %>
4
2
 
5
3
  <br/>
@@ -6,6 +6,7 @@ class CreateToSpotlightSpotlightTransfers < ActiveRecord::Migration[5.0]
6
6
  t.boolean :approved, default: false
7
7
  t.string :collection_id
8
8
  t.string :exhibit_id
9
+ t.string :spotlight_url
9
10
 
10
11
  t.timestamps
11
12
  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'
@@ -1,3 +1,3 @@
1
1
  module ToSpotlight
2
- VERSION = '0.1'
2
+ VERSION = '0.2.4'.freeze
3
3
  end
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.1'
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,6 +72,8 @@ files:
72
72
  - config/application.rb
73
73
  - config/routes.rb
74
74
  - db/migrate/20200310153953_create_to_spotlight_spotlight_transfers.rb
75
+ - lib/generators/install/install_generator.rb
76
+ - lib/generators/install/templates/config/to_spotlight.yml
75
77
  - lib/tasks/to_spotlight_tasks.rake
76
78
  - lib/to_spotlight.rb
77
79
  - lib/to_spotlight/engine.rb