bulk_ops 0.1.4 → 0.1.5

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: 01207f13266c7653d3b4febb53b07ca3841fe8db72e8a7798fbd0686f8301816
4
- data.tar.gz: '085b2596587d210d457e6dc0a7fe5f760ad8b28e5465da5266a2307133e83442'
3
+ metadata.gz: 5ca22890f1ad64017c266506d40ec4da8a457534bab1a129b8a19b2e49081bbc
4
+ data.tar.gz: dca608af70c35c1d1afb2def0c5afbdbf015d035f4ee15d4d7e58baaaf89f1a8
5
5
  SHA512:
6
- metadata.gz: d423e774693a246d8e7dde5ec88fb58dead4f92e30d3601f74f285feeb370efd193475c5ba0a1a10b1013532e0fc3e0d80dc551bdd6407644838abd12317b4dc
7
- data.tar.gz: 644fddf973a2c03e20c39b0bc55fa18ff290685ce41f4e1296c8cb0e1cf03a1b8e0a7a3597838a2cd858d87d549634de29af3c9c86e6a4dc00aefdd3d9fe5d68
6
+ metadata.gz: 7b3f8b03cd80cc8e24a1f135ebf8dadac1dc274d8c49d7fb0b1f968f41b5836aa2c92353d40e24a3a9d6dd48e32543ffe8ab83195c1cd8702cc481901bfd6d21
7
+ data.tar.gz: 9252201c835571f0a2c9d5a8027cd45c03acf95ffc865e5e5eebdbdab1c765d6c97c7515175874de2aede0a5950037a55b395fd47ed5ec590139501801f75751
@@ -316,7 +316,7 @@ module BulkOps
316
316
 
317
317
  @operation.stage = "verifying"
318
318
  @operation.save
319
- BulkOps::VerificationJob.perform_later(@operation)
319
+ BulkOps::VerificationJob.perform_later(@operation.id)
320
320
  flash[:notice] = "We are now running the data from your spreadsheet through an automatic verification process to anticipate any problems before we begin the ingest. This may take a few minutes. You should recieve an email when the process completes."
321
321
  redirect_to action: "show"
322
322
  end
@@ -4,9 +4,13 @@ module BulkOps
4
4
 
5
5
  def verify
6
6
  @verification_errors ||= []
7
+ update(message: "verifying spreadsheet column headers")
7
8
  verify_column_headers
9
+ update(message: "verifying controlled vocab urls (starting)")
8
10
  verify_remote_urls
11
+ update(message: "verifying complex object structures")
9
12
  verify_internal_references
13
+ update(message: "verifying that all files exist")
10
14
  verify_files
11
15
  verify_works_to_update if operation_type.to_s == "update"
12
16
  unless @verification_errors.blank?
@@ -29,6 +33,7 @@ module BulkOps
29
33
 
30
34
  def is_file_field?(fieldname)
31
35
  return false if fieldname.blank?
36
+ return false if schema.get_field(fieldname)
32
37
  field_parts = fieldname.underscore.humanize.downcase.gsub(/[-_]/,' ').split(" ")
33
38
  return false unless field_parts.any?{ |field_type| BulkOps::WorkProxy::FILE_FIELDS.include?(field_type) }
34
39
  return "remove" if field_parts.any?{ |field_type| ['remove','delete'].include?(field_type) }
@@ -126,12 +131,18 @@ module BulkOps
126
131
  end
127
132
 
128
133
  def verify_remote_urls
129
- get_spreadsheet.each do |row, row_num|
134
+ row_offset = BulkOps::GithubAccess::ROW_OFFSET.present? ? BulkOps::GithubAccess::ROW_OFFSET : 2
135
+ get_spreadsheet.each_with_index do |row, row_num|
136
+ update(message: "verifying controlled vocab urls (row number #{row_num})")
137
+ next if row_num.nil?
130
138
  schema.controlled_field_names.each do |controlled_field_name|
131
- next unless (url = row[controlled_field_name])
132
- label = ::WorkIndexer.fetch_remote_label(url)
133
- if !label || label.blank?
134
- @verification_errors << BulkOps::Error.new({type: :cannot_retrieve_label, row: row_num + ROW_OFFSET, field: controlled_field_name, url: url})
139
+ next unless (urls = row[controlled_field_name])
140
+ urls.split(';').each do |url|
141
+ label = ::WorkIndexer.fetch_remote_label(url)
142
+ # if we can't get the label, and we aren't going to add a local label, throw an error
143
+ if (!label || label.blank?) && !schema.get_field(controlled_field_name).vocabularies.any?{|vocab| vocab["authority"].to_s.downcase == "local"}
144
+ @verification_errors << BulkOps::Error.new({type: :cannot_retrieve_label, row_number: row_num + row_offset, field: controlled_field_name, url: url})
145
+ end
135
146
  end
136
147
  end
137
148
  end
@@ -148,7 +159,6 @@ module BulkOps
148
159
  end
149
160
  end
150
161
 
151
-
152
162
  def verify_works_to_update
153
163
  return [] unless operation_type == "update"
154
164
  get_spreadsheet.each_with_index do |row, row_num|
@@ -7,17 +7,17 @@ class BulkOps::VerificationJob < ActiveJob::Base
7
7
 
8
8
  queue_as :default
9
9
 
10
- def perform(operation)
11
-
12
- if operation.verify
13
- operation.set_stage "authorize"
14
- if operation.create_pull_request
15
- operation.notify(subject: "Bulk Operation Verification Successful", message: "Your bulk ingest has passed verification, and we have requested to start applying the operation. It may required one final approval from an administrator before the operation proceeds.")
16
- else
17
- operation.notify(subject: "Bulk Operation - Error creating Github pull request", message: "Your bulk ingest has passed verification, but we had a problem creating a pull request on Github in order to merge this operation with the master branch. Please check your github configuration.")
18
- end
10
+ def perform(operation_id)
11
+ operation = BulkOps::Operation.find(operation_id)
12
+ if operation.verify
13
+ operation.set_stage "authorize"
14
+ if operation.create_pull_request
15
+ operation.notify(subject: "Bulk Operation Verification Successful", message: "Your bulk ingest has passed verification, and we have requested to start applying the operation. It may required one final approval from an administrator before the operation proceeds.")
19
16
  else
20
- operation.set_stage "pending"
17
+ operation.notify(subject: "Bulk Operation - Error creating Github pull request", message: "Your bulk ingest has passed verification, but we had a problem creating a pull request on Github in order to merge this operation with the master branch. Please check your github configuration.")
21
18
  end
19
+ else
20
+ operation.set_stage "pending"
21
+ end
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module BulkOps
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -111,7 +111,7 @@ class BulkOps::WorkProxy < ActiveRecord::Base
111
111
  def split_values value_string
112
112
  # Split values on all un-escaped separator character (escape character is '\')
113
113
  # Then replace all escaped separator charactors with un-escaped versions
114
- value_string.split(/(?<!\\)#{SEPARATOR}/).map{|val| val.gsub("\\#{SEPARATOR}",SEPARATOR)}
114
+ value_string.split(/(?<!\\)#{SEPARATOR}/).map{|val| val.gsub("\\#{SEPARATOR}",SEPARATOR).strip}
115
115
  end
116
116
 
117
117
  def interpret_controlled_fields raw_data
@@ -154,11 +154,14 @@ class BulkOps::WorkProxy < ActiveRecord::Base
154
154
 
155
155
  remove = field_name.downcase.starts_with?("remove") || field_name.downcase.starts_with?("delete")
156
156
 
157
+
157
158
  # handle multiple values
158
- split_values(value).each do |value|
159
-
159
+ value_array = split_values(value)
160
+ controlled_data[field_name_norm] ||= [] unless value_array.blank?
161
+ value_array.each do |value|
160
162
  # Decide of we're dealing with a label or url
161
163
  # It's an ID if it's a URL and the name doesn't end in 'label'
164
+ value.strip!
162
165
  if value =~ /^#{URI::regexp}$/ and !field_name.downcase.ends_with?("label")
163
166
  id = value
164
167
  label = WorkIndexer.fetch_remote_label(value)
@@ -173,37 +176,21 @@ class BulkOps::WorkProxy < ActiveRecord::Base
173
176
  url: value,
174
177
  row_number: row_number) unless id
175
178
  end
176
- (controlled_data[field_name_norm] ||= []) << {id: id, label: label, remove: field_name.downcase.starts_with?("remove")}
179
+ controlled_data[field_name_norm] << {id: id, label: label, remove: field_name.downcase.starts_with?("remove")}
177
180
  end
178
181
  end
179
182
 
180
183
  #delete any duplicates (if someone listed a url and also its label, or the same url twice)
181
184
  controlled_data.each{|field_name, values| controlled_data[field_name] = values.uniq }
182
-
183
- if operation.options["compare_labels"]
184
- controlled_data.each do |field_name,values|
185
- unless labels['field'].count == values.count
186
- report_error(:mismatched_auth_terms,
187
- message: "Different numbers of labels and ids for #{field}",
188
- row_number: row_number)
189
- end
190
- end
191
- labels['field'].each do |label|
192
- next if controlled_data.any?{|dt| dt["label"] == label}
193
- report_error(:mismatched_auth_terms,
194
- message: "There are controlled vocab term labels that no provided URL resolves to, in the field #{field}.",
195
- row_number: row_number)
196
- end
197
- end
198
-
185
+
199
186
  # Actually add all the data
200
187
  metadata = {}
201
188
  leftover_data = raw_data.dup.to_hash
202
189
  controlled_data.each do |property_name, data|
190
+ metadata["#{property_name}_attributes"] ||= [] unless data.blank?
203
191
  data.each do |datum|
204
192
  atts = {"id" => datum[:id]}
205
193
  atts["_delete"] = true if datum[:remove]
206
- metadata["#{property_name}_attributes"] ||= []
207
194
  metadata["#{property_name}_attributes"] << atts
208
195
  leftover_data.except! property_name
209
196
  end
@@ -382,7 +369,8 @@ class BulkOps::WorkProxy < ActiveRecord::Base
382
369
  end
383
370
  end
384
371
 
385
- def mintLocalAuthUrl(auth_name, value)
372
+ def mintLocalAuthUrl(auth_name, value)
373
+ value.strip!
386
374
  id = value.parameterize
387
375
  auth = Qa::LocalAuthority.find_or_create_by(name: auth_name)
388
376
  entry = Qa::LocalAuthorityEntry.create(local_authority: auth,
@@ -392,22 +380,25 @@ class BulkOps::WorkProxy < ActiveRecord::Base
392
380
  end
393
381
 
394
382
  def findAuthUrl(auth, value)
383
+ value.strip!
395
384
  return nil if auth.nil?
396
385
  return nil unless (entries = Qa::Authorities::Local.subauthority_for(auth).search(value))
397
386
  entries.each do |entry|
398
387
  #require exact match
399
- if entry["label"] == value
400
- url = entry["url"]
401
- url ||= entry["id"]
402
- url = localIdToUrl(url,auth) unless url =~ URI::regexp
403
- return url
404
- end
388
+ next unless entry["label"] == value
389
+ url = entry["url"]
390
+ url ||= entry["id"]
391
+ url = localIdToUrl(url,auth) unless url =~ URI::regexp
392
+ return url
405
393
  end
406
394
  return nil
407
395
  end
408
396
 
409
397
  def localIdToUrl(id,auth_name)
410
- return "https://digitalcollections.library.ucsc.edu/authorities/show/local/#{auth_name}/#{id}"
398
+ hostname = Socket.gethostname
399
+ hostname = "localhost" unless hostname.include?(',')
400
+ protocol = (Rails.env == "production") ? "https" : "http"
401
+ return "#{protocol}://#{hostname}/authorities/show/local/#{auth_name}/#{id}"
411
402
  end
412
403
 
413
404
  def getLocalAuth(field_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ned Henry, UCSC Library Digital Initiatives
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-02 00:00:00.000000000 Z
11
+ date: 2019-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails