Skip to content

Commit

Permalink
Merge pull request #255 from sul-dlss/dr_templates
Browse files Browse the repository at this point in the history
DiscoveryReport templates
  • Loading branch information
ndushay committed Sep 12, 2018
2 parents f176896 + 98f4aa6 commit 773daa1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
23 changes: 1 addition & 22 deletions app/services/discovery_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ def process_dobj(dobj)
errors[:empty_object] = true if counts[:total_size] > 0
errors[:missing_files] = true unless dobj.object_files_exist?
errors[:dupes] = true unless object_filenames_unique?(dobj)
counts[:source_ids][dobj.source_id] += 1
errors.merge!(registration_check(dobj.druid))
if using_manifest? # check global uniqueness
errors[:source_id_dup] = true if dobj.source_id.any? { |id| Dor::SearchService.query_by_id(id) }
end
return { errors: errors, counts: counts }
end

Expand All @@ -67,29 +63,13 @@ def registration_check(druid)
return { apo_not_registered: true }
end

# @return [String] primitive version
def header
fields = ['Object Container', 'Number of Items', 'Files with no ext', 'Files with 0 Size', 'Total Size', 'Files Readable']
fields.concat ['Label', 'Source ID'] if using_manifest?
fields.concat ['Num Files in CM Manifest', 'All CM files found'] if using_smpl_manifest?
fields.concat ['Duplicate Filenames?', 'DRUID', 'Registered?', 'APO exists?']
fields << 'SourceID unique in DOR?' if using_manifest?
fields.join(' , ')
end

# For use by template
def skipped_files
files = ['Thumbs.db', '.DS_Store'] # if these files are in the bundle directory but not in the manifest, they will be ignorned and not reported as missing
files = ['Thumbs.db', '.DS_Store', manifest] # if these files are in the bundle directory but not in the manifest, they will be ignorned and not reported as missing
files << File.basename(content_md_creation[:smpl_manifest]) if using_smpl_manifest?
files << File.basename(manifest) if using_manifest?
files
end

# @return [Boolean]
def using_manifest?
manifest.present?
end

# @return [Boolean]
def using_smpl_manifest?
content_md_creation[:style] == :smpl && File.exist?(File.join(bundle_dir, content_md_creation[:smpl_manifest]))
Expand All @@ -99,5 +79,4 @@ def using_smpl_manifest?
def smpl
@smpl ||= PreAssembly::Smpl.new(csv_filename: content_md_creation[:smpl_manifest], bundle_dir: bundle_dir)
end

end
1 change: 1 addition & 0 deletions app/views/discovery_report/_row.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Example row output
5 changes: 5 additions & 0 deletions app/views/discovery_report/show.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Discovery Report
=====================
<%= render partial: 'row', collection: @discovery_report.each_row %>
=====================
Possible summary data
16 changes: 16 additions & 0 deletions spec/services/discover_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@
report.each_row { |_r| } # no-op
end
end

describe '#process_dobj' do
let(:dobj) { report.bundle.objects_to_process.first }

before do
allow(dobj).to receive(:pid).and_return('kk203bw3276')
allow(report).to receive(:registration_check).and_return({}) # pretend everything is in Dor
end

it 'converts a DigtialObject to structured data (Hash)' do
expect(report.process_dobj(dobj)).to match a_hash_including(
counts: a_hash_including(total_size: 0),
errors: a_hash_including(missing_files: true)
)
end
end
end
17 changes: 17 additions & 0 deletions spec/views/discovery_report/show.text.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.describe 'discovery_report/show.text.erb' do
let(:bundle) { bundle_setup(:proj_revs) }
subject(:report) { DiscoveryReport.new(bundle) }

before do
allow_any_instance_of(BundleContextTemporary).to receive(:validate_usage) # replace w/ AR validation
report.bundle.digital_objects.each { |dobj| allow(dobj).to receive(:pid).and_return('kk203bw3276') }
allow(report).to receive(:registration_check).and_return({}) # pretend everything is in Dor
end

it 'renders the wrapper and a row per DigitalObject' do
assign(:discovery_report, report)
render
expect(rendered).to match(/Discovery Report/)
expect(rendered).to match(/^Example row output\nExample row output\nExample row output\n[^E]/) # 3 rows
end
end

0 comments on commit 773daa1

Please sign in to comment.