bulkrax 3.0.0.beta5 → 3.0.0.beta8

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: 994ee06cdd4ed63d0dfa79e0e77b1fb6b017528926a7b891d8ff702a15cf7347
4
- data.tar.gz: 55298f93ce2078f1157a1426ce63823b78ae8a04cd4b076947a2ba1ad93ad05c
3
+ metadata.gz: 7cfcae9e154506ea5b6699b530da3f2d370d478963de1cb5ce854db1e0ded3ed
4
+ data.tar.gz: 7b1511cbaad98ef523ac5c1f53442d0f568b7088aba2312df77e104c41c8e192
5
5
  SHA512:
6
- metadata.gz: 512b254802875cca2dae6377a1317439b25d35038aacd56ce2db18ee2aaaf9d0f1d22bb2f521ce16366a7a5630d5768468f3949579216fc02502b36e06e6159a
7
- data.tar.gz: b25f1d98da59db8bc91f02d90fe44003350d7bf7eb7b67d5610d2006f7e0f5e1b72e9d37601b3a41f01faf34c8c07d8c388e173084edc6ebaf985e5f124f7d4a
6
+ metadata.gz: af73e975cd84be460ff29e2364a79e4fdae77793ca2a1b50534b8582e602138bd9c700af2068221907eee055f593f2305afab6d304385ba4f53e5ed72c64678f
7
+ data.tar.gz: 06bc7006d8b701dda2dd68487252e563f8b46484012124d5f81e43d3aa8af4916ba3c378948ad91157dce125768e2ea01e117673288fc8dbe1e9001cef03eb7e
@@ -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
@@ -59,6 +59,7 @@ module Bulkrax
59
59
  if factory_class == Collection
60
60
  add_collection_type_gid
61
61
  elsif factory_class == FileSet
62
+ validate_presence_of_filename!
62
63
  add_path_to_file
63
64
  validate_presence_of_parent!
64
65
  else
@@ -250,7 +251,7 @@ module Bulkrax
250
251
  split_references = record[parent_field_mapping].split(/\s*[;|]\s*/)
251
252
  split_references.each do |c_reference|
252
253
  matching_collection_entries = importerexporter.entries.select do |e|
253
- (e.raw_metadata[source_identifier] == c_reference) &&
254
+ (e.raw_metadata&.[](source_identifier) == c_reference) &&
254
255
  e.is_a?(CsvCollectionEntry)
255
256
  end
256
257
  raise ::StandardError, 'Only expected to find one matching entry' if matching_collection_entries.count > 1
@@ -17,6 +17,12 @@ module Bulkrax
17
17
  parsed_metadata['file']
18
18
  end
19
19
 
20
+ def validate_presence_of_filename!
21
+ return if parsed_metadata&.[]('file')&.map(&:present?)&.any?
22
+
23
+ raise StandardError, 'File set must have a filename'
24
+ end
25
+
20
26
  def validate_presence_of_parent!
21
27
  return if parsed_metadata[related_parents_parsed_mapping]&.map(&:present?)&.any?
22
28
 
@@ -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
@@ -193,7 +217,7 @@ module Bulkrax
193
217
  instance_variable_set(instance_var, ActiveFedora::SolrService.post(
194
218
  extra_filters.to_s,
195
219
  fq: [
196
- "#{work_identifier}_sim:(#{complete_entry_identifiers.join(' OR ')})",
220
+ "#{::Solrizer.solr_name(work_identifier)}:(#{complete_entry_identifiers.join(' OR ')})",
197
221
  "has_model_ssim:(#{models_to_search.join(' OR ')})"
198
222
  ],
199
223
  fl: 'id',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '3.0.0.beta5'
4
+ VERSION = '3.0.0.beta8'
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.beta5
4
+ version: 3.0.0.beta8
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-04-27 00:00:00.000000000 Z
11
+ date: 2022-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails