bulk_ops 0.1.13 → 0.1.14

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: b118e0e6b4039a3fff3174e553faaa05c447c09b08c3ea5ad013ba8922b09084
4
- data.tar.gz: d27b01baf50a45da61d1131f8a84a61bd0b2db6bbfd23742a49b508e55cdecd3
3
+ metadata.gz: 27b9b67583cbf4ca808867661196e5bb8a6b95490b3a377dd85d11a91d0a41fb
4
+ data.tar.gz: 508dbf4a72146f7a893851aec847bb9bb82a399765135dfde6daa6eec0a4d121
5
5
  SHA512:
6
- metadata.gz: 75b9f53d064c5cdef7044c7b727fe36d2ccd1fcfb50bf522b5c45375fb7c6f548a9fbe1bc88ef4cfe757dac1f44af4d4b2d503246a98b65891883c1e08d1dc75
7
- data.tar.gz: 32faf9307eb850f7a306d7e3c9c088b53faf63fd9a25578c04b6facdcb6647eca0fb38c26253c078772d2e49715e559a7b3bc655fa349791dbf33b6070edded1
6
+ metadata.gz: da715c7235ae2044b2354653b382825078a63f466e542642d995c81b6dd3bb8d8336c13ac84dd811ecefbff4e9e2422c45f1dc39e10b0ea1a4119a6736397ee2
7
+ data.tar.gz: 9bd37e6481170e1da5ba4494888fb16a1cfa65cc9869edcee87353228a1eb78eefe5f32c87bb7c14f4fc2b6e3ead0ad068901273d8c100e3afbce0d5268e4486
@@ -10,11 +10,11 @@ class BulkOps::Relationship < ActiveRecord::Base
10
10
 
11
11
  # Attempt to resolve the relationship immediately
12
12
  # which might work in the case of updates
13
- resolve!
13
+ # resolve!
14
14
  end
15
15
 
16
16
  def findObject
17
- case identifier_type.downcase
17
+ case (identifier_type || "").downcase
18
18
  when "id"
19
19
  begin
20
20
  object = ActiveFedora::Base.find(object_identifier)
@@ -29,7 +29,7 @@ class BulkOps::Relationship < ActiveRecord::Base
29
29
  params: { fq: query, rows: 100})["response"]["docs"]
30
30
  if objects.present?
31
31
  return ActiveFedora::Base.find(objects.first["id"])
32
- elsif relationship_type.downcase == "collection"
32
+ elsif (relationship_type || "").downcase == "collection"
33
33
  return Collection.create(title: [object_identifier])
34
34
  else
35
35
  return false
@@ -59,22 +59,22 @@ class BulkOps::Relationship < ActiveRecord::Base
59
59
  end
60
60
 
61
61
  def insert_among_children(object,new_member)
62
- return nil unless ["parent"].include?(relationship_type.downcase)
62
+ return nil unless ["parent"].include?((relationship_type || "").downcase)
63
63
  prev_sib_id = previous_sibling
64
64
  # This is the id of the WorkProxy associate with the most recent sibling work
65
65
  # that might be fully ingested. If is it not fully ingested, we will move on
66
66
  # to the preceding sibling.
67
67
  while prev_sib_id.present?
68
- prev_sib_proxy = BulkOps::WorkProxy.find(previous_sibling)
68
+ prev_sib_proxy = BulkOps::WorkProxy.find(prev_sib_id)
69
69
  # Check if the previous sibling is fully ingested
70
70
  # and get its index among its siblings (if it has been successfully attached to the parent)
71
71
  prev_sib_index = object.ordered_member_ids.index(prev_sib_proxy.work_id) if prev_sib_proxy.work_id.present?
72
72
  # Insert the new member among its siblings if we found the right place
73
73
  return object.ordered_members.to_a.insert(prev_sib_index+1, new_member) if prev_sib_index.present?
74
74
  # Otherwise, pull up the sibling's relationship field to check if it sibling has a sibling before it
75
- sib_relationship = prev_sib_proxy.relationships.find_by(relationship_type: relationship_type, object_identifier: object_identifier)
75
+ sib_relationship = prev_sib_proxy.relationships.find{|rel| rel.findObject.id == object.id }
76
76
  # If we can't find an ingested sibling among the ordered members,
77
- # make this work the first member.
77
+ # break this loop and make this work the first member.
78
78
  break unless sib_relationship.present?
79
79
  prev_sib_id = sib_relationship.previous_sibling
80
80
  end
@@ -83,9 +83,11 @@ class BulkOps::Relationship < ActiveRecord::Base
83
83
  end
84
84
 
85
85
  def implement_relationship!(type,subject,object)
86
- case type.downcase
86
+ case (type || "").downcase
87
87
  when "parent"
88
88
  unless object.member_ids.include? subject.id
89
+ object.reload
90
+ object.save
89
91
  object.ordered_members = insert_among_children(object, subject)
90
92
  object.save
91
93
  end
@@ -95,11 +97,6 @@ class BulkOps::Relationship < ActiveRecord::Base
95
97
  subject.ordered_members << object
96
98
  subject.save
97
99
  end
98
- when "collection"
99
- unless object.member_object_ids.include? subject.id
100
- object.add_members([subject.id])
101
- object.save
102
- end
103
100
  when "order"
104
101
  #TODO - implement this - related to ordering of filesets
105
102
 
@@ -1,3 +1,3 @@
1
1
  module BulkOps
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
@@ -46,7 +46,7 @@ class BulkOps::WorkProxy < ActiveRecord::Base
46
46
  metadata.merge! interpret_file_fields(raw_data)
47
47
  metadata.merge! interpret_controlled_fields(raw_data)
48
48
  metadata.merge! interpret_scalar_fields(raw_data)
49
- metadata.merge! interpret_relationship_fields(raw_data )
49
+ metadata.merge! interpret_relationship_fields(raw_data)
50
50
  metadata.merge! interpret_option_fields(raw_data)
51
51
  metadata = setAdminSet(metadata)
52
52
  metadata = setMetadataInheritance(metadata)
@@ -293,9 +293,9 @@ class BulkOps::WorkProxy < ActiveRecord::Base
293
293
  return {}
294
294
  end
295
295
 
296
- def interpret_relationship_fields raw_data, row_number=nil
296
+ def interpret_relationship_fields(raw_data)
297
297
  metadata = {}
298
- raw_data do |field,value|
298
+ raw_data.each do |field,value|
299
299
  next if value.blank? or field.blank?
300
300
  field = field.to_s
301
301
  value = unescape_csv(value)
@@ -305,47 +305,49 @@ class BulkOps::WorkProxy < ActiveRecord::Base
305
305
 
306
306
  if (split = field.split(":")).count == 2
307
307
  identifier_type = split.last
308
- field = split.first.to_s
308
+ relationship_type = split.first.to_s
309
+ else
310
+ relationship_type = field
309
311
  end
310
312
 
311
- relationship_type = normalize_relationship_field_name(field)
313
+ relationship_type = normalize_relationship_field_name(relationship_type)
312
314
  case relationship_type
313
315
  when "order"
314
- # If the field specifies the object's order among siblings (usually for multiple filesets)
316
+ # If the field specifies the object's order among siblings
315
317
  update(order: value.to_f)
318
+ next
316
319
  when "collection"
317
320
  # If the field specifies the name or ID of a collection,
318
321
  # find or create the collection and update the metadata to match
319
322
  col = find_or_create_collection(value)
320
323
  ( metadata[:member_of_collection_ids] ||= [] ) << col.id if col
324
+ next
321
325
  when "parent", "child"
322
- object_id = interpret_relationship_value(value,identifier_type)
323
- end
324
-
325
- # correctly interpret the notation "id:a78C2d81"
326
- if ((split = value.split(":")).count == 2)
327
- identifier_type = split.first
328
- value = split.last
329
- end
330
-
331
- interpret_relationship_value(identifier_type, value)
332
-
333
- relationship_parameters = { work_proxy_id: id,
334
- identifier_type: ref_type,
335
- relationship_type: normfield,
336
- object_identifier: value,
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
326
+
327
+ # correctly interpret the notation "id:a78C2d81"
328
+ identifier_type, object_identifier = interpret_relationship_value(identifier_type, value)
329
+
330
+ relationship_parameters = { work_proxy_id: id,
331
+ identifier_type: identifier_type,
332
+ relationship_type: relationship_type,
333
+ object_identifier: object_identifier,
334
+ status: "new"}
335
+
336
+ #add previous sibling link if necessary
337
+ previous_value = operation.final_spreadsheet[row_number-1][field]
338
+ # Check if this is a parent relationship, and the previous row also has one
339
+ if previous_value.present? && (relationship_type == "parent")
340
+ # Check if the previous row has the same parent as this row
341
+ if object_identifier == interpret_relationship_value(identifier_type, previous_value, field).last
342
+ # If so, set the previous sibling parameter on the relationshp
343
+ # to the id for the proxy associated with the previous row
344
+ relationship_parameters[:previous_sibling] = operation.work_proxies.find_by(row_number: row_number-1).id
345
+ end
344
346
  end
347
+ BulkOps::Relationship.create(relationship_parameters)
345
348
  end
346
- BulkOps::Relationship.create(relationship_parameters)
349
+ return metadata
347
350
  end
348
- return metadata
349
351
  end
350
352
 
351
353
  def normalize_relationship_field_name field
@@ -353,19 +355,15 @@ class BulkOps::WorkProxy < ActiveRecord::Base
353
355
  RELATIONSHIP_FIELDS.find{|field| normfield.include?(field) }
354
356
  end
355
357
 
356
- def find_previous_parent field
358
+ def find_previous_parent field="parent"
359
+ #Return the row number of the most recent preceding row that does
360
+ # not itself have a parent defined
357
361
  i = 0;
358
- while (prev_row = operation.metadata[row_number - i])
362
+ while (prev_row = operation.final_spreadsheet[row_number - i])
359
363
  return (row_number - i) if prev_row[field].blank?
360
364
  end
361
365
  end
362
366
 
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
367
  def interpret_relationship_value id_type, value, field="parent"
370
368
  #Handle "id:20kj4259" syntax if it hasn't already been handled
371
369
  if (split = value.to_s.split(":")).count == 2
@@ -376,12 +374,13 @@ class BulkOps::WorkProxy < ActiveRecord::Base
376
374
  if id_type == "row"
377
375
  if value.to_i < 0
378
376
  # if given a negative integer, count backwards from the current row
379
- return row_number - value
377
+ return [id_type,row_number - value]
380
378
  elsif value.to_s.downcase.include?("prev")
381
379
  # 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)
380
+ return [id_type,find_previous_parent(field)]
383
381
  end
384
382
  end
383
+ return [id_type,value]
385
384
  end
386
385
 
387
386
  def unescape_csv(value)
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.13
4
+ version: 0.1.14
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-09-26 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails