bulkrax 3.0.0.beta6 → 3.0.0

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: 744a122509bc57b9b9a24367c2eee3660d3184bd8209543de43e7f9bf3b1c6ef
4
- data.tar.gz: c9156dba83a463872cf700d93d12770b5967a1e28f269aba0141d0ae9a280e8e
3
+ metadata.gz: 3976f63546f72c7a1fcc47ba595aa3e6486f2f6bcf7fb39a65f9cceb61513dc2
4
+ data.tar.gz: 267eb1e87602fdc7a510eff6ac61a459c11a1bbc3691b0b07e9aebd9d84de743
5
5
  SHA512:
6
- metadata.gz: 3abe5abd1a882ebe4090a75c8600a9c9e35ede83fdaab22aaf33966d5b412fc256835ccef6ab7eaf3776f5ff7a4b0c27eaf94ac77fccf99985b7ad1dc2172c78
7
- data.tar.gz: 6f1387ce3876c65f23b15cb0cf6824040af2071f59a7f2c3d68377c78994d543f1bd7beced5a334e9467bc7285c1930da9acc6ac7c9e2fdddbdcd0b156541386
6
+ metadata.gz: 6512d5c1169d1024b9b5e16847772cb8a662b98638127204e198e09463a54bd3c93f36eac12460e20c43156148ff546a85fbea3d01dd9a0a55df179c56fc8b5d
7
+ data.tar.gz: f80a6017b2247235a10b7d23fbbd5199464ac018cd7a9d5609ad8a6c97898e7b20b718c8cb2d9821231de9654f68caf6f39359eb82270c4832d15385ad1f7d12
@@ -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 member_of_collections_attributes]
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
- attrs = { id: child_record.id, member_of_collections_attributes: { 0 => { id: parent_record.id } } }
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
- child_record = child_records[:collections].first
105
- attrs = { id: parent_record.id, child_collection_id: child_record.id }
106
- ObjectFactory.new(
107
- attributes: attrs,
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
- ObjectFactory.new(
131
- attributes: attrs,
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,
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,56 @@ 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 collections
21
- # retrieve a list of unique collections
22
- records.map do |r|
23
- collections = []
24
- model_field_mappings.each do |model_mapping|
25
- collections << r if r[model_mapping.to_sym]&.downcase == 'collection'
22
+ def build_records
23
+ @collections = []
24
+ @works = []
25
+ @file_sets = []
26
+
27
+ if model_field_mappings.map { |mfm| mfm.to_sym.in?(records.first.keys) }.any?
28
+ records.map do |r|
29
+ model_field_mappings.map(&:to_sym).each do |model_mapping|
30
+ next unless r.key?(model_mapping)
31
+
32
+ if r[model_mapping].casecmp('collection').zero?
33
+ @collections << r
34
+ elsif r[model_mapping].casecmp('fileset').zero?
35
+ @file_sets << r
36
+ else
37
+ @works << r
38
+ end
39
+ end
26
40
  end
27
- collections
28
- end.flatten.compact.uniq
41
+ @collections = @collections.flatten.compact.uniq
42
+ @file_sets = @file_sets.flatten.compact.uniq
43
+ @works = @works.flatten.compact.uniq
44
+ else # if no model is specified, assume all records are works
45
+ @works = records.flatten.compact.uniq
46
+ end
47
+
48
+ true
29
49
  end
30
50
 
31
- def collections_total
32
- collections.size
51
+ def collections
52
+ build_records if @collections.nil?
53
+ @collections
33
54
  end
34
55
 
35
56
  def works
36
- records - collections - file_sets
57
+ build_records if @works.nil?
58
+ @works
37
59
  end
38
60
 
39
- def works_total
40
- works.size
61
+ def file_sets
62
+ build_records if @file_sets.nil?
63
+ @file_sets
41
64
  end
42
65
 
43
- def file_sets
44
- records.map do |r|
45
- file_sets = []
46
- model_field_mappings.each do |model_mapping|
47
- file_sets << r if r[model_mapping.to_sym]&.downcase == 'fileset'
48
- end
49
- file_sets
50
- end.flatten.compact.uniq
66
+ def collections_total
67
+ collections.size
68
+ end
69
+
70
+ def works_total
71
+ works.size
51
72
  end
52
73
 
53
74
  def file_sets_total
@@ -96,21 +117,24 @@ module Bulkrax
96
117
  end
97
118
 
98
119
  def create_objects(types_array = nil)
99
- (types_array || %w[work collection file_set relationship]).each do |type|
120
+ index = 0
121
+ (types_array || %w[collection work file_set relationship]).each do |type|
100
122
  if type.eql?('relationship')
101
123
  ScheduleRelationshipsJob.set(wait: 5.minutes).perform_later(importer_id: importerexporter.id)
102
124
  next
103
125
  end
104
- send(type.pluralize).each_with_index do |current_record, index|
105
- next unless record_has_source_identifier(current_record, records.find_index(current_record))
106
- break if limit_reached?(limit, records.find_index(current_record))
126
+ send(type.pluralize).each do |current_record|
127
+ next unless record_has_source_identifier(current_record, index)
128
+ break if limit_reached?(limit, index)
107
129
 
108
130
  seen[current_record[source_identifier]] = true
109
131
  create_entry_and_job(current_record, type)
110
132
  increment_counters(index, "#{type}": true)
133
+ index += 1
111
134
  end
112
135
  importer.record_status
113
136
  end
137
+ true
114
138
  rescue StandardError => e
115
139
  status_info(e)
116
140
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '3.0.0.beta6'
4
+ VERSION = '3.0.0'
5
5
  end
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.beta6
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-27 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -382,7 +382,7 @@ homepage: https://github.com/samvera-labs/bulkrax
382
382
  licenses:
383
383
  - Apache-2.0
384
384
  metadata: {}
385
- post_install_message:
385
+ post_install_message:
386
386
  rdoc_options: []
387
387
  require_paths:
388
388
  - lib
@@ -393,12 +393,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
393
393
  version: '0'
394
394
  required_rubygems_version: !ruby/object:Gem::Requirement
395
395
  requirements:
396
- - - ">"
396
+ - - ">="
397
397
  - !ruby/object:Gem::Version
398
- version: 1.3.1
398
+ version: '0'
399
399
  requirements: []
400
- rubygems_version: 3.1.4
401
- signing_key:
400
+ rubygems_version: 3.1.2
401
+ signing_key:
402
402
  specification_version: 4
403
403
  summary: Import and export tool for Hyrax and Hyku
404
404
  test_files: []