-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to import FileSet metadata using the CSV Importer (#388)
* set up initial logic for importing file sets * add file set entry counter, and file set entries to importer show view * guard migrations against "duplicate column name" errors * add ApplicationParser#file_sets_total fallback * add #create_file_set to ObjectFactory, extract dynamic record lookup into module * case statements don't work as expected, change #create_file_set to more closely mirror Hyrax's AttachFilesToWorkJob * wait for the file set's work to exist before attempting to import * relationships jobs should not run in validate only mode * FileSets can have multiple files, better error messages for FileSet entries * add ability to update file set metadata * more accurate error message, remove unused comment * enqueued_records counts all entries, index is set per entry type * fix importer run counters and split them up by type * fix specs, ignore class length warning for now * add shared specs for DynamicRecordLookup#find_record * add validations to ImportFileSetJob, use descriptive params * specs for ImportFileSetJob and DynamicRecordLookup * bundler version and db/schema updates * include DynamicRecordLookup specs in ObjectFactory spec * add specs for #file_sets and #create_file_sets
- Loading branch information
1 parent
14e4992
commit 0919acf
Showing
34 changed files
with
748 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -928,4 +928,4 @@ DEPENDENCIES | |
willow_sword! | ||
|
||
BUNDLED WITH | ||
1.17.3 | ||
2.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulkrax | ||
class MissingParentError < ::StandardError; end | ||
class ImportFileSetJob < ApplicationJob | ||
include DynamicRecordLookup | ||
|
||
queue_as :import | ||
|
||
def perform(entry_id, importer_run_id) | ||
entry = Entry.find(entry_id) | ||
parent_identifier = entry.raw_metadata[entry.related_parents_raw_mapping]&.strip | ||
|
||
validate_parent!(parent_identifier) | ||
|
||
entry.build | ||
if entry.succeeded? | ||
# rubocop:disable Rails/SkipsModelValidations | ||
ImporterRun.find(importer_run_id).increment!(:processed_records) | ||
ImporterRun.find(importer_run_id).increment!(:processed_file_sets) | ||
else | ||
ImporterRun.find(importer_run_id).increment!(:failed_records) | ||
ImporterRun.find(importer_run_id).increment!(:failed_file_sets) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
ImporterRun.find(importer_run_id).decrement!(:enqueued_records) # rubocop:disable Rails/SkipsModelValidations | ||
entry.save! | ||
|
||
rescue MissingParentError => e | ||
# try waiting for the parent record to be created | ||
entry.import_attempts += 1 | ||
entry.save! | ||
if entry.import_attempts < 5 | ||
ImportFileSetJob | ||
.set(wait: (entry.import_attempts + 1).minutes) | ||
.perform_later(entry_id, importer_run_id) | ||
else | ||
ImporterRun.find(importer_run_id).decrement!(:enqueued_records) # rubocop:disable Rails/SkipsModelValidations | ||
entry.status_info(e) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :parent_record | ||
|
||
def validate_parent!(parent_identifier) | ||
# if parent_identifier is missing, it will be caught by #validate_presence_of_parent! | ||
return if parent_identifier.blank? | ||
|
||
find_parent_record(parent_identifier) | ||
check_parent_exists!(parent_identifier) | ||
check_parent_is_a_work!(parent_identifier) | ||
end | ||
|
||
def check_parent_exists!(parent_identifier) | ||
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") if parent_record.blank? | ||
end | ||
|
||
def check_parent_is_a_work!(parent_identifier) | ||
error_msg = %(A record with the ID "#{parent_identifier}" was found, but it was a #{parent_record.class}, which is not an valid/available work type) | ||
raise ::StandardError, error_msg unless curation_concern?(parent_record) | ||
end | ||
|
||
def find_parent_record(parent_identifier) | ||
@parent_record ||= find_record(parent_identifier) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.