Skip to content

Commit

Permalink
BP errors re work (#1452)
Browse files Browse the repository at this point in the history
Co-authored-by: JP Engstrom <jpengstrom@macbook-pro.lan>
  • Loading branch information
JP Engstrom and JP Engstrom authored Oct 25, 2024
1 parent d1e8503 commit bf2fff6
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/jobs/setup_metadata_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def perform(parent_object, current_batch_process, current_batch_connection = par
end
unless parent_object.default_fetch(current_batch_process, current_batch_connection)
# Don't retry in this case. default_fetch() will throw an exception if it's a network error and trigger retry
parent_object.processing_event("Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information and that the descriptive records are public and/or published.", "failed")
parent_object.processing_event("Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information and that the descriptive records are public and/or published. ------------ Message from System: SetupMetadataJob failed to retrieve authoritative metadata. [#{parent_object.metadata_cloud_url}]", "failed")
return
end

Expand All @@ -34,9 +34,9 @@ def perform(parent_object, current_batch_process, current_batch_connection = par
end
setup_child_object_jobs(parent_object, current_batch_process)
index_private(parent_object)
rescue
rescue => e
parent_object.processing_event(
"Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information, you have included a record source (ils or aspace), and, for aspace records, that you have included the public Archives at Yale address for the record.", "failed"
"Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information, you have included a record source (ils or aspace), and, for aspace records, that you have included the public Archives at Yale address for the record. ------------ Message from System: Setup job failed to save: #{e.message}", "failed"
)
raise # this reraises the error after we document it
end
Expand Down
5 changes: 1 addition & 4 deletions app/lib/preservica_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def get(uri)
return get_body(uri) unless block_given?
authenticated_get URI("#{@host}#{uri}") do |http, request|
http.request request do |response|
unless response.is_a? Net::HTTPSuccess
raise StandardError,
"The given URI does not match the URI of an entity of this type in Preservica. Please make sure your Preservica URI and object structure type is correct."
end
raise StandardError, "Request error #{response.code} #{response.body}" unless response.is_a? Net::HTTPSuccess
response.read_body do |chunk|
yield chunk
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/child_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def width_and_height(size)
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Layout/LineLength
def convert_to_ptiff
Rails.logger.info "************ child_object.rb # convert_to_ptiff +++ is the ptiff valid? #{pyramidal_tiff.valid?} *************"
if pyramidal_tiff.valid?
Expand All @@ -172,7 +173,7 @@ def convert_to_ptiff
true
else
report_ptiff_generation_error
raise "The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance."
raise "The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance. ------------ Message from System: Child Object #{oid} failed to convert PTIFF due to #{pyramidal_tiff.errors.full_messages.join('\n')}"
end
end
# rubocop:disable Metrics/AbcSize
Expand All @@ -183,8 +184,8 @@ def convert_to_ptiff
def report_ptiff_generation_error
Rails.logger.info "************ child_object.rb # report_ptiff_generation_error +++ hits method *************"
Rails.logger.info "************ child_object.rb # report_ptiff_generation_error +++ ptiff errors: #{pyramidal_tiff.errors.full_messages.join("\n")} *************"
parent_object&.processing_event("The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance.", "failed")
processing_event("The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance.", "failed")
parent_object&.processing_event("The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance. ------------ Message from System: Child Object #{oid} failed to convert PTIFF due to #{pyramidal_tiff.errors.full_messages.join("\n")}", "failed")
processing_event("The child object's image file cannot be found. Please contact the Technical Lead for Digital Collections for assistance. ------------ Message from System: Child Object #{oid} failed to convert PTIFF due to #{pyramidal_tiff.errors.full_messages.join("\n")}", "failed")
end

def convert_to_ptiff!(force = false)
Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/create_parent_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def create_new_parent_csv
next
rescue PreservicaImageService::PreservicaImageServiceError => e
if e.message.include?("bad URI")
batch_processing_event("The given URI does not match the URI of an entity in Preservica. Please make sure your URI is correct, starts with /structure-object/ or /information-object/, and includes no spaces or line breaks.", "Skipped Row")
batch_processing_event("The given URI does not match the URI of an entity in Preservica. Please make sure your URI is correct, starts with /structure-object/ or /information-object/, and includes no spaces or line breaks. ------------ Message from System: Skipping row [#{index + 2}] #{e.message}.", "Skipped Row")
elsif e.message.include?("entity.does.not.exist")
batch_processing_event("The given URI does not match the URI of an entity of this type in Preservica. Please make sure your Preservica URI and object structure type is correct. ------------ Message from System: Skipping row [#{index + 2}] #{e.message}.", "Skipped Row")
else
batch_processing_event("Skipping row [#{index + 2}] #{e.message}.", "Skipped Row")
end
Expand Down Expand Up @@ -116,7 +118,6 @@ def create_new_parent_csv
end
end
end
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/PerceivedComplexity
Expand All @@ -129,8 +130,7 @@ def editable_admin_set(admin_set_key, oid, index)
admin_sets_hash[admin_set_key] ||= AdminSet.find_by(key: admin_set_key)
admin_set = admin_sets_hash[admin_set_key]
if admin_set.blank?
batch_processing_event("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct.",
'Skipped Row')
batch_processing_event("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct. ------------ Message from System: Skipping row [#{index + 2}] with unknown admin set [#{admin_set_key}] for parent: #{oid}", 'Skipped Row')
false
elsif !current_ability.can?(:add_member, admin_set)
batch_processing_event("Skipping row [#{index + 2}] because #{user.uid} does not have permission to create or update parent: #{oid}", 'Permission Denied')
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/updatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ def update_parent_objects
# rubocop:enable Metrics/BlockLength
# rubocop:enable Metrics/MethodLength

# rubocop:disable Layout/LineLength
# CHECKS TO SEE IF USER HAS ABILITY TO EDIT AN ADMIN SET:
def editable_admin_set(admin_set_key, oid, index)
admin_sets_hash = {}
admin_sets_hash[admin_set_key] ||= AdminSet.find_by(key: admin_set_key)
admin_set = admin_sets_hash[admin_set_key]
if admin_set.blank?
batch_processing_event("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct.",
batch_processing_event("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct. ------------ Message from System: Skipping row [#{index + 2}] with unknown admin set [#{admin_set_key}] for parent: #{oid}",
'Skipped Row')
false
elsif !current_ability.can?(:add_member, admin_set)
Expand Down
4 changes: 3 additions & 1 deletion app/models/preservica/bitstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def bits

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# rubocop:disable Layout/LineLength
def download_to_file(file_name)
Rails.logger.info "************ bitstream.rb # download_to_file +++ hits download to file method with file: #{file_name} *************"
attempt ||= 1
Expand All @@ -55,14 +56,15 @@ def download_to_file(file_name)
Rails.logger.info "************ bitstream.rb # download_to_file +++ grabs sha checksum (data_sha512): #{data_sha512} *************"
unless data_sha512.casecmp?(sha512_checksum)
raise StandardError,
"The checksum for this object is different than the checksum that DCS expected. Please ensure your image folder in Preservica has SHA-512 fixity checksums."
"The checksum for this object is different than the checksum that DCS expected. Please ensure your image folder in Preservica has SHA-512 fixity checksums. ------------ Message from System: Checksum mismatch for Child Object: #{co_oid} - (#{data_sha512} != #{sha512_checksum})"
end
raise StandardError, "Data size did not match for Child Object: #{co_oid} - (#{data_length} != #{size})" unless data_length == size
raise StandardError, "File sizes do not match for Child Object: #{co_oid} - (#{file_size} != #{size})" unless file_size == size
# could also check: Digest::SHA512.file(file_name).hexdigest == sha512_checksum, but probably not necessary
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
# rubocop:enable Layout/LineLength

def xml
@xml ||= Nokogiri::XML(preservica_client.content_object_generation_bitstream(@content_id, @generation_id, @id)).remove_namespaces!
Expand Down
2 changes: 1 addition & 1 deletion app/services/csv_row_parent_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def admin_set
admin_sets_hash[admin_set_key] ||= AdminSet.find_by(key: admin_set_key)
admin_set = admin_sets_hash[admin_set_key]

raise BatchProcessingError.new("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct.", 'Skipped Row') if admin_set.blank?
raise BatchProcessingError.new("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct. ------------ Message from System: Skipping row [#{index + 2}] with unknown admin set [#{admin_set_key}] for parent: #{oid}", 'Skipped Row') if admin_set.blank?

raise BatchProcessingError.new("Skipping row [#{index + 2}] with admin set [#{admin_set_key}] for parent: #{oid}. Preservica credentials not set for #{admin_set_key}.", 'Skipped Row') unless admin_set.preservica_credentials_verified

Expand Down
2 changes: 1 addition & 1 deletion spec/models/batch_process_create_parent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
batch_process.file = no_admin_set
batch_process.save
end.not_to change { ParentObject.count }
expect(batch_process.batch_ingest_events[0].reason).to eq('The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct.')
expect(batch_process.batch_ingest_events[0].reason).to eq('The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct. ------------ Message from System: Skipping row [2] with unknown admin set [] for parent: ')
end
# rubocop:enable Layout/LineLength
it 'can fail when csv has no source' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/parent_object_statable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
# rubocop:disable Layout/LineLength
batch_process_with_failure.batch_connections.first.update_status
expect(parent_object.latest_failure(batch_process_with_failure)).to be_an_instance_of Hash
expect(parent_object.latest_failure(batch_process_with_failure)[:reason]).to eq("Fake failure 2").or eq("Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information and that the descriptive records are public and/or published.")
expect(parent_object.latest_failure(batch_process_with_failure)[:reason]).to eq("Fake failure 2").or eq("Metadata Cloud could not access this descriptive record. Please make sure you have entered the correct information and that the descriptive records are public and/or published. ------------ Message from System: SetupMetadataJob failed to retrieve authoritative metadata. [https://metadata-api-uat.library.yale.edu/metadatacloud/api/1.0.1/ladybird/oid/2005512?include-children=1&mediaType=json]")
expect(parent_object.latest_failure(batch_process_with_failure)[:time]).to be
# rubocop:enable Layout/LineLength
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/preservica/preservica_parent_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
batch_process.file = preservica_parent_no_admin_set
batch_process.save
expect(batch_process.batch_ingest_events.count).to eq(1)
expect(batch_process.batch_ingest_events[0].reason).to eq("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct.")
expect(batch_process.batch_ingest_events[0].reason).to eq("The admin set code is missing or incorrect. Please ensure an admin_set value is in the correct spreadsheet column and that your 3 or 4 letter code is correct. ------------ Message from System: Skipping row [2] with unknown admin set [] for parent: 200000000")
end.not_to change { ParentObject.count }
end
# rubocop:enable Layout/LineLength
Expand Down

0 comments on commit bf2fff6

Please sign in to comment.