diff --git a/app/models/concerns/integrity_checkable.rb b/app/models/concerns/integrity_checkable.rb index 62de8f66e..54bccfd11 100644 --- a/app/models/concerns/integrity_checkable.rb +++ b/app/models/concerns/integrity_checkable.rb @@ -5,6 +5,7 @@ module IntegrityCheckable # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Layout/LineLength def integrity_check @@ -26,8 +27,18 @@ def integrity_check add_admin_set_to_bp(sets, co) if co.access_master_exists? - co.parent_object.processing_event("Integrity check complete for Child Object: #{co.oid}", 'review-complete') - co.processing_event("Child Object: #{co.oid} - file exists.", 'review-complete') + if co&.file_size&.positive? + if co&.access_master_checksum_matches? + co.parent_object.processing_event("Integrity check complete for Child Object: #{co.oid}", 'review-complete') + co.processing_event("Child Object: #{co.oid} - file exists and checksum matches.", 'review-complete') + else + co.parent_object.processing_event("Integrity check complete for Child Object: #{co.oid}", 'failed') + co.processing_event("The Child Object: #{co.oid} - has a checksum mismatch. The checksum of the image file saved to this child oid does not match the checksum of the image file in the database. This may mean that the image has been corrupted. Please verify integrity of image for Child Object: #{co.oid} - by manually comparing the checksum values and update record as necessary.", 'failed') + end + else + co.parent_object.processing_event("Integrity check complete for Child Object: #{co.oid}", 'failed') + co.processing_event("Child Object: #{co.oid} - has a file size of 0. Please verify image for Child Object: #{co.oid}.", 'failed') + end else co.parent_object.processing_event("Integrity check complete for Child Object: #{co.oid}", 'failed') co.processing_event("Child Object: #{co.oid} - file not found at #{co.access_master_path} on #{ENV['ACCESS_MASTER_MOUNT']}.", 'failed') @@ -42,6 +53,7 @@ def integrity_check end # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/PerceivedComplexity # rubocop:enable Layout/LineLength end diff --git a/spec/fixtures/images/ptiff_images/09/90/56/78/90/567890.tif b/spec/fixtures/images/ptiff_images/09/90/56/78/90/567890.tif new file mode 100644 index 000000000..c3a7c0f8f Binary files /dev/null and b/spec/fixtures/images/ptiff_images/09/90/56/78/90/567890.tif differ diff --git a/spec/models/concerns/integrity_checkable_spec.rb b/spec/models/concerns/integrity_checkable_spec.rb index 3a4b228e7..19cd32f03 100644 --- a/spec/models/concerns/integrity_checkable_spec.rb +++ b/spec/models/concerns/integrity_checkable_spec.rb @@ -8,9 +8,11 @@ let(:parent_object_one) { FactoryBot.create(:parent_object, oid: '111', child_object_count: 1, authoritative_metadata_source: metadata_source, admin_set: admin_set) } let(:parent_object_two) { FactoryBot.create(:parent_object, oid: '222', child_object_count: 1, authoritative_metadata_source: metadata_source, admin_set: admin_set) } let(:parent_object_three) { FactoryBot.create(:parent_object, oid: '333', child_object_count: 1, authoritative_metadata_source: metadata_source, admin_set: admin_set) } + let(:parent_object_four) { FactoryBot.create(:parent_object, oid: '444', child_object_count: 1, authoritative_metadata_source: metadata_source, admin_set: admin_set) } let(:child_object_one) { FactoryBot.create(:child_object, oid: '1', parent_object: parent_object_one) } let(:child_object_two) { FactoryBot.create(:child_object, oid: '356789', parent_object: parent_object_two, checksum: '78909999999999999') } - let(:child_object_three) { FactoryBot.create(:child_object, oid: '456789', parent_object: parent_object_three, checksum: 'f3755c5d9e086b4522a0d3916e9a0bfcbd47564e') } + let(:child_object_three) { FactoryBot.create(:child_object, oid: '456789', parent_object: parent_object_three, file_size: 1234, checksum: 'f3755c5d9e086b4522a0d3916e9a0bfcbd47564e') } + let(:child_object_four) { FactoryBot.create(:child_object, oid: '567890', parent_object: parent_object_four, file_size: 1234, checksum: 'f3755c5d9e086b4522a0d3916e9a0bfcbd47564et') } around do |example| original_access_master_mount = ENV["ACCESS_MASTER_MOUNT"] @@ -28,18 +30,21 @@ before do # file not present stub_request(:get, File.join(child_object_one.access_master_path)).to_return(status: 200, body: '') - # file present but checksum does not match + # file present but file size is less than 0 stub_request(:get, File.join(child_object_two.access_master_path)).to_return(status: 200, body: File.open(File.join(child_object_two.access_master_path)).read) # file present and checksum matches stub_request(:get, File.join(child_object_three.access_master_path)).to_return(status: 200, body: File.open(File.join(child_object_three.access_master_path)).read) + # file present and file size greater than 0 but checksum does not match + stub_request(:get, File.join(child_object_four.access_master_path)).to_return(status: 200, body: File.open(File.join(child_object_three.access_master_path)).read) end it 'reflects messages as expected' do - expect { ChildObjectIntegrityCheckJob.new.perform }.to change { IngestEvent.count }.by(7) + expect { ChildObjectIntegrityCheckJob.new.perform }.to change { IngestEvent.count }.by(9) # rubocop:disable Layout/LineLength expect(child_object_one.events_for_batch_process(BatchProcess.first)[0].reason).to eq "Child Object: #{child_object_one.oid} - file not found at #{child_object_one.access_master_path} on #{ENV['ACCESS_MASTER_MOUNT']}." - expect(child_object_two.events_for_batch_process(BatchProcess.first)[0].reason).to eq "Child Object: #{child_object_two.oid} - file exists." - expect(child_object_three.events_for_batch_process(BatchProcess.first)[0].reason).to eq "Child Object: #{child_object_three.oid} - file exists." + expect(child_object_two.events_for_batch_process(BatchProcess.first)[0].reason).to eq "Child Object: #{child_object_two.oid} - has a file size of 0. Please verify image for Child Object: #{child_object_two.oid}." + expect(child_object_three.events_for_batch_process(BatchProcess.first)[0].reason).to eq "Child Object: #{child_object_three.oid} - file exists and checksum matches." + expect(child_object_four.events_for_batch_process(BatchProcess.first)[0].reason).to eq "The Child Object: #{child_object_four.oid} - has a checksum mismatch. The checksum of the image file saved to this child oid does not match the checksum of the image file in the database. This may mean that the image has been corrupted. Please verify integrity of image for Child Object: #{child_object_four.oid} - by manually comparing the checksum values and update record as necessary." # rubocop:enable Layout/LineLength end end