bulkrax 3.0.0.beta6 → 3.0.0.beta7
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 +1 -34
- data/app/jobs/bulkrax/create_relationships_job.rb +8 -36
- data/app/jobs/bulkrax/import_collection_job.rb +0 -18
- data/app/models/concerns/bulkrax/import_behavior.rb +20 -0
- data/app/parsers/bulkrax/csv_parser.rb +38 -22
- 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: 33cb77498f84a977101dd70e7de2ae3853a47c9c9fb514a156df759ab35f6b75
|
4
|
+
data.tar.gz: 49f433acd439eb004c8d95c668811df214fcd1bef5fdbfb1477cbc6cd6d598b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58f561feac1a1d3c85f442c2612ed7e52105fb335358dda3eeb07a51433c5edc03d2f4c26402384be1529002e00d5acd46f5d5e51c715d20d27e21bc7198e68d
|
7
|
+
data.tar.gz: 35b539c937e0d66427a0d5f8bf801431b33aaa1d26dfef83786a97f3704a9aafbce4dd33903b7b9f6b1026a8d4339d2b6033b80b1e7aa725bc07d7e463b5493d
|
@@ -143,13 +143,11 @@ module Bulkrax
|
|
143
143
|
object.attributes = attrs
|
144
144
|
object.apply_depositor_metadata(@user)
|
145
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
146
|
end
|
148
147
|
|
149
148
|
def update_collection(attrs)
|
150
149
|
object.attributes = attrs
|
151
150
|
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
151
|
end
|
154
152
|
|
155
153
|
# This method is heavily inspired by Hyrax's AttachFilesToWorkJob
|
@@ -182,37 +180,6 @@ module Bulkrax
|
|
182
180
|
actor.update_metadata(file_set_attrs)
|
183
181
|
end
|
184
182
|
|
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
|
-
|
193
|
-
# Add child to parent's #member_collections
|
194
|
-
# Add parent to child's #member_of_collections
|
195
|
-
def persist_collection_memberships(parent, child)
|
196
|
-
parent.reject!(&:blank?) if parent.respond_to?(:reject!)
|
197
|
-
child.reject!(&:blank?) if child.respond_to?(:reject!)
|
198
|
-
return if parent.blank? || child.blank?
|
199
|
-
|
200
|
-
::Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: parent, child: child)
|
201
|
-
end
|
202
|
-
|
203
|
-
def find_collection(id)
|
204
|
-
case id
|
205
|
-
when Hash
|
206
|
-
Collection.find(id[:id])
|
207
|
-
when String
|
208
|
-
Collection.find(id) if id.present?
|
209
|
-
when Array
|
210
|
-
id.map { |i| find_collection(i) }
|
211
|
-
else
|
212
|
-
[]
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
183
|
def clean_attrs(attrs)
|
217
184
|
# avoid the "ArgumentError: Identifier must be a string of size > 0 in order to be treeified" error
|
218
185
|
# when setting object.attributes
|
@@ -237,7 +204,7 @@ module Bulkrax
|
|
237
204
|
|
238
205
|
# Regardless of what the Parser gives us, these are the properties we are prepared to accept.
|
239
206
|
def permitted_attributes
|
240
|
-
klass.properties.keys.map(&:to_sym) + %i[id edit_users edit_groups read_groups visibility work_members_attributes admin_set_id
|
207
|
+
klass.properties.keys.map(&:to_sym) + %i[id edit_users edit_groups read_groups visibility work_members_attributes admin_set_id]
|
241
208
|
end
|
242
209
|
end
|
243
210
|
end
|
@@ -83,17 +83,7 @@ module Bulkrax
|
|
83
83
|
# This is adding the reverse relationship, from the child to the parent
|
84
84
|
def collection_parent_work_child
|
85
85
|
child_records[:works].each do |child_record|
|
86
|
-
|
87
|
-
ObjectFactory.new(
|
88
|
-
attributes: attrs,
|
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,
|
92
|
-
replace_files: false,
|
93
|
-
user: user,
|
94
|
-
klass: child_record.class,
|
95
|
-
importer_run_id: importer_run_id
|
96
|
-
).run
|
86
|
+
::Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: parent_record, child: child_record)
|
97
87
|
# TODO: add counters for :processed_parents and :failed_parents
|
98
88
|
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
99
89
|
end
|
@@ -101,20 +91,10 @@ module Bulkrax
|
|
101
91
|
|
102
92
|
# Collection-Collection membership is added to the as member_ids
|
103
93
|
def collection_parent_collection_child
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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,
|
111
|
-
replace_files: false,
|
112
|
-
user: user,
|
113
|
-
klass: parent_record.class,
|
114
|
-
importer_run_id: importer_run_id
|
115
|
-
).run
|
116
|
-
# TODO: add counters for :processed_parents and :failed_parents
|
117
|
-
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
94
|
+
child_records[:collections].each do |child_record|
|
95
|
+
::Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: parent_record, child: child_record)
|
96
|
+
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
97
|
+
end
|
118
98
|
end
|
119
99
|
|
120
100
|
# Work-Work membership is added to the parent as member_ids
|
@@ -124,19 +104,11 @@ module Bulkrax
|
|
124
104
|
records_hash[i] = { id: child_record.id }
|
125
105
|
end
|
126
106
|
attrs = {
|
127
|
-
id: parent_record.id,
|
128
107
|
work_members_attributes: records_hash
|
129
108
|
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
work_identifier: parent_entry&.parser&.work_identifier,
|
134
|
-
related_parents_parsed_mapping: parent_entry&.parser&.related_parents_parsed_mapping,
|
135
|
-
replace_files: false,
|
136
|
-
user: user,
|
137
|
-
klass: parent_record.class,
|
138
|
-
importer_run_id: importer_run_id
|
139
|
-
).run
|
109
|
+
parent_record.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX if parent_record.respond_to?(:reindex_extent)
|
110
|
+
env = Hyrax::Actors::Environment.new(parent_record, Ability.new(user), attrs)
|
111
|
+
Hyrax::CurationConcern.actor.update(env)
|
140
112
|
# TODO: add counters for :processed_parents and :failed_parents
|
141
113
|
Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
|
142
114
|
end
|
@@ -10,7 +10,6 @@ module Bulkrax
|
|
10
10
|
begin
|
11
11
|
entry.build
|
12
12
|
entry.save
|
13
|
-
add_user_to_permission_template!(entry)
|
14
13
|
ImporterRun.find(args[1]).increment!(:processed_records)
|
15
14
|
ImporterRun.find(args[1]).increment!(:processed_collections)
|
16
15
|
ImporterRun.find(args[1]).decrement!(:enqueued_records)
|
@@ -22,22 +21,5 @@ module Bulkrax
|
|
22
21
|
end
|
23
22
|
end
|
24
23
|
# rubocop:enable Rails/SkipsModelValidations
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def add_user_to_permission_template!(entry)
|
29
|
-
user = ::User.find(entry.importerexporter.user_id)
|
30
|
-
collection = entry.factory.find
|
31
|
-
permission_template = Hyrax::PermissionTemplate.find_or_create_by!(source_id: collection.id)
|
32
|
-
|
33
|
-
Hyrax::PermissionTemplateAccess.find_or_create_by!(
|
34
|
-
permission_template_id: permission_template.id,
|
35
|
-
agent_id: user.user_key,
|
36
|
-
agent_type: 'user',
|
37
|
-
access: 'manage'
|
38
|
-
)
|
39
|
-
|
40
|
-
collection.reset_access_controls!
|
41
|
-
end
|
42
24
|
end
|
43
25
|
end
|
@@ -11,6 +11,7 @@ module Bulkrax
|
|
11
11
|
unless self.importerexporter.validate_only
|
12
12
|
raise CollectionsCreatedError unless collections_created?
|
13
13
|
@item = factory.run!
|
14
|
+
add_user_to_permission_templates! if self.class.to_s.include?("Collection")
|
14
15
|
parent_jobs if self.parsed_metadata[related_parents_parsed_mapping].present?
|
15
16
|
child_jobs if self.parsed_metadata[related_children_parsed_mapping].present?
|
16
17
|
end
|
@@ -24,6 +25,25 @@ module Bulkrax
|
|
24
25
|
return @item
|
25
26
|
end
|
26
27
|
|
28
|
+
def add_user_to_permission_templates!
|
29
|
+
permission_template = Hyrax::PermissionTemplate.find_or_create_by!(source_id: @item.id)
|
30
|
+
|
31
|
+
Hyrax::PermissionTemplateAccess.find_or_create_by!(
|
32
|
+
permission_template_id: permission_template.id,
|
33
|
+
agent_id: user.user_key,
|
34
|
+
agent_type: 'user',
|
35
|
+
access: 'manage'
|
36
|
+
)
|
37
|
+
Hyrax::PermissionTemplateAccess.find_or_create_by!(
|
38
|
+
permission_template_id: permission_template.id,
|
39
|
+
agent_id: 'admin',
|
40
|
+
agent_type: 'group',
|
41
|
+
access: 'manage'
|
42
|
+
)
|
43
|
+
|
44
|
+
@item.reset_access_controls!
|
45
|
+
end
|
46
|
+
|
27
47
|
def parent_jobs
|
28
48
|
self.parsed_metadata[related_parents_parsed_mapping].each do |parent_identifier|
|
29
49
|
next if parent_identifier.blank?
|
@@ -4,6 +4,8 @@ require 'csv'
|
|
4
4
|
module Bulkrax
|
5
5
|
class CsvParser < ApplicationParser # rubocop:disable Metrics/ClassLength
|
6
6
|
include ErroredEntries
|
7
|
+
attr_writer :collections, :file_sets, :works
|
8
|
+
|
7
9
|
def self.export_supported?
|
8
10
|
true
|
9
11
|
end
|
@@ -17,37 +19,48 @@ module Bulkrax
|
|
17
19
|
@records ||= csv_data.map { |record_data| entry_class.data_for_entry(record_data, nil, self) }
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
+
def build_records
|
23
|
+
@collections = []
|
24
|
+
@works = []
|
25
|
+
@file_sets = []
|
22
26
|
records.map do |r|
|
23
|
-
collections = []
|
24
27
|
model_field_mappings.each do |model_mapping|
|
25
|
-
|
28
|
+
if r[model_mapping.to_sym]&.downcase == 'collection'
|
29
|
+
@collections << r
|
30
|
+
elsif r[model_mapping.to_sym]&.downcase == 'fileset'
|
31
|
+
@file_sets << r
|
32
|
+
else
|
33
|
+
@works << r
|
34
|
+
end
|
26
35
|
end
|
27
|
-
|
28
|
-
|
36
|
+
end
|
37
|
+
@collections = @collections.flatten.compact.uniq
|
38
|
+
@file_sets = @file_sets.flatten.compact.uniq
|
39
|
+
@works = @works.flatten.compact.uniq
|
40
|
+
true
|
29
41
|
end
|
30
42
|
|
31
|
-
def
|
32
|
-
collections.
|
43
|
+
def collections
|
44
|
+
build_records if @collections.nil?
|
45
|
+
@collections
|
33
46
|
end
|
34
47
|
|
35
48
|
def works
|
36
|
-
|
49
|
+
build_records if @works.nil?
|
50
|
+
@works
|
37
51
|
end
|
38
52
|
|
39
|
-
def
|
40
|
-
|
53
|
+
def file_sets
|
54
|
+
build_records if @file_sets.nil?
|
55
|
+
@file_sets
|
41
56
|
end
|
42
57
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
file_sets
|
50
|
-
end.flatten.compact.uniq
|
58
|
+
def collections_total
|
59
|
+
collections.size
|
60
|
+
end
|
61
|
+
|
62
|
+
def works_total
|
63
|
+
works.size
|
51
64
|
end
|
52
65
|
|
53
66
|
def file_sets_total
|
@@ -96,21 +109,24 @@ module Bulkrax
|
|
96
109
|
end
|
97
110
|
|
98
111
|
def create_objects(types_array = nil)
|
112
|
+
index = 0
|
99
113
|
(types_array || %w[work collection file_set relationship]).each do |type|
|
100
114
|
if type.eql?('relationship')
|
101
115
|
ScheduleRelationshipsJob.set(wait: 5.minutes).perform_later(importer_id: importerexporter.id)
|
102
116
|
next
|
103
117
|
end
|
104
|
-
send(type.pluralize).
|
105
|
-
next unless record_has_source_identifier(current_record,
|
106
|
-
break if limit_reached?(limit,
|
118
|
+
send(type.pluralize).each do |current_record|
|
119
|
+
next unless record_has_source_identifier(current_record, index)
|
120
|
+
break if limit_reached?(limit, index)
|
107
121
|
|
108
122
|
seen[current_record[source_identifier]] = true
|
109
123
|
create_entry_and_job(current_record, type)
|
110
124
|
increment_counters(index, "#{type}": true)
|
125
|
+
index += 1
|
111
126
|
end
|
112
127
|
importer.record_status
|
113
128
|
end
|
129
|
+
true
|
114
130
|
rescue StandardError => e
|
115
131
|
status_info(e)
|
116
132
|
end
|
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.beta7
|
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-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|