bulkrax 3.0.0.beta8 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cfcae9e154506ea5b6699b530da3f2d370d478963de1cb5ce854db1e0ded3ed
4
- data.tar.gz: 7b1511cbaad98ef523ac5c1f53442d0f568b7088aba2312df77e104c41c8e192
3
+ metadata.gz: 23cd36b2c3dc13769f7d20da3c0d53f2d5c2cabef15d5beeeccee75aed6d679a
4
+ data.tar.gz: 868f0ec5c54862943e126af0ecf63d49771bc9a4ac88e566074205d7077e063c
5
5
  SHA512:
6
- metadata.gz: af73e975cd84be460ff29e2364a79e4fdae77793ca2a1b50534b8582e602138bd9c700af2068221907eee055f593f2305afab6d304385ba4f53e5ed72c64678f
7
- data.tar.gz: 06bc7006d8b701dda2dd68487252e563f8b46484012124d5f81e43d3aa8af4916ba3c378948ad91157dce125768e2ea01e117673288fc8dbe1e9001cef03eb7e
6
+ metadata.gz: a4f9c359a539054dba54000ca30bd1209bb862254c75463c2598807e8fd91e7e562e3bd6203f5f347ffe17da22f58d7915c1090109e88aabccac774c0281b1ee
7
+ data.tar.gz: 11c0083e67c4add719f04c01d20fac3216f6e994407dfdc48ae5f6d82696241a2b81ef6156279568b92e4bd56d3598085e83bac3718d04892a4fc96bbefd1028
@@ -82,18 +82,18 @@ module Bulkrax
82
82
  # Work-Collection membership is added to the child as member_of_collection_ids
83
83
  # This is adding the reverse relationship, from the child to the parent
84
84
  def collection_parent_work_child
85
- child_records[:works].each do |child_record|
86
- ::Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: parent_record, child: child_record)
87
- # TODO: add counters for :processed_parents and :failed_parents
88
- Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
89
- end
85
+ child_work_ids = child_records[:works].map(&:id)
86
+ parent_record.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
87
+
88
+ parent_record.add_member_objects(child_work_ids)
89
+ ImporterRun.find(importer_run_id).increment!(:processed_relationships, child_work_ids.count) # rubocop:disable Rails/SkipsModelValidations
90
90
  end
91
91
 
92
92
  # Collection-Collection membership is added to the as member_ids
93
93
  def collection_parent_collection_child
94
94
  child_records[:collections].each do |child_record|
95
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
96
+ ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
97
97
  end
98
98
  end
99
99
 
@@ -103,14 +103,12 @@ module Bulkrax
103
103
  child_records[:works].each_with_index do |child_record, i|
104
104
  records_hash[i] = { id: child_record.id }
105
105
  end
106
- attrs = {
107
- work_members_attributes: records_hash
108
- }
109
- parent_record.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX if parent_record.respond_to?(:reindex_extent)
106
+ attrs = { work_members_attributes: records_hash }
107
+ parent_record.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
110
108
  env = Hyrax::Actors::Environment.new(parent_record, Ability.new(user), attrs)
109
+
111
110
  Hyrax::CurationConcern.actor.update(env)
112
- # TODO: add counters for :processed_parents and :failed_parents
113
- Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations
111
+ ImporterRun.find(importer_run_id).increment!(:processed_relationships, child_records[:works].count) # rubocop:disable Rails/SkipsModelValidations
114
112
  end
115
113
 
116
114
  def reschedule(parent_identifier:, importer_run_id:)
@@ -27,6 +27,7 @@ module Bulkrax
27
27
  end
28
28
  exporter_run = ExporterRun.find(args[1])
29
29
  return entry if exporter_run.enqueued_records.positive?
30
+
30
31
  if exporter_run.failed_records.positive?
31
32
  exporter_run.exporter.status_info('Complete (with failures)')
32
33
  else
@@ -46,6 +46,7 @@ module Bulkrax
46
46
  add_visibility
47
47
  add_metadata_for_model
48
48
  add_rights_statement
49
+ sanitize_controlled_uri_values!
49
50
  add_local
50
51
 
51
52
  self.parsed_metadata
@@ -96,7 +96,8 @@ module Bulkrax
96
96
  end
97
97
 
98
98
  def current_run
99
- @current_run ||= self.exporter_runs.create!(total_work_entries: self.limit || parser.total)
99
+ total = self.limit || parser.total
100
+ @current_run ||= self.exporter_runs.create!(total_work_entries: total, enqueued_records: total)
100
101
  end
101
102
 
102
103
  def last_run
@@ -142,7 +142,7 @@ module Bulkrax
142
142
 
143
143
  def import_objects(types_array = nil)
144
144
  self.only_updates ||= false
145
- types = types_array || %w[work collection file_set relationship]
145
+ types = types_array || %w[collection work file_set relationship]
146
146
  if parser.class == Bulkrax::CsvParser
147
147
  parser.create_objects(types)
148
148
  else
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bulkrax
4
4
  # Import Behavior for Entry classes
5
- module ImportBehavior
5
+ module ImportBehavior # rubocop:disable Metrics/ModuleLength
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  def build_for_importer
@@ -21,6 +21,8 @@ module Bulkrax
21
21
  status_info(e)
22
22
  else
23
23
  status_info
24
+ ensure
25
+ self.save!
24
26
  end
25
27
  return @item
26
28
  end
@@ -103,6 +105,65 @@ module Bulkrax
103
105
  end
104
106
  end
105
107
 
108
+ # Attempt to sanitize Questioning Authority URI values for configured controlled fields of common
109
+ # data entry mistakes. Controlled URI values are only valid if they are an exact match.
110
+ # Example:
111
+ # Valid value: http://rightsstatements.org/vocab/InC/1.0/
112
+ # Provided value: https://rightsstatements.org/vocab/InC/1.0
113
+ # Sanitized value: http://rightsstatements.org/vocab/InC/1.0/ ("s" from "https" removed, trailing "/" added)
114
+ #
115
+ # @return [Boolean] true if all controlled URI values are sanitized successfully
116
+ def sanitize_controlled_uri_values!
117
+ Bulkrax.qa_controlled_properties.each do |field|
118
+ next if parsed_metadata[field].blank?
119
+
120
+ parsed_metadata[field].each_with_index do |value, i|
121
+ next if value.blank?
122
+
123
+ if (validated_uri_value = validate_value(value, field))
124
+ parsed_metadata[field][i] = validated_uri_value
125
+ else
126
+ debug_msg = %(Unable to locate active authority ID "#{value}" in config/authorities/#{field.pluralize}.yml)
127
+ Rails.logger.debug(debug_msg)
128
+ error_msg = %("#{value}" is not a valid and/or active authority ID for the :#{field} field)
129
+ raise ::StandardError, error_msg
130
+ end
131
+ end
132
+ end
133
+
134
+ true
135
+ end
136
+
137
+ # @param value [String] value to validate
138
+ # @param field [String] name of the controlled property
139
+ # @return [String, nil] validated URI value or nil
140
+ def validate_value(value, field)
141
+ if value.match?(::URI::DEFAULT_PARSER.make_regexp)
142
+ value = value.strip.chomp
143
+ # add trailing forward slash unless one is already present
144
+ value << '/' unless value.match?(%r{/$})
145
+ end
146
+
147
+ valid = if active_id_for_authority?(value, field)
148
+ true
149
+ else
150
+ value.include?('https') ? value.sub!('https', 'http') : value.sub!('http', 'https')
151
+ active_id_for_authority?(value, field)
152
+ end
153
+
154
+ valid ? value : nil
155
+ end
156
+
157
+ # @param value [String] value to check
158
+ # @param field [String] name of the controlled property
159
+ # @return [Boolean] provided value is a present, active authority ID for the provided field
160
+ def active_id_for_authority?(value, field)
161
+ field_service = ('Hyrax::' + "#{field}_service".camelcase).constantize
162
+ active_authority_ids = field_service.new.active_elements.map { |ae| ae['id'] }
163
+
164
+ active_authority_ids.include?(value)
165
+ end
166
+
106
167
  def factory
107
168
  @factory ||= Bulkrax::ObjectFactory.new(attributes: self.parsed_metadata,
108
169
  source_identifier_value: identifier,
@@ -270,7 +270,7 @@ module Bulkrax
270
270
  # Changed to grep as wc -l counts blank lines, and ignores the final unescaped line (which may or may not contain data)
271
271
  def total
272
272
  @total = importer.parser_fields['total'] || 0 if importer?
273
- @total = importerexporter.entries.count if exporter?
273
+ @total = limit || current_record_ids.count if exporter?
274
274
 
275
275
  return @total || 0
276
276
  rescue StandardError
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '3.0.0.beta8'
4
+ VERSION = '3.1.0'
5
5
  end
data/lib/bulkrax.rb CHANGED
@@ -12,13 +12,13 @@ module Bulkrax
12
12
  :related_children_field_mapping,
13
13
  :related_parents_field_mapping,
14
14
  :reserved_properties,
15
+ :qa_controlled_properties,
15
16
  :field_mappings,
16
17
  :import_path,
17
18
  :export_path,
18
19
  :removed_image_path,
19
20
  :server_name,
20
- :api_definition,
21
- :removed_image_path
21
+ :api_definition
22
22
 
23
23
  self.parsers = [
24
24
  { name: "OAI - Dublin Core", class_name: "Bulkrax::OaiDcParser", partial: "oai_fields" },
@@ -119,6 +119,11 @@ module Bulkrax
119
119
  original_url
120
120
  relative_path
121
121
  ]
122
+
123
+ # List of Questioning Authority properties that are controlled via YAML files in
124
+ # the config/authorities/ directory. For example, the :rights_statement property
125
+ # is controlled by the active terms in config/authorities/rights_statements.yml
126
+ self.qa_controlled_properties = %w[rights_statement license]
122
127
  end
123
128
 
124
129
  def self.api_definition
@@ -131,8 +136,6 @@ module Bulkrax
131
136
  )
132
137
  end
133
138
 
134
- self.removed_image_path = 'app/assets/images/bulkrax/removed.png'
135
-
136
139
  # this function maps the vars from your app into your engine
137
140
  def self.setup
138
141
  yield self
@@ -61,6 +61,12 @@ Bulkrax.setup do |config|
61
61
 
62
62
  # Properties that should not be used in imports/exports. They are reserved for use by Hyrax.
63
63
  # config.reserved_properties += ['my_field']
64
+
65
+ # List of Questioning Authority properties that are controlled via YAML files in
66
+ # the config/authorities/ directory. For example, the :rights_statement property
67
+ # is controlled by the active terms in config/authorities/rights_statements.yml
68
+ # Defaults: 'rights_statement' and 'license'
69
+ # config.qa_controlled_properties += ['my_field']
64
70
  end
65
71
 
66
72
  # Sidebar for hyrax 3+ support
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.beta8
4
+ version: 3.1.0
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-05-11 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -393,9 +393,9 @@ 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
400
  rubygems_version: 3.1.4
401
401
  signing_key: