bulkrax 3.0.1 → 3.1.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: 7810d87388103e4ff6d160e6acb64a492dcfcf16a23f93ad6848f6cc97f2d9db
4
- data.tar.gz: 75bee56959564774f20cda642b6c732cd9cb8a4fbd19222222fbac429effc949
3
+ metadata.gz: 23cd36b2c3dc13769f7d20da3c0d53f2d5c2cabef15d5beeeccee75aed6d679a
4
+ data.tar.gz: 868f0ec5c54862943e126af0ecf63d49771bc9a4ac88e566074205d7077e063c
5
5
  SHA512:
6
- metadata.gz: 74297cb60a695e46fa97389b6a9a23124c816304d636267e72585a286f370c923aefe0e10727d3a215fc8d7a1eefa579cb84cd3b84b8e8f65a72619c0c10176e
7
- data.tar.gz: 57e62164db12eb01bbfa200d612ecd0439099e257d760009b289644e93fd043e7edc3f95c08f023fed2746abfc2c57fac996b542abc0cf724794dc78bc422ddc
6
+ metadata.gz: a4f9c359a539054dba54000ca30bd1209bb862254c75463c2598807e8fd91e7e562e3bd6203f5f347ffe17da22f58d7915c1090109e88aabccac774c0281b1ee
7
+ data.tar.gz: 11c0083e67c4add719f04c01d20fac3216f6e994407dfdc48ae5f6d82696241a2b81ef6156279568b92e4bd56d3598085e83bac3718d04892a4fc96bbefd1028
@@ -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
@@ -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
@@ -105,6 +105,65 @@ module Bulkrax
105
105
  end
106
106
  end
107
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
+
108
167
  def factory
109
168
  @factory ||= Bulkrax::ObjectFactory.new(attributes: self.parsed_metadata,
110
169
  source_identifier_value: identifier,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '3.0.1'
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulkrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman