From bf2fff6c4434bbe17c6140d198a0d433863e58cb Mon Sep 17 00:00:00 2001 From: JP Engstrom Date: Fri, 25 Oct 2024 14:49:01 -0700 Subject: [PATCH] BP errors re work (#1452) Co-authored-by: JP Engstrom --- app/jobs/setup_metadata_job.rb | 6 +++--- app/lib/preservica_client.rb | 5 +---- app/models/child_object.rb | 7 ++++--- app/models/concerns/create_parent_object.rb | 8 ++++---- app/models/concerns/updatable.rb | 3 ++- app/models/preservica/bitstream.rb | 4 +++- app/services/csv_row_parent_service.rb | 2 +- spec/models/batch_process_create_parent_spec.rb | 2 +- spec/models/parent_object_statable_spec.rb | 2 +- spec/models/preservica/preservica_parent_error_spec.rb | 2 +- 10 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/jobs/setup_metadata_job.rb b/app/jobs/setup_metadata_job.rb index 619758f88..4e168e8e3 100644 --- a/app/jobs/setup_metadata_job.rb +++ b/app/jobs/setup_metadata_job.rb @@ -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 @@ -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 diff --git a/app/lib/preservica_client.rb b/app/lib/preservica_client.rb index 355f00d26..b7a5bc3cc 100644 --- a/app/lib/preservica_client.rb +++ b/app/lib/preservica_client.rb @@ -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 diff --git a/app/models/child_object.rb b/app/models/child_object.rb index fc3365e83..d4144faae 100644 --- a/app/models/child_object.rb +++ b/app/models/child_object.rb @@ -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? @@ -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 @@ -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) diff --git a/app/models/concerns/create_parent_object.rb b/app/models/concerns/create_parent_object.rb index 5b6635a3d..e975cacd8 100644 --- a/app/models/concerns/create_parent_object.rb +++ b/app/models/concerns/create_parent_object.rb @@ -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 @@ -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 @@ -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') diff --git a/app/models/concerns/updatable.rb b/app/models/concerns/updatable.rb index 1ebededa0..a042f0d0b 100644 --- a/app/models/concerns/updatable.rb +++ b/app/models/concerns/updatable.rb @@ -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) diff --git a/app/models/preservica/bitstream.rb b/app/models/preservica/bitstream.rb index e02389b56..e79302d39 100644 --- a/app/models/preservica/bitstream.rb +++ b/app/models/preservica/bitstream.rb @@ -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 @@ -55,7 +56,7 @@ 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 @@ -63,6 +64,7 @@ def download_to_file(file_name) 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! diff --git a/app/services/csv_row_parent_service.rb b/app/services/csv_row_parent_service.rb index a7d50a280..0e93fad59 100644 --- a/app/services/csv_row_parent_service.rb +++ b/app/services/csv_row_parent_service.rb @@ -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 diff --git a/spec/models/batch_process_create_parent_spec.rb b/spec/models/batch_process_create_parent_spec.rb index ece96e5cd..65d23ece5 100644 --- a/spec/models/batch_process_create_parent_spec.rb +++ b/spec/models/batch_process_create_parent_spec.rb @@ -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 diff --git a/spec/models/parent_object_statable_spec.rb b/spec/models/parent_object_statable_spec.rb index 11e425209..c2f3a269c 100644 --- a/spec/models/parent_object_statable_spec.rb +++ b/spec/models/parent_object_statable_spec.rb @@ -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 diff --git a/spec/models/preservica/preservica_parent_error_spec.rb b/spec/models/preservica/preservica_parent_error_spec.rb index 7e5ecbc21..1e15acbdc 100644 --- a/spec/models/preservica/preservica_parent_error_spec.rb +++ b/spec/models/preservica/preservica_parent_error_spec.rb @@ -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