bulkrax 3.0.0.beta4 → 3.0.0.beta5

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: 29702685c19fb65a1cbf963615774541488af30e48feca79bdbf296edee7d4d8
4
- data.tar.gz: f8b902f88a523155bab3d819905ffa25da29cad05178c445541a1159b84c94a9
3
+ metadata.gz: 994ee06cdd4ed63d0dfa79e0e77b1fb6b017528926a7b891d8ff702a15cf7347
4
+ data.tar.gz: 55298f93ce2078f1157a1426ce63823b78ae8a04cd4b076947a2ba1ad93ad05c
5
5
  SHA512:
6
- metadata.gz: 3e6f041b8180b95d6f126649a0fe7da5a02f2a5afae88fd8f79e6f8c04bd9d4e854e4f626eb032132599ae865f8b4c8bdfb26a7f17469bef8426bc702bd88665
7
- data.tar.gz: c4fcdb5b393970c9a79569a34e6317616ba96f9a953f5a963b413266621a76cb6a6f8c79de0a1f3b0753cd350e1ea11114d252a7724552b70f06ff4819657eb3
6
+ metadata.gz: 512b254802875cca2dae6377a1317439b25d35038aacd56ce2db18ee2aaaf9d0f1d22bb2f521ce16366a7a5630d5768468f3949579216fc02502b36e06e6159a
7
+ data.tar.gz: b25f1d98da59db8bc91f02d90fe44003350d7bf7eb7b67d5610d2006f7e0f5e1b72e9d37601b3a41f01faf34c8c07d8c388e173084edc6ebaf985e5f124f7d4a
@@ -140,16 +140,16 @@ module Bulkrax
140
140
  def create_collection(attrs)
141
141
  attrs = clean_attrs(attrs)
142
142
  attrs = collection_type(attrs)
143
- persist_collection_memberships(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
144
143
  object.attributes = attrs
145
144
  object.apply_depositor_metadata(@user)
146
145
  object.save!
146
+ pass_collection_to_be_persisted(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
147
147
  end
148
148
 
149
149
  def update_collection(attrs)
150
- persist_collection_memberships(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
151
150
  object.attributes = attrs
152
151
  object.save!
152
+ pass_collection_to_be_persisted(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
153
153
  end
154
154
 
155
155
  # This method is heavily inspired by Hyrax's AttachFilesToWorkJob
@@ -182,9 +182,17 @@ module Bulkrax
182
182
  actor.update_metadata(file_set_attrs)
183
183
  end
184
184
 
185
+ def pass_collection_to_be_persisted(parent:, child:)
186
+ if parent.is_a? Array
187
+ parent.each { |par| persist_collection_memberships(par, child) }
188
+ else
189
+ persist_collection_memberships(parent, child)
190
+ end
191
+ end
192
+
185
193
  # Add child to parent's #member_collections
186
194
  # Add parent to child's #member_of_collections
187
- def persist_collection_memberships(parent:, child:)
195
+ def persist_collection_memberships(parent, child)
188
196
  parent.reject!(&:blank?) if parent.respond_to?(:reject!)
189
197
  child.reject!(&:blank?) if child.respond_to?(:reject!)
190
198
  return if parent.blank? || child.blank?
@@ -21,7 +21,7 @@ module Bulkrax
21
21
 
22
22
  queue_as :import
23
23
 
24
- attr_accessor :child_records, :parent_record, :parent_entry, :importer_run_id
24
+ attr_accessor :child_records, :child_entry, :parent_record, :parent_entry, :importer_run_id
25
25
 
26
26
  # @param parent_identifier [String] Work/Collection ID or Bulkrax::Entry source_identifiers
27
27
  # @param importer_run [Bulkrax::ImporterRun] current importer run (needed to properly update counters)
@@ -31,7 +31,7 @@ module Bulkrax
31
31
  # Whether the @base_entry is the parent or the child in the relationship is determined by the presence of a
32
32
  # parent_identifier or child_identifier param. For example, if a parent_identifier is passed, we know @base_entry
33
33
  # is the child in the relationship, and vice versa if a child_identifier is passed.
34
- def perform(parent_identifier:, importer_run_id:)
34
+ def perform(parent_identifier:, importer_run_id:) # rubocop:disable Metrics/AbcSize
35
35
  pending_relationships = Bulkrax::PendingRelationship.find_each.select do |rel|
36
36
  rel.bulkrax_importer_run_id == importer_run_id && rel.parent_id == parent_identifier
37
37
  end.sort_by(&:order)
@@ -41,7 +41,7 @@ module Bulkrax
41
41
  @child_records = { works: [], collections: [] }
42
42
  pending_relationships.each do |rel|
43
43
  raise ::StandardError, %("#{rel}" needs either a child or a parent to create a relationship) if rel.child_id.nil? || rel.parent_id.nil?
44
- _, child_record = find_record(rel.child_id, importer_run_id)
44
+ @child_entry, child_record = find_record(rel.child_id, importer_run_id)
45
45
  child_record.is_a?(::Collection) ? @child_records[:collections] << child_record : @child_records[:works] << child_record
46
46
  end
47
47
 
@@ -59,7 +59,7 @@ module Bulkrax
59
59
  create_relationships
60
60
  pending_relationships.each(&:destroy)
61
61
  rescue ::StandardError => e
62
- parent_entry.status_info(e)
62
+ parent_entry ? parent_entry.status_info(e) : child_entry.status_info(e)
63
63
  Bulkrax::ImporterRun.find(importer_run_id).increment!(:failed_relationships) # rubocop:disable Rails/SkipsModelValidations
64
64
  end
65
65
 
@@ -87,8 +87,8 @@ module Bulkrax
87
87
  ObjectFactory.new(
88
88
  attributes: attrs,
89
89
  source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value
90
- work_identifier: parent_entry.parser.work_identifier,
91
- related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
90
+ work_identifier: parent_entry&.parser&.work_identifier,
91
+ related_parents_parsed_mapping: parent_entry&.parser&.related_parents_parsed_mapping,
92
92
  replace_files: false,
93
93
  user: user,
94
94
  klass: child_record.class,
@@ -106,8 +106,8 @@ module Bulkrax
106
106
  ObjectFactory.new(
107
107
  attributes: attrs,
108
108
  source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value
109
- work_identifier: parent_entry.parser.work_identifier,
110
- related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
109
+ work_identifier: parent_entry&.parser&.work_identifier,
110
+ related_parents_parsed_mapping: parent_entry&.parser&.related_parents_parsed_mapping,
111
111
  replace_files: false,
112
112
  user: user,
113
113
  klass: parent_record.class,
@@ -130,8 +130,8 @@ module Bulkrax
130
130
  ObjectFactory.new(
131
131
  attributes: attrs,
132
132
  source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value
133
- work_identifier: parent_entry.parser.work_identifier,
134
- related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
133
+ work_identifier: parent_entry&.parser&.work_identifier,
134
+ related_parents_parsed_mapping: parent_entry&.parser&.related_parents_parsed_mapping,
135
135
  replace_files: false,
136
136
  user: user,
137
137
  klass: parent_record.class,
@@ -240,8 +240,8 @@ module Bulkrax
240
240
  Bulkrax::CsvMatcher
241
241
  end
242
242
 
243
- def possible_collection_ids
244
- return @possible_collection_ids if @possible_collection_ids.present?
243
+ def collection_identifiers
244
+ return @collection_identifiers if @collection_identifiers.present?
245
245
 
246
246
  parent_field_mapping = self.class.parent_field(parser)
247
247
  return [] unless parent_field_mapping.present? && record[parent_field_mapping].present?
@@ -249,22 +249,25 @@ module Bulkrax
249
249
  identifiers = []
250
250
  split_references = record[parent_field_mapping].split(/\s*[;|]\s*/)
251
251
  split_references.each do |c_reference|
252
- matching_collection_entries = importerexporter.entries.select { |e| e.raw_metadata[work_identifier] == c_reference && e.is_a?(CsvCollectionEntry) }
252
+ matching_collection_entries = importerexporter.entries.select do |e|
253
+ (e.raw_metadata[source_identifier] == c_reference) &&
254
+ e.is_a?(CsvCollectionEntry)
255
+ end
253
256
  raise ::StandardError, 'Only expected to find one matching entry' if matching_collection_entries.count > 1
254
257
  identifiers << matching_collection_entries.first&.identifier
255
258
  end
256
259
 
257
- @possible_collection_ids = identifiers.compact.presence || []
260
+ @collection_identifiers = identifiers.compact.presence || []
258
261
  end
259
262
 
260
263
  def collections_created?
261
- possible_collection_ids.length == self.collection_ids.length
264
+ collection_identifiers.length == self.collection_ids.length
262
265
  end
263
266
 
264
267
  def find_collection_ids
265
268
  return self.collection_ids if collections_created?
266
- if possible_collection_ids.present?
267
- possible_collection_ids.each do |collection_id|
269
+ if collection_identifiers.present?
270
+ collection_identifiers.each do |collection_id|
268
271
  c = find_collection(collection_id)
269
272
  skip = c.blank? || self.collection_ids.include?(c.id)
270
273
  self.collection_ids << c.id unless skip
@@ -5,6 +5,8 @@ module Bulkrax
5
5
  belongs_to :importer
6
6
  has_many :statuses, as: :runnable, dependent: :destroy
7
7
 
8
- serialize :parents, Array
8
+ def parents
9
+ PendingRelationship.where(bulkrax_importer_run_id: id).pluck(:parent_id).uniq
10
+ end
9
11
  end
10
12
  end
@@ -11,7 +11,8 @@ module Bulkrax
11
11
  def find_record(identifier, importer_run_id = nil)
12
12
  # check for our entry in our current importer first
13
13
  importer_id = ImporterRun.find(importer_run_id).importer_id
14
- record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) || Entry.find_by(identifier: identifier)
14
+ default_scope = { identifier: identifier, importerexporter_type: 'Bulkrax::Importer' }
15
+ record = Entry.find_by(default_scope, importerexporter_id: importer_id) || Entry.find_by(default_scope)
15
16
 
16
17
  # TODO(alishaevn): discuss whether we are only looking for Collection models here
17
18
  # use ActiveFedora::Base.find(identifier) instead?
@@ -28,7 +28,6 @@ module Bulkrax
28
28
  self.parsed_metadata[related_parents_parsed_mapping].each do |parent_identifier|
29
29
  next if parent_identifier.blank?
30
30
 
31
- add_parent_to_import_run(parent_identifier, importerexporter.last_run)
32
31
  PendingRelationship.create!(child_id: self.identifier, parent_id: parent_identifier, bulkrax_importer_run_id: importerexporter.last_run.id, order: self.id)
33
32
  end
34
33
  end
@@ -37,16 +36,10 @@ module Bulkrax
37
36
  self.parsed_metadata[related_children_parsed_mapping].each do |child_identifier|
38
37
  next if child_identifier.blank?
39
38
 
40
- add_parent_to_import_run(self.identifier, importerexporter.last_run)
41
39
  PendingRelationship.create!(parent_id: self.identifier, child_id: child_identifier, bulkrax_importer_run_id: importerexporter.last_run.id, order: self.id)
42
40
  end
43
41
  end
44
42
 
45
- def add_parent_to_import_run(parent_id, run)
46
- run.parents << parent_id
47
- run.save
48
- end
49
-
50
43
  def find_collection_ids
51
44
  self.collection_ids
52
45
  end
@@ -79,13 +79,12 @@
79
79
  <%= @exporter.exporter_runs.last&.total_work_entries %>
80
80
  </p>
81
81
  <br>
82
- <div class="bulkrax-nav-tab-table-left-align">
82
+ <div class='bulkrax-nav-tab-table-left-align'>
83
83
  <h2>Entries</h2>
84
84
  <table class='table table-striped'>
85
85
  <thead>
86
86
  <tr>
87
87
  <th>Identifier</th>
88
- <th>Collection</th>
89
88
  <th>Entry ID</th>
90
89
  <th>Status</th>
91
90
  <th>Errors</th>
@@ -97,17 +96,12 @@
97
96
  <% @work_entries.each do |e| %>
98
97
  <tr>
99
98
  <td><%= link_to e.identifier, bulkrax.exporter_entry_path(@exporter.id, e.id) %></td>
100
- <% if e.parsed_metadata.present? && e.parsed_metadata.dig('collections').present? %>
101
- <td><%= e.parsed_metadata.dig('collections').map {|c| c['id'] }.join('; ') %></td>
102
- <% elsif e.raw_metadata.present? %>
103
- <td><%= Array.wrap(e.raw_metadata.dig('collection')).join(';') %></td>
104
- <% else %>
105
- <td></td>
106
- <% end %>
107
99
  <td><%= e.id %></td>
108
100
  <% if e.status == 'Complete' %>
109
101
  <td><span class='glyphicon glyphicon-ok' style='color: green;'></span> <%= e.status %></td>
110
- <% else %>
102
+ <% elsif e.status == 'Pending' %>
103
+ <td><span class='glyphicon glyphicon-option-horizontal' style='color: blue;'></span> <%= e.status %></td>
104
+ <% else %>
111
105
  <td><span class='glyphicon glyphicon-remove' style='color: red;'></span> <%= e.status %></td>
112
106
  <% end %>
113
107
  <% if e.last_error.present? %>
@@ -85,7 +85,6 @@
85
85
  <thead>
86
86
  <tr>
87
87
  <th>Identifier</th>
88
- <th>Collection</th>
89
88
  <th>Entry ID</th>
90
89
  <th>Status</th>
91
90
  <th>Errors</th>
@@ -97,8 +96,6 @@
97
96
  <% @work_entries.each do |e| %>
98
97
  <tr>
99
98
  <td><%= link_to e.identifier, bulkrax.importer_entry_path(@importer.id, e.id) %></td>
100
- <% collection_titles = e.collection_ids.map {|id| c = Collection.find id; c.title.first } %>
101
- <td><%= collection_titles.join('; ') %></td>
102
99
  <td><%= e.id %></td>
103
100
  <% if e.status == "Complete" %>
104
101
  <td><span class="glyphicon glyphicon-ok" style="color: green;"></span> <%= e.status %></td>
@@ -178,6 +175,8 @@
178
175
  <td><%= e.id %></td>
179
176
  <% if e.status == "Complete" %>
180
177
  <td><span class="glyphicon glyphicon-ok" style="color: green;"></span> <%= e.status %></td>
178
+ <% elsif e.status == "Pending" %>
179
+ <td><span class="glyphicon glyphicon-option-horizontal" style="color: blue;"></span> <%= e.status %></td>
181
180
  <% else %>
182
181
  <td><span class="glyphicon glyphicon-remove" style="color: red;"></span> <%= e.status %></td>
183
182
  <% end %>
@@ -1,6 +1,6 @@
1
1
  class RenameChildrenCountersToRelationships < ActiveRecord::Migration[5.2]
2
2
  def change
3
- rename_column :bulkrax_importer_runs, :processed_children, :processed_relationships
4
- rename_column :bulkrax_importer_runs, :failed_children, :failed_relationships
3
+ rename_column :bulkrax_importer_runs, :processed_children, :processed_relationships unless column_exists?(:bulkrax_importer_runs, :processed_relationships)
4
+ rename_column :bulkrax_importer_runs, :failed_children, :failed_relationships unless column_exists?(:bulkrax_importer_runs, :failed_relationships)
5
5
  end
6
6
  end
@@ -1,11 +1,13 @@
1
1
  class CreateBulkraxPendingRelationships < ActiveRecord::Migration[5.2]
2
2
  def change
3
- create_table :bulkrax_pending_relationships do |t|
4
- t.belongs_to :bulkrax_importer_run, foreign_key: true, null: false
5
- t.string :parent_id, null: false
6
- t.string :child_id, null: false
3
+ unless table_exists?(:bulkrax_pending_relationships)
4
+ create_table :bulkrax_pending_relationships do |t|
5
+ t.belongs_to :bulkrax_importer_run, foreign_key: true, null: false
6
+ t.string :parent_id, null: false
7
+ t.string :child_id, null: false
7
8
 
8
- t.timestamps
9
+ t.timestamps
10
+ end
9
11
  end
10
12
  end
11
13
  end
@@ -1,5 +1,5 @@
1
1
  class AddOrderToBulkraxPendingRelationships < ActiveRecord::Migration[5.2]
2
2
  def change
3
- add_column :bulkrax_pending_relationships, :order, :integer, default: 0
3
+ add_column :bulkrax_pending_relationships, :order, :integer, default: 0 unless column_exists?(:bulkrax_pending_relationships, :order)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '3.0.0.beta4'
4
+ VERSION = '3.0.0.beta5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulkrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta4
4
+ version: 3.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman
@@ -366,9 +366,7 @@ files:
366
366
  - db/migrate/20220118001339_add_import_attempts_to_entries.rb
367
367
  - db/migrate/20220119213325_add_work_counters_to_importer_runs.rb
368
368
  - db/migrate/20220301001839_create_bulkrax_pending_relationships.rb
369
- - db/migrate/20220301020307_add_parents_to_bulkrax_importer_runs.rb
370
369
  - db/migrate/20220303212810_add_order_to_bulkrax_pending_relationships.rb
371
- - db/migrate/20220330165510_remove_array_true_from_importer_run_parents_column.rb
372
370
  - lib/bulkrax.rb
373
371
  - lib/bulkrax/engine.rb
374
372
  - lib/bulkrax/version.rb
@@ -1,5 +0,0 @@
1
- class AddParentsToBulkraxImporterRuns < ActiveRecord::Migration[5.1]
2
- def change
3
- add_column :bulkrax_importer_runs, :parents, :text, array: true
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class RemoveArrayTrueFromImporterRunParentsColumn < ActiveRecord::Migration[5.2]
2
- def change
3
- change_column :bulkrax_importer_runs, :parents, :text, array: false, default: nil
4
- end
5
- end