bulkrax 3.0.0.beta3 → 3.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/factories/bulkrax/object_factory.rb +14 -3
- data/app/jobs/bulkrax/create_relationships_job.rb +11 -8
- data/app/jobs/bulkrax/import_file_set_job.rb +5 -1
- data/app/models/bulkrax/csv_entry.rb +9 -5
- data/app/models/concerns/bulkrax/dynamic_record_lookup.rb +12 -4
- data/app/models/concerns/bulkrax/file_factory.rb +8 -1
- data/app/models/concerns/bulkrax/import_behavior.rb +1 -0
- data/app/views/bulkrax/importers/show.html.erb +2 -7
- data/lib/bulkrax/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29702685c19fb65a1cbf963615774541488af30e48feca79bdbf296edee7d4d8
|
4
|
+
data.tar.gz: f8b902f88a523155bab3d819905ffa25da29cad05178c445541a1159b84c94a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e6f041b8180b95d6f126649a0fe7da5a02f2a5afae88fd8f79e6f8c04bd9d4e854e4f626eb032132599ae865f8b4c8bdfb26a7f17469bef8426bc702bd88665
|
7
|
+
data.tar.gz: c4fcdb5b393970c9a79569a34e6317616ba96f9a953f5a963b413266621a76cb6a6f8c79de0a1f3b0753cd350e1ea11114d252a7724552b70f06ff4819657eb3
|
@@ -7,10 +7,10 @@ module Bulkrax
|
|
7
7
|
include DynamicRecordLookup
|
8
8
|
|
9
9
|
define_model_callbacks :save, :create
|
10
|
-
attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :related_parents_parsed_mapping
|
10
|
+
attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :related_parents_parsed_mapping, :importer_run_id
|
11
11
|
|
12
12
|
# rubocop:disable Metrics/ParameterLists
|
13
|
-
def initialize(attributes:, source_identifier_value:, work_identifier:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, update_files: false)
|
13
|
+
def initialize(attributes:, source_identifier_value:, work_identifier:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, importer_run_id: nil, update_files: false)
|
14
14
|
@attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
|
15
15
|
@replace_files = replace_files
|
16
16
|
@update_files = update_files
|
@@ -19,6 +19,7 @@ module Bulkrax
|
|
19
19
|
@related_parents_parsed_mapping = related_parents_parsed_mapping
|
20
20
|
@source_identifier_value = source_identifier_value
|
21
21
|
@klass = klass || Bulkrax.default_work_type.constantize
|
22
|
+
@importer_run_id = importer_run_id
|
22
23
|
end
|
23
24
|
# rubocop:enable Metrics/ParameterLists
|
24
25
|
|
@@ -137,6 +138,7 @@ module Bulkrax
|
|
137
138
|
end
|
138
139
|
|
139
140
|
def create_collection(attrs)
|
141
|
+
attrs = clean_attrs(attrs)
|
140
142
|
attrs = collection_type(attrs)
|
141
143
|
persist_collection_memberships(parent: find_collection(attributes[related_parents_parsed_mapping]), child: object) if attributes[related_parents_parsed_mapping].present?
|
142
144
|
object.attributes = attrs
|
@@ -152,8 +154,9 @@ module Bulkrax
|
|
152
154
|
|
153
155
|
# This method is heavily inspired by Hyrax's AttachFilesToWorkJob
|
154
156
|
def create_file_set(attrs)
|
155
|
-
work = find_record(attributes[related_parents_parsed_mapping].first)
|
157
|
+
_, work = find_record(attributes[related_parents_parsed_mapping].first, importer_run_id)
|
156
158
|
work_permissions = work.permissions.map(&:to_hash)
|
159
|
+
attrs = clean_attrs(attrs)
|
157
160
|
file_set_attrs = attrs.slice(*object.attributes.keys)
|
158
161
|
object.assign_attributes(file_set_attrs)
|
159
162
|
|
@@ -202,8 +205,16 @@ module Bulkrax
|
|
202
205
|
end
|
203
206
|
end
|
204
207
|
|
208
|
+
def clean_attrs(attrs)
|
209
|
+
# avoid the "ArgumentError: Identifier must be a string of size > 0 in order to be treeified" error
|
210
|
+
# when setting object.attributes
|
211
|
+
attrs.delete('id') if attrs['id'].blank?
|
212
|
+
attrs
|
213
|
+
end
|
214
|
+
|
205
215
|
def collection_type(attrs)
|
206
216
|
return attrs if attrs['collection_type_gid'].present?
|
217
|
+
|
207
218
|
attrs['collection_type_gid'] = Hyrax::CollectionType.find_or_create_default_collection_type.gid
|
208
219
|
attrs
|
209
220
|
end
|
@@ -37,11 +37,11 @@ module Bulkrax
|
|
37
37
|
end.sort_by(&:order)
|
38
38
|
|
39
39
|
@importer_run_id = importer_run_id
|
40
|
-
@parent_record = find_record(parent_identifier)
|
40
|
+
@parent_entry, @parent_record = find_record(parent_identifier, importer_run_id)
|
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)
|
44
|
+
_, 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
|
|
@@ -53,9 +53,9 @@ module Bulkrax
|
|
53
53
|
return false # stop current job from continuing to run after rescheduling
|
54
54
|
end
|
55
55
|
|
56
|
-
@parent_entry
|
57
|
-
|
58
|
-
|
56
|
+
@parent_entry ||= Bulkrax::Entry.where(identifier: parent_identifier,
|
57
|
+
importerexporter_id: ImporterRun.find(importer_run_id).importer_id,
|
58
|
+
importerexporter_type: "Bulkrax::Importer").first
|
59
59
|
create_relationships
|
60
60
|
pending_relationships.each(&:destroy)
|
61
61
|
rescue ::StandardError => e
|
@@ -91,7 +91,8 @@ module Bulkrax
|
|
91
91
|
related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
|
92
92
|
replace_files: false,
|
93
93
|
user: user,
|
94
|
-
klass: child_record.class
|
94
|
+
klass: child_record.class,
|
95
|
+
importer_run_id: importer_run_id
|
95
96
|
).run
|
96
97
|
# TODO: add counters for :processed_parents and :failed_parents
|
97
98
|
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
@@ -109,7 +110,8 @@ module Bulkrax
|
|
109
110
|
related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
|
110
111
|
replace_files: false,
|
111
112
|
user: user,
|
112
|
-
klass: parent_record.class
|
113
|
+
klass: parent_record.class,
|
114
|
+
importer_run_id: importer_run_id
|
113
115
|
).run
|
114
116
|
# TODO: add counters for :processed_parents and :failed_parents
|
115
117
|
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
@@ -132,7 +134,8 @@ module Bulkrax
|
|
132
134
|
related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping,
|
133
135
|
replace_files: false,
|
134
136
|
user: user,
|
135
|
-
klass: parent_record.class
|
137
|
+
klass: parent_record.class,
|
138
|
+
importer_run_id: importer_run_id
|
136
139
|
).run
|
137
140
|
# TODO: add counters for :processed_parents and :failed_parents
|
138
141
|
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
@@ -7,7 +7,10 @@ module Bulkrax
|
|
7
7
|
|
8
8
|
queue_as :import
|
9
9
|
|
10
|
+
attr_reader :importer_run_id
|
11
|
+
|
10
12
|
def perform(entry_id, importer_run_id)
|
13
|
+
@importer_run_id = importer_run_id
|
11
14
|
entry = Entry.find(entry_id)
|
12
15
|
parent_identifier = entry.raw_metadata[entry.related_parents_raw_mapping]&.strip
|
13
16
|
|
@@ -63,7 +66,8 @@ module Bulkrax
|
|
63
66
|
end
|
64
67
|
|
65
68
|
def find_parent_record(parent_identifier)
|
66
|
-
@parent_record ||= find_record(parent_identifier)
|
69
|
+
@parent_record ||= find_record(parent_identifier, importer_run_id)
|
70
|
+
@parent_record = parent_record.last if parent_record.is_a? Array
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
@@ -41,6 +41,8 @@ module Bulkrax
|
|
41
41
|
self.parsed_metadata = {}
|
42
42
|
add_identifier
|
43
43
|
add_ingested_metadata
|
44
|
+
# TODO(alishaevn): remove the collections stuff entirely and only reference collections via the new parents code
|
45
|
+
add_collections
|
44
46
|
add_visibility
|
45
47
|
add_metadata_for_model
|
46
48
|
add_rights_statement
|
@@ -241,16 +243,17 @@ module Bulkrax
|
|
241
243
|
def possible_collection_ids
|
242
244
|
return @possible_collection_ids if @possible_collection_ids.present?
|
243
245
|
|
244
|
-
|
245
|
-
return [] unless
|
246
|
+
parent_field_mapping = self.class.parent_field(parser)
|
247
|
+
return [] unless parent_field_mapping.present? && record[parent_field_mapping].present?
|
246
248
|
|
247
249
|
identifiers = []
|
248
|
-
|
249
|
-
|
250
|
-
matching_collection_entries = importerexporter.entries.select { |e| e.raw_metadata[
|
250
|
+
split_references = record[parent_field_mapping].split(/\s*[;|]\s*/)
|
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) }
|
251
253
|
raise ::StandardError, 'Only expected to find one matching entry' if matching_collection_entries.count > 1
|
252
254
|
identifiers << matching_collection_entries.first&.identifier
|
253
255
|
end
|
256
|
+
|
254
257
|
@possible_collection_ids = identifiers.compact.presence || []
|
255
258
|
end
|
256
259
|
|
@@ -267,6 +270,7 @@ module Bulkrax
|
|
267
270
|
self.collection_ids << c.id unless skip
|
268
271
|
end
|
269
272
|
end
|
273
|
+
|
270
274
|
self.collection_ids
|
271
275
|
end
|
272
276
|
|
@@ -6,9 +6,15 @@ module Bulkrax
|
|
6
6
|
# has the provided identifier.
|
7
7
|
#
|
8
8
|
# @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
9
|
+
# @param importer_run_id [Number] ID of the current_run of this Importer Job
|
10
|
+
# @return [Entry, nil], [Work, Collection, nil] Entry if found, otherwise nil and a Work or Collection if found, otherwise nil
|
11
|
+
def find_record(identifier, importer_run_id = nil)
|
12
|
+
# check for our entry in our current importer first
|
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)
|
15
|
+
|
16
|
+
# TODO(alishaevn): discuss whether we are only looking for Collection models here
|
17
|
+
# use ActiveFedora::Base.find(identifier) instead?
|
12
18
|
record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy
|
13
19
|
if record.blank?
|
14
20
|
available_work_types.each do |work_type|
|
@@ -16,7 +22,9 @@ module Bulkrax
|
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
|
-
|
25
|
+
# return the found entry here instead of searching for it again in the CreateRelationshipsJob
|
26
|
+
# also accounts for when the found entry isn't a part of this importer
|
27
|
+
record.is_a?(Entry) ? [record, record.factory.find] : [nil, record]
|
20
28
|
end
|
21
29
|
|
22
30
|
# Check if the record is a Work
|
@@ -45,6 +45,8 @@ module Bulkrax
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def new_remote_files
|
48
|
+
return if object.is_a? FileSet
|
49
|
+
|
48
50
|
@new_remote_files ||= if object.present? && object.file_sets.present?
|
49
51
|
parsed_remote_files.select do |file|
|
50
52
|
# is the url valid?
|
@@ -101,7 +103,12 @@ module Bulkrax
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def local_file_sets
|
104
|
-
@local_file_sets ||=
|
106
|
+
@local_file_sets ||= ordered_file_sets
|
107
|
+
end
|
108
|
+
|
109
|
+
def ordered_file_sets
|
110
|
+
# OVERRIDE Hyrda-works 1.2.0 - this method was deprecated in v1.0
|
111
|
+
object&.ordered_members.to_a.select(&:file_set?)
|
105
112
|
end
|
106
113
|
|
107
114
|
def import_files
|
@@ -97,13 +97,8 @@
|
|
97
97
|
<% @work_entries.each do |e| %>
|
98
98
|
<tr>
|
99
99
|
<td><%= link_to e.identifier, bulkrax.importer_entry_path(@importer.id, e.id) %></td>
|
100
|
-
<%
|
101
|
-
|
102
|
-
<% elsif e.raw_metadata.present? %>
|
103
|
-
<td><%= Array.wrap(e.raw_metadata.dig("collection")).join(';') %></td>
|
104
|
-
<% else %>
|
105
|
-
<td></td>
|
106
|
-
<% end %>
|
100
|
+
<% collection_titles = e.collection_ids.map {|id| c = Collection.find id; c.title.first } %>
|
101
|
+
<td><%= collection_titles.join('; ') %></td>
|
107
102
|
<td><%= e.id %></td>
|
108
103
|
<% if e.status == "Complete" %>
|
109
104
|
<td><span class="glyphicon glyphicon-ok" style="color: green;"></span> <%= e.status %></td>
|
data/lib/bulkrax/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulkrax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Kaufman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|