bulk_ops 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20181017180436_create_bulk_ops_tables.rb +1 -0
- data/lib/bulk_ops/error.rb +10 -8
- data/lib/bulk_ops/operation.rb +12 -3
- data/lib/bulk_ops/queue_work_ingests_job.rb +21 -0
- data/lib/bulk_ops/relationship.rb +44 -12
- data/lib/bulk_ops/verification.rb +1 -1
- data/lib/bulk_ops/version.rb +1 -1
- data/lib/bulk_ops/work_job.rb +24 -25
- data/lib/bulk_ops/work_proxy.rb +74 -35
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5769c63fe85e0a97a16da3f147f2788af3ce5114ac84fd9ea1e3078f187ce11
|
4
|
+
data.tar.gz: 6164cafacea7e4f88cb39464ad2cf19cd38268f63cf4fdccda6f0bee35cc3515
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e93c25e5bf47b3d9230b78b42695871bb4c7905270c9f9eeda92e459f030e4a74cc32e5a362e2224a1817ee0dd3f639b36aa573032d90cea00aaf0c3b4c9717a
|
7
|
+
data.tar.gz: 307ad0126fd62baa1a21b7f0ca5073c0847a27435a0665955aa3df68df24a28b85b96396ba01ef966e82d9b218e6b728ef46cd03ec8bcfbb369b18c56d24d32e
|
data/lib/bulk_ops/error.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class BulkOps::Error
|
2
2
|
attr_accessor :type, :row_number, :object_id, :message, :option_name, :file, :option_values, :field, :url
|
3
3
|
|
4
|
-
MAX_ERROR =
|
4
|
+
MAX_ERROR = 5000
|
5
|
+
MAX_ERROR_SHORT = 50
|
5
6
|
|
6
7
|
def initialize type:, row_number: nil, object_id: nil, message: nil, options_name: nil, option_values: nil, field: nil, url: nil , file: nil
|
7
8
|
@type = type
|
@@ -39,12 +40,13 @@ class BulkOps::Error
|
|
39
40
|
return error_file_name
|
40
41
|
end
|
41
42
|
|
42
|
-
def self.error_message type, errors
|
43
|
+
def self.error_message type, errors, short=false
|
44
|
+
max_error = short ? MAX_ERROR_SHORT : MAX_ERROR
|
43
45
|
case type
|
44
46
|
when :mismatched_auth_terms
|
45
47
|
message = "\n-- Controlled Authority IDs and Labels don't match -- \n"
|
46
48
|
message += "The operation is set to create an error if the provided URLs for controlled authority terms do not resolve to the provided labels.\n"
|
47
|
-
if errors.count <
|
49
|
+
if errors.count < max_error
|
48
50
|
message += "The following rows were affected:\n"
|
49
51
|
message += errors.map{|error| error.row_number}.join(",")+"\n"
|
50
52
|
else
|
@@ -53,7 +55,7 @@ class BulkOps::Error
|
|
53
55
|
when :upload_error
|
54
56
|
message = "\n-- Errors uploading files -- \n"
|
55
57
|
message += "Your files looked ok when we checked earlier, but we couldn't access them when we were trying to actually start the operation.\n"
|
56
|
-
if errors.count <
|
58
|
+
if errors.count < max_error
|
57
59
|
message += "The following files were affected:\n"
|
58
60
|
message += errors.map{|error| "Row #{row_number}, Filename: #{error.file}"}.join("\n")+"\n"
|
59
61
|
else
|
@@ -90,7 +92,7 @@ class BulkOps::Error
|
|
90
92
|
when :cannot_retrieve_label
|
91
93
|
message = "\n-- Errors Retrieving Remote Labels --\n"
|
92
94
|
urls = errors.map{|error| error.url}.uniq
|
93
|
-
if urls.count <
|
95
|
+
if urls.count < max_error
|
94
96
|
urls.each do |url|
|
95
97
|
url_errors = errors.select{|er| er.url == url}
|
96
98
|
message += "Error retrieving label for remote url #{url}. \nThis url appears in #{url_errors.count} instances in the spreadsheet.\n"
|
@@ -104,7 +106,7 @@ class BulkOps::Error
|
|
104
106
|
when :cannot_retrieve_url
|
105
107
|
message = "\n-- Errors Retrieving Remote URLs --\n"
|
106
108
|
urls = errors.map{|error| error.url}.uniq
|
107
|
-
if urls.count <
|
109
|
+
if urls.count < max_error
|
108
110
|
urls.each do |url|
|
109
111
|
url_errors = errors.select{|er| er.url == url}
|
110
112
|
message += "Error retrieving URL for remote authority term #{url}. \nThis term appears in #{url_errors.count} instances in the spreadsheet.\n"
|
@@ -118,7 +120,7 @@ class BulkOps::Error
|
|
118
120
|
when :bad_object_reference
|
119
121
|
message = "\n-- Error: bad object reference --\m"
|
120
122
|
message += "We enountered #{errors.count} problems resolving object references.\n"
|
121
|
-
if errors.count <
|
123
|
+
if errors.count < max_error
|
122
124
|
message += "The row numbers with problems were:\n"
|
123
125
|
message += errors.map{|er| "row number #{er.row_number} references the object #{er.object_id}"}.join("\n")
|
124
126
|
else
|
@@ -128,7 +130,7 @@ class BulkOps::Error
|
|
128
130
|
when :cannot_find_file
|
129
131
|
message = "\n-- Missing File Errors --\n "
|
130
132
|
message += "We couldn't find the files listed on #{errors.count} rows.\n"
|
131
|
-
if errors.count <
|
133
|
+
if errors.count < max_error
|
132
134
|
message += "Missing filenames:\n"
|
133
135
|
message += errors.map{|er| er.file}.join("\n")
|
134
136
|
else
|
data/lib/bulk_ops/operation.rb
CHANGED
@@ -141,12 +141,21 @@ module BulkOps
|
|
141
141
|
def check_if_finished
|
142
142
|
return unless stage == "running" && !busy?
|
143
143
|
|
144
|
+
update(stage: "finishing")
|
145
|
+
|
144
146
|
# Attempt to resolve each dangling (objectless) relationships
|
145
147
|
BulkOps::Relationship.where(:status => "pending").each do |relationship|
|
146
|
-
relationship.resolve!
|
148
|
+
relationship.resolve! if relationship.work_proxy.operation_id == id
|
149
|
+
end
|
150
|
+
|
151
|
+
work_proxies.each do |proxy|
|
152
|
+
wrk = Work.find(proxy.work_id)
|
153
|
+
wrk.save if wrk.members.any?{|mem| mem.class.to_s !== "FileSet"}
|
154
|
+
sd = SolrDocument.find(wrk.id)
|
155
|
+
wrk.save if sd['hasRelatedImage_ssim'].present? && sd['relatedImageId_ss'].blank?
|
147
156
|
end
|
148
157
|
|
149
|
-
update(stage: accumulated_errors.blank? ? "complete" : "errors" )
|
158
|
+
update(stage: (accumulated_errors.blank? ? "complete" : "errors" ))
|
150
159
|
report_errors!
|
151
160
|
lift_holds
|
152
161
|
end
|
@@ -272,7 +281,7 @@ module BulkOps
|
|
272
281
|
def options
|
273
282
|
return {} if name.nil?
|
274
283
|
return @options if @options
|
275
|
-
branch = running? ? "master" : nil
|
284
|
+
branch = (running? || complete?) ? "master" : nil
|
276
285
|
@options ||= git.load_options(branch: branch)
|
277
286
|
end
|
278
287
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class BulkOps::QueueWorkIngestsJob < ActiveJob::Base
|
2
|
+
attr_accessor :operation
|
3
|
+
|
4
|
+
queue_as :ingest
|
5
|
+
|
6
|
+
def perform(op)
|
7
|
+
@operation = op
|
8
|
+
metadata = op.final_spreadsheet
|
9
|
+
op.work_proxies.where(status:'queued').each do |proxy|
|
10
|
+
data = proxy.interpret_data(metadata[proxy.row_number])
|
11
|
+
next unless proxy.proxy_errors.blank?
|
12
|
+
proxy.update(status: 'sidekiq', message: "interpreted at #{DateTime.now.strftime("%d/%m/%Y %H:%M")} " + proxy.message)
|
13
|
+
BulkOps::CreateWorkJob.perform_later(proxy.work_type || "Work",
|
14
|
+
op.user.email,
|
15
|
+
data,
|
16
|
+
proxy.id,
|
17
|
+
proxy.visibility)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -3,6 +3,7 @@ class BulkOps::Relationship < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
self.table_name = "bulk_ops_relationships"
|
5
5
|
belongs_to :work_proxy, class_name: "BulkOps::WorkProxy", foreign_key: "work_proxy_id"
|
6
|
+
delegate :operation, :operation_id, to: :work_proxy
|
6
7
|
|
7
8
|
def initialize *args
|
8
9
|
super *args
|
@@ -13,7 +14,7 @@ class BulkOps::Relationship < ActiveRecord::Base
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def findObject
|
16
|
-
case identifier_type
|
17
|
+
case identifier_type.downcase
|
17
18
|
when "id"
|
18
19
|
begin
|
19
20
|
object = ActiveFedora::Base.find(object_identifier)
|
@@ -25,7 +26,7 @@ class BulkOps::Relationship < ActiveRecord::Base
|
|
25
26
|
# TODO clean up solr query and add work type to it
|
26
27
|
query = "{!field f=title_tesim}#{object_identifier}"
|
27
28
|
objects = ActiveFedora::SolrService.instance.conn.get(ActiveFedora::SolrService.select_path,
|
28
|
-
params: { fq: query, rows: 100})["response"]["docs"]
|
29
|
+
params: { fq: query, rows: 100})["response"]["docs"]
|
29
30
|
if objects.present?
|
30
31
|
return ActiveFedora::Base.find(objects.first["id"])
|
31
32
|
elsif relationship_type.downcase == "collection"
|
@@ -39,9 +40,13 @@ class BulkOps::Relationship < ActiveRecord::Base
|
|
39
40
|
return false if objects.blank?
|
40
41
|
return ActiveFedora::Base.find(objects.first["id"])
|
41
42
|
when "row"
|
42
|
-
object_proxy = BulkOps::WorkProxy.find_by(operation_id: work_proxy.
|
43
|
+
object_proxy = BulkOps::WorkProxy.find_by(operation_id: work_proxy.operation_id,
|
43
44
|
row_number: (object_identifier.to_i - 2))
|
44
45
|
ActiveFedora::Base.find(object_proxy.work_id)
|
46
|
+
when "proxy_id"
|
47
|
+
return false unless (proxy = BulkOps::WorkProxy.find(proxy_id))
|
48
|
+
return false unless proxy.work_id.present?
|
49
|
+
ActiveFedora::Base.find(proxy.work_id)
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
@@ -52,20 +57,47 @@ class BulkOps::Relationship < ActiveRecord::Base
|
|
52
57
|
end
|
53
58
|
implement_relationship! relationship_type, subject, object
|
54
59
|
end
|
60
|
+
|
61
|
+
def insert_among_siblings(object,new_member)
|
62
|
+
return nil unless ["parent"].include?(relationship_type.downcase)
|
63
|
+
prev_sib_id = previous_sibling
|
64
|
+
# This is the id of the WorkProxy associate with the most recent sibling work
|
65
|
+
# that might be fully ingested. If is it not fully ingested, we will move on
|
66
|
+
# to the preceding sibling.
|
67
|
+
while prev_sib_id.present?
|
68
|
+
prev_sib_proxy = BulkOps::WorkProxy.find(previous_sibling)
|
69
|
+
# Check if the previous sibling is fully ingested
|
70
|
+
# and get its index among its siblings (if it has been successfully attached to the parent)
|
71
|
+
prev_sib_index = object.ordered_member_ids.index(prev_sib_proxy.work_id) if prev_sib_proxy.work_id.present? # Insert the new member among its siblings if we found the right place
|
72
|
+
return object.ordered_members.to_a.insert(prev_sib_index+1, new_member) if prev_sib_index.present?
|
73
|
+
# Otherwise, pull up the sibling's relationship field to check if it sibling has a sibling before it
|
74
|
+
sib_relationship = prev_sib_proxy.relationships.find_by(relationship_type: relationship_type, object_identifier: object_identifier)
|
75
|
+
# If we can't find an ingested sibling among the ordered members,
|
76
|
+
# make this work the first member.
|
77
|
+
break unless sib_relationship.present?
|
78
|
+
prev_sib_id = sib_relationship.previous_sibling
|
79
|
+
end
|
80
|
+
return [new_member]+ordered_members.to_a
|
81
|
+
end
|
55
82
|
|
56
83
|
def implement_relationship!(type,subject,object)
|
57
|
-
case type
|
84
|
+
case type.downcase
|
58
85
|
when "parent"
|
59
|
-
object.
|
60
|
-
|
86
|
+
unless object.member_ids.include? subject.id
|
87
|
+
object.ordered_members = insert_among_siblings(object, new_member)
|
88
|
+
object.save
|
89
|
+
end
|
61
90
|
when "child"
|
62
|
-
|
63
|
-
subject.
|
91
|
+
#CAVEAT ordering not fully implemented in this case
|
92
|
+
unless subject.member_ids.include? object.id
|
93
|
+
subject.ordered_members << object
|
94
|
+
subject.save
|
95
|
+
end
|
64
96
|
when "collection"
|
65
|
-
object.
|
66
|
-
|
67
|
-
|
68
|
-
|
97
|
+
unless object.member_object_ids.include? subject.id
|
98
|
+
object.add_members([subject.id])
|
99
|
+
object.save
|
100
|
+
end
|
69
101
|
when "order"
|
70
102
|
#TODO - implement this - related to ordering of filesets
|
71
103
|
|
@@ -200,7 +200,7 @@ module BulkOps
|
|
200
200
|
if ref_id == "row" || (ref_id == "id/row" && obj_id.is_a?(Integer))
|
201
201
|
obj_id = obj_id.to_i
|
202
202
|
# This is a row number reference. It should be an integer in the range of possible row numbers.
|
203
|
-
unless obj_id.present?(obj_id > 0) && (obj_id <= metadata.count)
|
203
|
+
unless obj_id.present? && (obj_id > 0) && (obj_id <= metadata.count)
|
204
204
|
@verification_errors << BulkOps::Error.new({type: :bad_object_reference, object_id: obj_id, row_number: row_num + ROW_OFFSET})
|
205
205
|
end
|
206
206
|
elsif ref_id == "id" || ref_id == "hyrax id" || (ref_id == "id/row" && (obj_id.is_a? Integer))
|
data/lib/bulk_ops/version.rb
CHANGED
data/lib/bulk_ops/work_job.rb
CHANGED
@@ -9,42 +9,40 @@ class BulkOps::WorkJob < ActiveJob::Base
|
|
9
9
|
after_perform do |job|
|
10
10
|
|
11
11
|
# update BulkOperationsWorkProxy status
|
12
|
-
@work
|
13
|
-
|
14
|
-
status = "error"
|
12
|
+
if @work.nil? || @work.id.nil?
|
13
|
+
update_status "error"
|
15
14
|
else
|
16
15
|
@work_proxy.work_id = @work.id
|
17
|
-
|
18
|
-
end
|
19
|
-
update_status status
|
16
|
+
update_status "complete"
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
# Attempt to resolve all of the relationships defined in this row
|
19
|
+
@work_proxy.relationships.each do |relationship|
|
20
|
+
relationship.resolve!
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
# Delete any UploadedFiles. These take up tons of unnecessary disk space.
|
24
|
+
@work.file_sets.each do |fileset|
|
25
|
+
if uf = Hyrax::UploadedFile.find_by(file: fileset.label)
|
26
|
+
uf.destroy!
|
27
|
+
end
|
30
28
|
end
|
31
|
-
end
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
# Remove any edit holds placed on an item
|
31
|
+
@work_proxy.lift_hold
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
# Check if the parent operation is finished
|
34
|
+
# and do any cleanup if so
|
35
|
+
if @work_proxy.operation.present? && @work_proxy.operation.respond_to?(:check_if_finished)
|
36
|
+
@work_proxy.operation.check_if_finished
|
37
|
+
end
|
38
|
+
end
|
42
39
|
end
|
43
40
|
|
44
41
|
def perform(workClass,user_email,attributes,work_proxy_id,visibility=nil)
|
45
42
|
return if status == "complete"
|
46
43
|
update_status "starting", "Initializing the job"
|
47
44
|
attributes['visibility']= visibility if visibility.present?
|
45
|
+
attributes['title'] = ['Untitled'] if attributes['title'].blank?
|
48
46
|
@work_proxy = BulkOps::WorkProxy.find(work_proxy_id)
|
49
47
|
unless @work_proxy
|
50
48
|
report_error("Cannot find work proxy with id: #{work_proxy_id}")
|
@@ -79,9 +77,10 @@ class BulkOps::WorkJob < ActiveJob::Base
|
|
79
77
|
:create
|
80
78
|
end
|
81
79
|
|
82
|
-
def update_status
|
80
|
+
def update_status stat, message=false
|
81
|
+
@status = stat
|
83
82
|
return false unless @work_proxy
|
84
|
-
atts = {status:
|
83
|
+
atts = {status: stat}
|
85
84
|
atts[:message] = message if message
|
86
85
|
@work_proxy.update(atts)
|
87
86
|
end
|
data/lib/bulk_ops/work_proxy.rb
CHANGED
@@ -2,7 +2,7 @@ class BulkOps::WorkProxy < ActiveRecord::Base
|
|
2
2
|
|
3
3
|
require 'uri'
|
4
4
|
OPTION_FIELDS = ['visibility','work type']
|
5
|
-
RELATIONSHIP_FIELDS = ['parent','child','collection','
|
5
|
+
RELATIONSHIP_FIELDS = ['parent','child','collection','order']
|
6
6
|
REFERENCE_IDENTIFIER_FIELDS = ['Reference Identifier','ref_id','Reference ID','Relationship ID','Relationship Identifier','Reference Identifier Type','Reference ID Type','Ref ID Type','relationship_identifier_type','relationship_id_type']
|
7
7
|
FILE_FIELDS = ['file','files','filename','filenames']
|
8
8
|
FILE_ACTIONS = ['add','upload','remove','delete']
|
@@ -49,6 +49,7 @@ class BulkOps::WorkProxy < ActiveRecord::Base
|
|
49
49
|
metadata.merge! interpret_relationship_fields(raw_data )
|
50
50
|
metadata.merge! interpret_option_fields(raw_data)
|
51
51
|
metadata = setAdminSet(metadata)
|
52
|
+
metadata = setMetadataInheritance(metadata)
|
52
53
|
return metadata
|
53
54
|
end
|
54
55
|
|
@@ -208,7 +209,7 @@ class BulkOps::WorkProxy < ActiveRecord::Base
|
|
208
209
|
field = schema.get_field(field_name)
|
209
210
|
# Ignore controlled fields
|
210
211
|
next if field.controlled?
|
211
|
-
values
|
212
|
+
split_values(values).each do |value|
|
212
213
|
next if value.blank?
|
213
214
|
value = value.strip.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_') unless value.blank?
|
214
215
|
value = unescape_csv(value)
|
@@ -292,62 +293,94 @@ class BulkOps::WorkProxy < ActiveRecord::Base
|
|
292
293
|
return {}
|
293
294
|
end
|
294
295
|
|
295
|
-
def interpret_relationship_fields raw_data
|
296
|
+
def interpret_relationship_fields raw_data, row_number=nil
|
296
297
|
metadata = {}
|
297
|
-
raw_data
|
298
|
+
raw_data do |field,value|
|
298
299
|
next if value.blank? or field.blank?
|
299
300
|
field = field.to_s
|
300
301
|
value = unescape_csv(value)
|
302
|
+
identifer_type = reference_identifier
|
301
303
|
|
302
304
|
next if value == field
|
303
305
|
|
304
306
|
if (split = field.split(":")).count == 2
|
305
|
-
|
306
|
-
field = split.
|
307
|
+
identifier_type = split.last
|
308
|
+
field = split.first.to_s
|
307
309
|
end
|
308
310
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
if ["collection","collectiontitle","memberofcollection","collectionname", "collectionid"].include?(normfield)
|
311
|
+
relationship_type = normalize_relationship_field_name(field)
|
312
|
+
case relationship_type
|
313
|
+
when "order"
|
314
|
+
# If the field specifies the object's order among siblings (usually for multiple filesets)
|
315
|
+
update(order: value.to_f)
|
316
|
+
when "collection"
|
317
|
+
# If the field specifies the name or ID of a collection,
|
318
|
+
# find or create the collection and update the metadata to match
|
318
319
|
col = find_or_create_collection(value)
|
319
320
|
( metadata[:member_of_collection_ids] ||= [] ) << col.id if col
|
321
|
+
when "parent", "child"
|
322
|
+
object_id = interpret_relationship_value(value,identifier_type)
|
320
323
|
end
|
321
|
-
|
322
|
-
# All variations of field names that require BulkOps::Relationship objects
|
323
|
-
next unless ["parent","parentid","parentidentifier","parentwork","child","childid","childidentifier","childwork","next","nextfile","nextwork","nextid","nextfileidentifier","nextfileid","nextworkid"].include?(normfield)
|
324
324
|
|
325
|
-
# find which type of relationship
|
326
|
-
["parent","child","next"].select{|type| normfield.include?(type)}.first
|
327
325
|
# correctly interpret the notation "id:a78C2d81"
|
328
326
|
if ((split = value.split(":")).count == 2)
|
329
|
-
|
327
|
+
identifier_type = split.first
|
330
328
|
value = split.last
|
331
329
|
end
|
332
|
-
|
333
|
-
|
330
|
+
|
331
|
+
interpret_relationship_value(identifier_type, value)
|
332
|
+
|
333
|
+
relationship_parameters = { work_proxy_id: id,
|
334
|
+
identifier_type: ref_type,
|
334
335
|
relationship_type: normfield,
|
335
336
|
object_identifier: value,
|
336
|
-
status: "new"}
|
337
|
+
status: "new"}
|
338
|
+
|
339
|
+
#add previous sibling link if necessary
|
340
|
+
previous_value = op.metadata[row_number-1][field]
|
341
|
+
if previous_value.present? && (ref_type == "parent")
|
342
|
+
if value == interpret_relationship_value(ref_type, previous_value)
|
343
|
+
relationship_parameters[:previous_sibling] = operation.work_proxies.find_by(row_number: row_number-1).id
|
344
|
+
end
|
345
|
+
end
|
346
|
+
BulkOps::Relationship.create(relationship_parameters)
|
337
347
|
end
|
338
348
|
return metadata
|
339
349
|
end
|
340
350
|
|
341
|
-
def
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
+
def normalize_relationship_field_name field
|
352
|
+
normfield = field.downcase.parameterize.gsub(/[_\s-]/,'')
|
353
|
+
RELATIONSHIP_FIELDS.find{|field| normfield.include?(field) }
|
354
|
+
end
|
355
|
+
|
356
|
+
def find_previous_parent field
|
357
|
+
i = 0;
|
358
|
+
while (prev_row = operation.metadata[row_number - i])
|
359
|
+
return (row_number - i) if prev_row[field].blank?
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def find_previous_sibling (field,ref_type,object)
|
364
|
+
previous_value = interpret_relationship_value(ref_type,op.metadata[row_number-1][field])
|
365
|
+
return nil unless previous_value == object
|
366
|
+
return
|
367
|
+
end
|
368
|
+
|
369
|
+
def interpret_relationship_value id_type, value, field="parent"
|
370
|
+
#Handle "id:20kj4259" syntax if it hasn't already been handled
|
371
|
+
if (split = value.to_s.split(":")).count == 2
|
372
|
+
id_type = split.first
|
373
|
+
value = split.last
|
374
|
+
end
|
375
|
+
#Handle special shorthand syntax for refering to relative row numbers
|
376
|
+
if id_type == "row"
|
377
|
+
if value.to_i < 0
|
378
|
+
# if given a negative integer, count backwards from the current row
|
379
|
+
return row_number - value
|
380
|
+
elsif value.to_s.downcase.include?("prev")
|
381
|
+
# if given any variation of the word "previous", get the first preceding row with no parent of its own
|
382
|
+
return find_previous_parent(field)
|
383
|
+
end
|
351
384
|
end
|
352
385
|
end
|
353
386
|
|
@@ -422,7 +455,13 @@ class BulkOps::WorkProxy < ActiveRecord::Base
|
|
422
455
|
return metadata if metadata[:admin_set_id]
|
423
456
|
asets = AdminSet.where({title: "Bulk Ingest Set"})
|
424
457
|
asets = AdminSet.find('admin_set/default') if asets.blank?
|
425
|
-
metadata[:admin_set_id] = asets.first.id unless asets.blank?
|
458
|
+
metadata[:admin_set_id] = Array(asets).first.id unless asets.blank?
|
459
|
+
return metadata
|
460
|
+
end
|
461
|
+
|
462
|
+
def setMetadataInheritance metadata
|
463
|
+
return metadata if metadata[:metadataInheritance].present?
|
464
|
+
metadata[:metadataInheritance] = operation.options["metadataInheritance"] unless operation.options["metadataInheritance"].blank?
|
426
465
|
return metadata
|
427
466
|
end
|
428
467
|
|
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
|
+
version: 0.1.12
|
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-
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/bulk_ops/github_access.rb
|
107
107
|
- lib/bulk_ops/github_credential.rb
|
108
108
|
- lib/bulk_ops/operation.rb
|
109
|
+
- lib/bulk_ops/queue_work_ingests_job.rb
|
109
110
|
- lib/bulk_ops/relationship.rb
|
110
111
|
- lib/bulk_ops/search_builder_behavior.rb
|
111
112
|
- lib/bulk_ops/templates/configuration.yml
|