to_spotlight 0.0.3 → 0.1

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: 36ec581276c27e1c851f430d2390e177763863df1edbf2828f0015607e0e5d7d
4
- data.tar.gz: ed68bfd105acf8f243ffcadacba335c9fcade7d1bb3aad09e23785f48ebd3583
3
+ metadata.gz: 3dc3e37bf423a699fa57b0be84458a76c686728ba2a03e9c77568038e23f5182
4
+ data.tar.gz: f7afd69a08db348741e5bdfed68a600bfadfc7538af0334417efabacf8618578
5
5
  SHA512:
6
- metadata.gz: f496d05636aa8eca5681226d0e027fb45735917324568ecb945eb252f69fd7b436c633336765fc2defc57d833d4105f6cbfda917cbe9a7848226e674ffe9a212
7
- data.tar.gz: cead82120d6613d68bde233aeb1a653216e7ceb30da0c3579624f20c69eddd8e6dd3fb01f7e01da18c5b01f119200ba987e06eed18f74bbfebbdb87846a18ff0
6
+ metadata.gz: d4bf67bc61638150beb70abc78e6a2f91575824e777c7c983a5eda3ce07ef2617544ef03c38c05d51fbb19d9894d3ecce29496f028877d51b4bd8e3a305ab3ae
7
+ data.tar.gz: b8f4385cd08ed6a9de0afa4598c966665e85d9c287e3162c08c9bd05260c3eefadb3d5aee52f9f99e9563eda600a52dc9869aa84796accc7e320577834796b8b
@@ -43,9 +43,10 @@ module ToSpotlight
43
43
  def approve
44
44
  now = params[:commit].downcase.include?('now')
45
45
  transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
46
- works = ::Collection.find(transfer.collection_id).members
46
+ works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
47
47
  mappings = mapping_invert transfer.mappings
48
- SpotlightTransferJob.perform_later(works, 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
49
50
  #@res = ::Net::HTTP.post URI('http://localhost:3000/from_hyrax/receive'),
50
51
  # { transfer: transfer.attributes,
51
52
  # now: now,
@@ -56,10 +57,10 @@ module ToSpotlight
56
57
 
57
58
  private
58
59
 
59
- def mapping_invert hash
60
+ def mapping_invert(hash)
60
61
  result = []
61
- test = hash.map { |h| { h['hyrax'] => h['spotlight'].values } }
62
- test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result<<a2 } }
62
+ test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
63
+ test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result << a2 } }
63
64
  Hash[result]
64
65
  end
65
66
 
@@ -72,11 +73,11 @@ module ToSpotlight
72
73
  end
73
74
 
74
75
  def curated_fields
75
- work_fields(params[:work].constantize) - excluded_fields
76
+ {"common_fields" => (work_fields - excluded_fields - field_differences), "differences" => field_differences}
76
77
  end
77
78
 
78
- def work_fields work
79
- work.new.attributes.keys
79
+ def work_fields
80
+ curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
80
81
  #%w[id head tail depositor title date_uploaded date_modified state
81
82
  # proxy_depositor on_behalf_of arkivo_checksum owner alternative_title
82
83
  # edition geographic_coverage coordinates chronological_coverage extent
@@ -98,5 +99,24 @@ module ToSpotlight
98
99
  representative_id thumbnail_id rendering_ids admin_set_id embargo_id
99
100
  lease_id]
100
101
  end
102
+
103
+ def field_differences
104
+ if @dif.nil?
105
+ @dif = []
106
+ curated_works.each do |work|
107
+ @dif += (work.constantize.new.attributes.keys - common_fields)
108
+ end
109
+ end
110
+ @dif.uniq
111
+ end
112
+
113
+ def common_fields
114
+ @all_works_hash ||= intersect(curated_works.map { |w| w.constantize.new.attributes.keys })
115
+ end
116
+
117
+ def intersect a_of_a
118
+ eval a_of_a.map{|a| a.inspect}.join(' & ')
119
+ end
120
+
101
121
  end
102
122
  end
@@ -5,7 +5,7 @@ module ToSpotlight
5
5
  def perform(works, mappings)
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
- csv_array = csv_headers
8
+ csv_array = [csv_headers.join(',')]
9
9
  #items = []
10
10
  works.each do |wk|
11
11
  #if comp
@@ -30,16 +30,16 @@ module ToSpotlight
30
30
  doc = ::SolrDocument.find wk.id
31
31
 
32
32
  line_hash = {}
33
- line_hash << "http://#{base_url}/downloads/#{wk.file_sets.first.id}?locale=en" #url
34
- line_hash << (doc.title.length > 1 ? doc.title.join('; ') : doc.title.first) #full_title_tesim
33
+ line_hash['url'] = "http://#{base_url}/downloads/#{wk.file_sets.first.id}?locale=en" #url
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|
37
37
  line_hash[skey] = create_cell doc, field
38
38
  end
39
39
 
40
- line_hash << children.join("|")
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
 
@@ -50,7 +50,6 @@ module ToSpotlight
50
50
  File.open(dir.join(filename), 'wb') do |file|
51
51
  file.write(csv_array.join("\n"))
52
52
  end
53
- items
54
53
  end
55
54
 
56
55
  def base_url
@@ -58,13 +57,13 @@ module ToSpotlight
58
57
  end
59
58
 
60
59
  def empty_fs_line fs_id, commas
61
- "http://#{base_url}downloads/#{fs_id}?locale=en" + ("," * commas)
60
+ "http://#{base_url}downloads/#{fs_id}?locale=en" + (',' * commas)
62
61
  end
63
62
 
64
63
  def create_cell w, field
65
- if w.respond_to?((field + "_label").to_sym)
66
- w.send(field + "_label").join(';')
67
- else
64
+ if w.respond_to?((field + '_label').to_sym)
65
+ w.send(field + '_label').join(';')
66
+ elsif w.respond_to?(field.to_sym)
68
67
  if w.send(field).is_a?(Array)
69
68
  w.send(field).join(';')
70
69
  else
@@ -84,7 +83,7 @@ module ToSpotlight
84
83
  def get_resource list
85
84
  output = []
86
85
  list.each do |url|
87
- if url.include? "http"
86
+ if url.include? 'http'
88
87
  output << Hyrax::ResourceTypesService.label(url)
89
88
  else
90
89
  output << url
@@ -96,7 +95,7 @@ module ToSpotlight
96
95
  def get_rights list
97
96
  output = []
98
97
  list.each do |url|
99
- if url.include? "http"
98
+ if url.include? 'http'
100
99
  output << ::VaultRightsStatementsService.label(url)
101
100
  else
102
101
  output << url
@@ -1,5 +1,9 @@
1
1
  module ToSpotlight
2
2
  class SpotlightTransfer < ApplicationRecord
3
3
  serialize :mappings
4
+
5
+ def collection_title
6
+ @collection_title ||= ::SolrDocument.find(collection_id).title.first
7
+ end
4
8
  end
5
9
  end
@@ -4,7 +4,7 @@
4
4
 
5
5
  <td><%= transfer.user %></td>
6
6
 
7
- <td><%= transfer.collection_id %></td>
7
+ <td><%= transfer.collection_title %></td>
8
8
 
9
9
  <td>
10
10
  <%= form_tag to_spotlight.approve_path, method: :post, class: "form-inline" do %>
@@ -4,4 +4,4 @@
4
4
 
5
5
  <br/>
6
6
 
7
- <%= @res.body %>
7
+ <%#= @res.body %>
@@ -1,3 +1,3 @@
1
1
  module ToSpotlight
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1'
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.0.3
4
+ version: '0.1'
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-22 00:00:00.000000000 Z
11
+ date: 2020-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails