bulkrax 1.0.2 → 2.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 +4 -4
- data/README.md +1 -1
- data/app/controllers/bulkrax/exporters_controller.rb +12 -4
- data/app/controllers/bulkrax/importers_controller.rb +23 -17
- data/app/factories/bulkrax/object_factory.rb +84 -63
- data/app/jobs/bulkrax/create_relationships_job.rb +156 -0
- data/app/jobs/bulkrax/delete_work_job.rb +6 -2
- data/app/jobs/bulkrax/export_work_job.rb +3 -1
- data/app/jobs/bulkrax/exporter_job.rb +1 -0
- data/app/jobs/bulkrax/{import_work_collection_job.rb → import_collection_job.rb} +4 -2
- data/app/jobs/bulkrax/import_file_set_job.rb +69 -0
- data/app/jobs/bulkrax/import_work_job.rb +2 -0
- data/app/jobs/bulkrax/importer_job.rb +18 -1
- data/app/matchers/bulkrax/application_matcher.rb +5 -5
- data/app/models/bulkrax/csv_collection_entry.rb +8 -6
- data/app/models/bulkrax/csv_entry.rb +132 -65
- data/app/models/bulkrax/csv_file_set_entry.rb +26 -0
- data/app/models/bulkrax/entry.rb +19 -8
- data/app/models/bulkrax/exporter.rb +12 -5
- data/app/models/bulkrax/importer.rb +24 -5
- data/app/models/bulkrax/oai_entry.rb +5 -1
- data/app/models/bulkrax/rdf_entry.rb +16 -7
- data/app/models/bulkrax/xml_entry.rb +4 -0
- data/app/models/concerns/bulkrax/dynamic_record_lookup.rb +39 -0
- data/app/models/concerns/bulkrax/export_behavior.rb +2 -2
- data/app/models/concerns/bulkrax/has_matchers.rb +44 -13
- data/app/models/concerns/bulkrax/import_behavior.rb +40 -5
- data/app/models/concerns/bulkrax/importer_exporter_behavior.rb +23 -2
- data/app/models/concerns/bulkrax/status_info.rb +4 -4
- data/app/parsers/bulkrax/application_parser.rb +67 -84
- data/app/parsers/bulkrax/bagit_parser.rb +13 -4
- data/app/parsers/bulkrax/csv_parser.rb +170 -64
- data/app/parsers/bulkrax/oai_dc_parser.rb +6 -3
- data/app/parsers/bulkrax/xml_parser.rb +5 -0
- data/app/views/bulkrax/exporters/_form.html.erb +1 -1
- data/app/views/bulkrax/exporters/show.html.erb +2 -1
- data/app/views/bulkrax/importers/index.html.erb +17 -17
- data/app/views/bulkrax/importers/show.html.erb +52 -6
- data/config/locales/bulkrax.en.yml +1 -0
- data/db/migrate/20190731114016_change_importer_and_exporter_to_polymorphic.rb +5 -1
- data/db/migrate/20211004170708_change_bulkrax_statuses_error_message_column_type_to_text.rb +5 -0
- data/db/migrate/20211203195233_rename_children_counters_to_relationships.rb +6 -0
- data/db/migrate/20211220195027_add_file_set_counters_to_importer_runs.rb +7 -0
- data/db/migrate/20220118001339_add_import_attempts_to_entries.rb +5 -0
- data/db/migrate/20220119213325_add_work_counters_to_importer_runs.rb +6 -0
- data/lib/bulkrax/engine.rb +1 -1
- data/lib/bulkrax/version.rb +1 -1
- data/lib/bulkrax.rb +9 -17
- data/lib/generators/bulkrax/templates/bin/importer +17 -11
- data/lib/generators/bulkrax/templates/config/bulkrax_api.yml +3 -1
- data/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb +7 -12
- metadata +22 -10
- data/app/jobs/bulkrax/child_relationships_job.rb +0 -128
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bulkrax
|
4
|
+
module DynamicRecordLookup
|
5
|
+
# Search entries, collections, and every available work type for a record that
|
6
|
+
# has the provided identifier.
|
7
|
+
#
|
8
|
+
# @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier
|
9
|
+
# @return [Work, Collection, nil] Work or Collection if found, otherwise nil
|
10
|
+
def find_record(identifier)
|
11
|
+
record = Entry.find_by(identifier: identifier)
|
12
|
+
record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy
|
13
|
+
if record.blank?
|
14
|
+
available_work_types.each do |work_type|
|
15
|
+
record ||= work_type.where(id: identifier).first # rubocop:disable Rails/FindBy
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
record.is_a?(Entry) ? record.factory.find : record
|
20
|
+
end
|
21
|
+
|
22
|
+
# Check if the record is a Work
|
23
|
+
def curation_concern?(record)
|
24
|
+
available_work_types.include?(record.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @return [Array<Class>] list of work type classes
|
30
|
+
def available_work_types
|
31
|
+
# If running in a Hyku app, do not include disabled work types
|
32
|
+
@available_work_types ||= if defined?(::Hyku)
|
33
|
+
::Site.instance.available_works.map(&:constantize)
|
34
|
+
else
|
35
|
+
::Hyrax.config.curation_concerns
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -40,13 +40,13 @@ module Bulkrax
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
#
|
43
|
+
# Prepend the file_set id to ensure a unique filename
|
44
44
|
def filename(file_set)
|
45
45
|
return if file_set.original_file.blank?
|
46
46
|
fn = file_set.original_file.file_name.first
|
47
47
|
mime = Mime::Type.lookup(file_set.original_file.mime_type)
|
48
48
|
ext_mime = MIME::Types.of(file_set.original_file.file_name).first
|
49
|
-
if fn.include?(file_set.id)
|
49
|
+
if fn.include?(file_set.id) || importerexporter.metadata_only?
|
50
50
|
return fn if mime.to_s == ext_mime.to_s
|
51
51
|
return "#{fn}.#{mime.to_sym}"
|
52
52
|
else
|
@@ -43,7 +43,6 @@ module Bulkrax
|
|
43
43
|
|
44
44
|
value = if matcher
|
45
45
|
result = matcher.result(self, node_content)
|
46
|
-
next unless result
|
47
46
|
matched_metadata(multiple, name, result, object_multiple)
|
48
47
|
elsif multiple
|
49
48
|
Rails.logger.info("Bulkrax Column automatically matched #{node_name}, #{node_content}")
|
@@ -53,12 +52,20 @@ module Bulkrax
|
|
53
52
|
single_metadata(node_content)
|
54
53
|
end
|
55
54
|
|
56
|
-
|
55
|
+
object_name.present? ? set_parsed_object_data(object_multiple, object_name, name, index, value) : set_parsed_data(name, value)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
def set_parsed_data(
|
59
|
+
def set_parsed_data(name, value)
|
60
|
+
return parsed_metadata[name] = value unless multiple?(name)
|
61
|
+
|
62
|
+
parsed_metadata[name] ||= []
|
63
|
+
parsed_metadata[name] += Array.wrap(value).flatten
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_parsed_object_data(object_multiple, object_name, name, index, value)
|
61
67
|
if object_multiple
|
68
|
+
index ||= 0
|
62
69
|
parsed_metadata[object_name][index] ||= {}
|
63
70
|
parsed_metadata[object_name][index][name] ||= []
|
64
71
|
if value.is_a?(Array)
|
@@ -66,20 +73,13 @@ module Bulkrax
|
|
66
73
|
else
|
67
74
|
parsed_metadata[object_name][index][name] = value
|
68
75
|
end
|
69
|
-
|
76
|
+
else
|
70
77
|
parsed_metadata[object_name][name] ||= []
|
71
78
|
if value.is_a?(Array)
|
72
79
|
parsed_metadata[object_name][name] += value
|
73
80
|
else
|
74
81
|
parsed_metadata[object_name][name] = value
|
75
82
|
end
|
76
|
-
else
|
77
|
-
parsed_metadata[name] ||= []
|
78
|
-
if value.is_a?(Array)
|
79
|
-
parsed_metadata[name] += value
|
80
|
-
else
|
81
|
-
parsed_metadata[name] = value
|
82
|
-
end
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -124,12 +124,43 @@ module Bulkrax
|
|
124
124
|
field = field.gsub('_attributes', '')
|
125
125
|
|
126
126
|
return false if excluded?(field)
|
127
|
-
return true if
|
127
|
+
return true if supported_bulkrax_fields.include?(field)
|
128
128
|
return factory_class.method_defined?(field) && factory_class.properties[field].present?
|
129
129
|
end
|
130
130
|
|
131
|
+
def supported_bulkrax_fields
|
132
|
+
ActiveSupport::Deprecation.warn(
|
133
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
134
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
135
|
+
)
|
136
|
+
@supported_bulkrax_fields ||=
|
137
|
+
%W[
|
138
|
+
id
|
139
|
+
file
|
140
|
+
remote_files
|
141
|
+
model
|
142
|
+
delete
|
143
|
+
#{parser.collection_field_mapping}
|
144
|
+
#{related_parents_parsed_mapping}
|
145
|
+
#{related_children_parsed_mapping}
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
131
149
|
def multiple?(field)
|
132
|
-
|
150
|
+
ActiveSupport::Deprecation.warn(
|
151
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
152
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
153
|
+
)
|
154
|
+
@multiple_bulkrax_fields ||=
|
155
|
+
%W[
|
156
|
+
file
|
157
|
+
remote_files
|
158
|
+
#{parser.collection_field_mapping}
|
159
|
+
#{related_parents_parsed_mapping}
|
160
|
+
#{related_children_parsed_mapping}
|
161
|
+
]
|
162
|
+
|
163
|
+
return true if @multiple_bulkrax_fields.include?(field)
|
133
164
|
return false if field == 'model'
|
134
165
|
|
135
166
|
field_supported?(field) && factory_class&.properties&.[](field)&.[]('multiple')
|
@@ -11,6 +11,8 @@ module Bulkrax
|
|
11
11
|
unless self.importerexporter.validate_only
|
12
12
|
raise CollectionsCreatedError unless collections_created?
|
13
13
|
@item = factory.run!
|
14
|
+
parent_jobs if self.parsed_metadata[related_parents_parsed_mapping].present?
|
15
|
+
child_jobs if self.parsed_metadata[related_children_parsed_mapping].present?
|
14
16
|
end
|
15
17
|
rescue RSolr::Error::Http, CollectionsCreatedError => e
|
16
18
|
raise e
|
@@ -22,7 +24,23 @@ module Bulkrax
|
|
22
24
|
return @item
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
27
|
+
def parent_jobs
|
28
|
+
self.parsed_metadata[related_parents_parsed_mapping].each do |parent_identifier|
|
29
|
+
next if parent_identifier.blank?
|
30
|
+
|
31
|
+
CreateRelationshipsJob.perform_later(entry_identifier: self.identifier, parent_identifier: parent_identifier, importer_run: self.last_run)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def child_jobs
|
36
|
+
self.parsed_metadata[related_children_parsed_mapping].each do |child_identifier|
|
37
|
+
next if child_identifier.blank?
|
38
|
+
|
39
|
+
CreateRelationshipsJob.perform_later(entry_identifier: self.identifier, child_identifier: child_identifier, importer_run: self.last_run)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_collection_ids
|
26
44
|
self.collection_ids
|
27
45
|
end
|
28
46
|
|
@@ -57,15 +75,28 @@ module Bulkrax
|
|
57
75
|
end
|
58
76
|
|
59
77
|
def add_collections
|
60
|
-
return if
|
61
|
-
|
62
|
-
|
78
|
+
return if find_collection_ids.blank?
|
79
|
+
|
80
|
+
ActiveSupport::Deprecation.warn(
|
81
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
82
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
83
|
+
)
|
84
|
+
self.parsed_metadata['member_of_collections_attributes'] = {}
|
85
|
+
find_collection_ids.each_with_index do |c, i|
|
86
|
+
self.parsed_metadata['member_of_collections_attributes'][i.to_s] = { id: c }
|
87
|
+
end
|
63
88
|
end
|
64
89
|
|
65
90
|
def factory
|
91
|
+
ActiveSupport::Deprecation.warn(
|
92
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
93
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
94
|
+
)
|
66
95
|
@factory ||= Bulkrax::ObjectFactory.new(attributes: self.parsed_metadata,
|
67
96
|
source_identifier_value: identifier,
|
68
97
|
work_identifier: parser.work_identifier,
|
98
|
+
collection_field_mapping: parser.collection_field_mapping,
|
99
|
+
related_parents_parsed_mapping: related_parents_parsed_mapping,
|
69
100
|
replace_files: replace_files,
|
70
101
|
user: user,
|
71
102
|
klass: factory_class,
|
@@ -80,7 +111,11 @@ module Bulkrax
|
|
80
111
|
else
|
81
112
|
Bulkrax.default_work_type
|
82
113
|
end
|
83
|
-
|
114
|
+
|
115
|
+
# return the name of the collection or work
|
116
|
+
fc.tr!(' ', '_')
|
117
|
+
fc.downcase! if fc.match?(/[-_]/)
|
118
|
+
fc.camelcase.constantize
|
84
119
|
rescue NameError
|
85
120
|
nil
|
86
121
|
rescue
|
@@ -20,15 +20,36 @@ module Bulkrax
|
|
20
20
|
(last_imported_at || Time.current) + frequency.to_seconds if schedulable? && last_imported_at.present?
|
21
21
|
end
|
22
22
|
|
23
|
-
def increment_counters(index, collection
|
23
|
+
def increment_counters(index, collection: false, file_set: false)
|
24
24
|
# Only set the totals if they were not set on initialization
|
25
25
|
if collection
|
26
26
|
current_run.total_collection_entries = index + 1 unless parser.collections_total.positive?
|
27
|
+
elsif file_set
|
28
|
+
current_run.total_file_set_entries = index + 1 unless parser.file_sets_total.positive?
|
27
29
|
else
|
30
|
+
# TODO: differentiate between work and collection counts for exporters
|
28
31
|
current_run.total_work_entries = index + 1 unless limit.to_i.positive? || parser.total.positive?
|
29
32
|
end
|
30
|
-
current_run.enqueued_records
|
33
|
+
current_run.enqueued_records += 1
|
31
34
|
current_run.save!
|
32
35
|
end
|
36
|
+
|
37
|
+
def keys_without_numbers(keys)
|
38
|
+
keys.map { |key| key_without_numbers(key) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def key_without_numbers(key)
|
42
|
+
key.gsub(/_\d+/, '').sub(/^\d+_/, '')
|
43
|
+
end
|
44
|
+
|
45
|
+
# Is this a file?
|
46
|
+
def file?
|
47
|
+
parser_fields&.[]('import_file_path') && File.file?(parser_fields['import_file_path'])
|
48
|
+
end
|
49
|
+
|
50
|
+
# Is this a zip file?
|
51
|
+
def zip?
|
52
|
+
parser_fields&.[]('import_file_path') && MIME::Types.type_for(parser_fields['import_file_path']).include?('application/zip')
|
53
|
+
end
|
33
54
|
end
|
34
55
|
end
|
@@ -33,13 +33,13 @@ module Bulkrax
|
|
33
33
|
current_status&.created_at
|
34
34
|
end
|
35
35
|
|
36
|
-
def status_info(e = nil)
|
36
|
+
def status_info(e = nil, current_run = nil)
|
37
37
|
if e.nil?
|
38
|
-
self.statuses.create!(status_message: 'Complete', runnable: last_run)
|
38
|
+
self.statuses.create!(status_message: 'Complete', runnable: current_run || last_run)
|
39
39
|
elsif e.is_a?(String)
|
40
|
-
self.statuses.create!(status_message: e, runnable: last_run)
|
40
|
+
self.statuses.create!(status_message: e, runnable: current_run || last_run)
|
41
41
|
else
|
42
|
-
self.statuses.create!(status_message: 'Failed', runnable: last_run, error_class: e.class.to_s, error_message: e.message, error_backtrace: e.backtrace)
|
42
|
+
self.statuses.create!(status_message: 'Failed', runnable: current_run || last_run, error_class: e.class.to_s, error_message: e.message, error_backtrace: e.backtrace)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bulkrax
|
4
|
-
class ApplicationParser
|
5
|
-
attr_accessor :importerexporter
|
4
|
+
class ApplicationParser # rubocop:disable Metrics/ClassLength
|
5
|
+
attr_accessor :importerexporter, :headers
|
6
6
|
alias importer importerexporter
|
7
7
|
alias exporter importerexporter
|
8
|
-
delegate :only_updates, :limit, :current_run, :errors,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
delegate :only_updates, :limit, :current_run, :errors, :mapping,
|
9
|
+
:seen, :increment_counters, :parser_fields, :user, :keys_without_numbers,
|
10
|
+
:key_without_numbers, :status, :status_info, :status_at,
|
11
|
+
:exporter_export_path, :exporter_export_zip_path, :importer_unzip_path, :validate_only,
|
12
|
+
to: :importerexporter
|
13
13
|
|
14
14
|
def self.parser_fields
|
15
15
|
{}
|
@@ -25,6 +25,7 @@ module Bulkrax
|
|
25
25
|
|
26
26
|
def initialize(importerexporter)
|
27
27
|
@importerexporter = importerexporter
|
28
|
+
@headers = []
|
28
29
|
end
|
29
30
|
|
30
31
|
# @api
|
@@ -43,20 +44,54 @@ module Bulkrax
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def source_identifier
|
46
|
-
@source_identifier ||=
|
47
|
+
@source_identifier ||= get_field_mapping_hash_for('source_identifier')&.values&.first&.[]('from')&.first&.to_sym || :source_identifier
|
47
48
|
end
|
48
49
|
|
49
50
|
def work_identifier
|
50
|
-
@work_identifier ||=
|
51
|
+
@work_identifier ||= get_field_mapping_hash_for('source_identifier')&.keys&.first&.to_sym || :source
|
51
52
|
end
|
52
53
|
|
53
|
-
def
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def related_parents_raw_mapping
|
55
|
+
@related_parents_raw_mapping ||= get_field_mapping_hash_for('related_parents_field_mapping')&.values&.first&.[]('from')&.first
|
56
|
+
end
|
57
|
+
|
58
|
+
def related_parents_parsed_mapping
|
59
|
+
@related_parents_parsed_mapping ||= get_field_mapping_hash_for('related_parents_field_mapping')&.keys&.first
|
60
|
+
end
|
61
|
+
|
62
|
+
def related_children_raw_mapping
|
63
|
+
@related_children_raw_mapping ||= get_field_mapping_hash_for('related_children_field_mapping')&.values&.first&.[]('from')&.first
|
64
|
+
end
|
65
|
+
|
66
|
+
def related_children_parsed_mapping
|
67
|
+
@related_children_parsed_mapping ||= get_field_mapping_hash_for('related_children_field_mapping')&.keys&.first
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_field_mapping_hash_for(key)
|
71
|
+
return instance_variable_get("@#{key}_hash") if instance_variable_get("@#{key}_hash").present?
|
72
|
+
|
73
|
+
instance_variable_set(
|
74
|
+
"@#{key}_hash",
|
75
|
+
importerexporter.mapping.with_indifferent_access.select { |_, h| h.key?(key) }
|
76
|
+
)
|
77
|
+
raise StandardError, "more than one #{key} declared: #{instance_variable_get("@#{key}_hash").keys.join(', ')}" if instance_variable_get("@#{key}_hash").length > 1
|
78
|
+
|
79
|
+
instance_variable_get("@#{key}_hash")
|
80
|
+
end
|
81
|
+
|
82
|
+
def collection_field_mapping
|
83
|
+
ActiveSupport::Deprecation.warn(
|
84
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
85
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
86
|
+
)
|
87
|
+
Bulkrax.collection_field_mapping[self.entry_class.to_s]&.to_sym || :collection
|
88
|
+
end
|
89
|
+
|
90
|
+
def model_field_mappings
|
91
|
+
model_mappings = Bulkrax.field_mappings[self.class.to_s]&.dig('model', :from) || []
|
92
|
+
model_mappings |= ['model']
|
58
93
|
|
59
|
-
|
94
|
+
model_mappings
|
60
95
|
end
|
61
96
|
|
62
97
|
def perform_method
|
@@ -79,6 +114,10 @@ module Bulkrax
|
|
79
114
|
raise StandardError, 'must be defined' if importer?
|
80
115
|
end
|
81
116
|
|
117
|
+
def create_file_sets
|
118
|
+
raise StandardError, 'must be defined' if importer?
|
119
|
+
end
|
120
|
+
|
82
121
|
# Optional, define if using browse everything for file upload
|
83
122
|
def retrieve_cloud_files(files); end
|
84
123
|
|
@@ -91,76 +130,19 @@ module Bulkrax
|
|
91
130
|
path
|
92
131
|
end
|
93
132
|
|
133
|
+
# Base path for imported and exported files
|
134
|
+
def base_path(type = 'import')
|
135
|
+
ENV['HYKU_MULTITENANT'] ? File.join(Bulkrax.send("#{type}_path"), Site.instance.account.name) : Bulkrax.send("#{type}_path")
|
136
|
+
end
|
137
|
+
|
94
138
|
# Path where we'll store the import metadata and files
|
95
139
|
# this is used for uploaded and cloud files
|
96
140
|
def path_for_import
|
97
|
-
@path_for_import = File.join(
|
141
|
+
@path_for_import = File.join(base_path, importerexporter.path_string)
|
98
142
|
FileUtils.mkdir_p(@path_for_import) unless File.exist?(@path_for_import)
|
99
143
|
@path_for_import
|
100
144
|
end
|
101
145
|
|
102
|
-
# Optional, only used by certain parsers
|
103
|
-
# Other parsers should override with a custom or empty method
|
104
|
-
# Will be skipped unless the #record is a Hash
|
105
|
-
def create_parent_child_relationships
|
106
|
-
parents.each do |key, value|
|
107
|
-
parent = entry_class.where(
|
108
|
-
identifier: key,
|
109
|
-
importerexporter_id: importerexporter.id,
|
110
|
-
importerexporter_type: 'Bulkrax::Importer'
|
111
|
-
).first
|
112
|
-
|
113
|
-
# not finding the entries here indicates that the given identifiers are incorrect
|
114
|
-
# in that case we should log that
|
115
|
-
children = value.map do |child|
|
116
|
-
entry_class.where(
|
117
|
-
identifier: child,
|
118
|
-
importerexporter_id: importerexporter.id,
|
119
|
-
importerexporter_type: 'Bulkrax::Importer'
|
120
|
-
).first
|
121
|
-
end.compact.uniq
|
122
|
-
|
123
|
-
if parent.present? && (children.length != value.length)
|
124
|
-
# Increment the failures for the number we couldn't find
|
125
|
-
# Because all of our entries have been created by now, if we can't find them, the data is wrong
|
126
|
-
Rails.logger.error("Expected #{value.length} children for parent entry #{parent.id}, found #{children.length}")
|
127
|
-
break if children.empty?
|
128
|
-
Rails.logger.warn("Adding #{children.length} children to parent entry #{parent.id} (expected #{value.length})")
|
129
|
-
end
|
130
|
-
parent_id = parent.id
|
131
|
-
child_entry_ids = children.map(&:id)
|
132
|
-
ChildRelationshipsJob.perform_later(parent_id, child_entry_ids, current_run.id)
|
133
|
-
end
|
134
|
-
rescue StandardError => e
|
135
|
-
status_info(e)
|
136
|
-
end
|
137
|
-
|
138
|
-
def parents
|
139
|
-
@parents ||= setup_parents
|
140
|
-
end
|
141
|
-
|
142
|
-
def setup_parents
|
143
|
-
pts = []
|
144
|
-
records.each do |record|
|
145
|
-
r = if record.respond_to?(:to_h)
|
146
|
-
record.to_h
|
147
|
-
else
|
148
|
-
record
|
149
|
-
end
|
150
|
-
next unless r.is_a?(Hash)
|
151
|
-
children = if r[:children].is_a?(String)
|
152
|
-
r[:children].split(/\s*[:;|]\s*/)
|
153
|
-
else
|
154
|
-
r[:children]
|
155
|
-
end
|
156
|
-
next if children.blank?
|
157
|
-
pts << {
|
158
|
-
r[source_identifier] => children
|
159
|
-
}
|
160
|
-
end
|
161
|
-
pts.blank? ? pts : pts.inject(:merge)
|
162
|
-
end
|
163
|
-
|
164
146
|
def setup_export_file
|
165
147
|
raise StandardError, 'must be defined' if exporter?
|
166
148
|
end
|
@@ -256,6 +238,10 @@ module Bulkrax
|
|
256
238
|
0
|
257
239
|
end
|
258
240
|
|
241
|
+
def file_sets_total
|
242
|
+
0
|
243
|
+
end
|
244
|
+
|
259
245
|
def write
|
260
246
|
write_files
|
261
247
|
zip
|
@@ -288,12 +274,9 @@ module Bulkrax
|
|
288
274
|
private
|
289
275
|
|
290
276
|
def real_import_file_path
|
291
|
-
if file? && zip?
|
292
|
-
|
293
|
-
|
294
|
-
else
|
295
|
-
parser_fields['import_file_path']
|
296
|
-
end
|
277
|
+
return importer_unzip_path if file? && zip?
|
278
|
+
|
279
|
+
parser_fields['import_file_path']
|
297
280
|
end
|
298
281
|
end
|
299
282
|
end
|
@@ -40,7 +40,7 @@ module Bulkrax
|
|
40
40
|
raise StandardError, 'No metadata files were found' if path.blank?
|
41
41
|
data = entry_class.read_data(path)
|
42
42
|
data = entry_class.data_for_entry(data, source_identifier)
|
43
|
-
data[:file] = bag.bag_files.join('|')
|
43
|
+
data[:file] = bag.bag_files.join('|') unless importerexporter.metadata_only?
|
44
44
|
data
|
45
45
|
end
|
46
46
|
end
|
@@ -58,8 +58,8 @@ module Bulkrax
|
|
58
58
|
collection_type_gid: Hyrax::CollectionType.find_or_create_default_collection_type.gid
|
59
59
|
}
|
60
60
|
new_entry = find_or_create_entry(collection_entry_class, collection, 'Bulkrax::Importer', metadata)
|
61
|
-
|
62
|
-
increment_counters(index, true)
|
61
|
+
ImportCollectionJob.perform_now(new_entry.id, current_run.id)
|
62
|
+
increment_counters(index, collection: true)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -83,13 +83,22 @@ module Bulkrax
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def collections
|
86
|
-
|
86
|
+
ActiveSupport::Deprecation.warn(
|
87
|
+
'Creating Collections using the collection_field_mapping will no longer be supported as of Bulkrax version 3.0.' \
|
88
|
+
' Please configure Bulkrax to use related_parents_field_mapping and related_children_field_mapping instead.'
|
89
|
+
)
|
90
|
+
records.map { |r| r[collection_field_mapping].split(/\s*[;|]\s*/) if r[collection_field_mapping].present? }.flatten.compact.uniq
|
87
91
|
end
|
88
92
|
|
89
93
|
def collections_total
|
90
94
|
collections.size
|
91
95
|
end
|
92
96
|
|
97
|
+
# TODO: change to differentiate between collection and work records when adding ability to import collection metadata
|
98
|
+
def works_total
|
99
|
+
total
|
100
|
+
end
|
101
|
+
|
93
102
|
def total
|
94
103
|
metadata_paths.count
|
95
104
|
end
|