Skip to content

Commit

Permalink
add support for reading order
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Mar 17, 2021
1 parent cc007fc commit a7e7421
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 11 deletions.
16 changes: 10 additions & 6 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ def generate_content_metadata(file_attributes_supplied)
# Invoke the contentMetadata creation method used by the project
# @param [Boolean] file_attributes_supplied - true if publish/preserve/shelve attribs are supplied
def create_content_metadata(file_attributes_supplied)
reading_order = if content_structure == :simple_book_rtl
'rtl'
else
'ltr'
end
# Special case: if the content_structure set by the user is a rtl simple book,
# be sure we set this as the style, else use the default and style from the object
if content_structure == 'simple_book_rtl'
reading_order = 'rtl'
content_style = :simple_book
else
reading_order = 'ltr'
content_style = content_md_creation_style
end
ContentMetadataCreator.new(druid_id: druid.id,
content_md_creation: content_md_creation,
object_files: object_files,
content_md_creation_style: content_md_creation_style,
content_md_creation_style: content_style,
media_manifest: media_manifest,
reading_order: reading_order,
add_file_attributes: file_attributes_supplied).create
Expand Down
2 changes: 1 addition & 1 deletion spec/features/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

fill_in 'Project name', with: project_name
select 'Pre Assembly Run', from: 'Job type'
select 'Simple Image', from: 'Content structure'
select 'Image', from: 'Content structure'
fill_in 'Bundle dir', with: bundle_dir

click_button 'Submit'
Expand Down
2 changes: 1 addition & 1 deletion spec/features/public_tif_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

fill_in 'Project name', with: project_name
select 'Pre Assembly Run', from: 'Job type'
select 'Simple Image', from: 'Content structure'
select 'Image', from: 'Content structure'
fill_in 'Bundle dir', with: bundle_dir
choose 'Preserve=Yes, Shelve=Yes, Publish=Yes'

Expand Down
6 changes: 4 additions & 2 deletions spec/lib/pre_assembly/content_metadata_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
object_files: object_files,
content_md_creation_style: content_md_creation_style,
media_manifest: media_manifest,
reading_order: reading_order,
add_file_attributes: add_file_attributes)
end

let(:druid_id) { 'foo' }
let(:content_md_creation) { 'bar' }
let(:content_md_creation_style) { 'baz' }
let(:add_file_attributes) { false }
let(:reading_order) { 'ltr' }
let(:media_manifest) { 'quix' }

describe '#content_object_files' do
Expand Down Expand Up @@ -55,7 +57,7 @@
creator.create
expect(Assembly::ContentMetadata).to have_received(:create_content_metadata)
.with(druid: druid_id, objects: object_files, add_exif: false,
bundle: :bar, style: content_md_creation_style, add_file_attributes: false)
bundle: :bar, style: content_md_creation_style, reading_order: reading_order, add_file_attributes: false)
end
end

Expand All @@ -66,7 +68,7 @@
creator.create
expect(Assembly::ContentMetadata).to have_received(:create_content_metadata)
.with(druid: druid_id, objects: object_files, add_exif: false,
bundle: :bar, style: content_md_creation_style, add_file_attributes: true)
bundle: :bar, style: content_md_creation_style, reading_order: reading_order, add_file_attributes: true)
end
end
end
Expand Down
110 changes: 109 additions & 1 deletion spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_object_files(extension = 'tif', all_files_public: false)
end

describe '#create_content_metadata' do
describe 'default content metadata' do
describe 'default content metadata (image)' do
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="image" objectId="gn330dv6119">
Expand Down Expand Up @@ -227,6 +227,112 @@ def add_object_files(extension = 'tif', all_files_public: false)
end
end

describe 'book (ltr) content metadata' do
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="book" objectId="gn330dv6119">
<bookData readingOrder="ltr"/>
<resource type="page" id="gn330dv6119_1" sequence="1">
<label>Page 1</label>
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="page" id="gn330dv6119_2" sequence="2">
<label>Page 2</label>
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
</contentMetadata>
XML
end

let(:assembly_directory) { PreAssembly::AssemblyDirectory.new(druid_id: druid.id) }

before do
allow(object).to receive(:druid).and_return(druid)
allow(object).to receive(:object_type).and_return('')
allow(bc).to receive(:content_structure).and_return('simple_book')
add_object_files('jp2')
allow(object).to receive(:assembly_directory).and_return(assembly_directory)
end

around do |example|
RSpec::Mocks.with_temporary_scope do
Dir.mktmpdir(*tmp_dir_args) do |tmp_area|
allow(assembly_directory).to receive(:druid_tree_dir).and_return(tmp_area)
example.run
end
end
end

it 'generates the expected xml text' do
expect(noko_doc(object.send(:create_content_metadata, false))).to be_equivalent_to exp_xml
end

it 'is able to write the content_metadata XML to a file' do
assembly_directory.create_object_directories
file_name = object.send(:assembly_directory).content_metadata_file
expect(File.exist?(file_name)).to eq(false)
object.send(:generate_content_metadata, false)
expect(noko_doc(File.read(file_name))).to be_equivalent_to exp_xml
end
end

describe 'book (rtl) content metadata' do
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="book" objectId="gn330dv6119">
<bookData readingOrder="rtl"/>
<resource type="page" id="gn330dv6119_1" sequence="1">
<label>Page 1</label>
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="page" id="gn330dv6119_2" sequence="2">
<label>Page 2</label>
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
</contentMetadata>
XML
end

let(:assembly_directory) { PreAssembly::AssemblyDirectory.new(druid_id: druid.id) }

before do
allow(object).to receive(:druid).and_return(druid)
allow(object).to receive(:object_type).and_return('')
allow(bc).to receive(:content_structure).and_return('simple_book_rtl')
add_object_files('jp2')
allow(object).to receive(:assembly_directory).and_return(assembly_directory)
end

around do |example|
RSpec::Mocks.with_temporary_scope do
Dir.mktmpdir(*tmp_dir_args) do |tmp_area|
allow(assembly_directory).to receive(:druid_tree_dir).and_return(tmp_area)
example.run
end
end
end

it 'generates the expected xml text' do
expect(noko_doc(object.send(:create_content_metadata, false))).to be_equivalent_to exp_xml
end

it 'is able to write the content_metadata XML to a file' do
assembly_directory.create_object_directories
file_name = object.send(:assembly_directory).content_metadata_file
expect(File.exist?(file_name)).to eq(false)
object.send(:generate_content_metadata, false)
expect(noko_doc(File.read(file_name))).to be_equivalent_to exp_xml
end
end

describe 'webarchive-seed content metadata' do
let(:exp_xml) do
noko_doc <<-XML
Expand Down Expand Up @@ -283,6 +389,7 @@ def add_object_files(extension = 'tif', all_files_public: false)
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="book" objectId="gn330dv6119">
<bookData readingOrder="ltr"/>
<resource type="page" sequence="1" id="gn330dv6119_1">
<label>Page 1</label>
<file id="image1.jp2">
Expand Down Expand Up @@ -323,6 +430,7 @@ def add_object_files(extension = 'tif', all_files_public: false)
let(:exp_xml) do
noko_doc <<-XML
<contentMetadata type="book" objectId="gn330dv6119">
<bookData readingOrder="ltr"/>
<resource type="page" sequence="1" id="gn330dv6119_1">
<label>Page 1</label>
<file id="image1.jp2" preserve="yes" shelve="yes" publish="yes">
Expand Down

0 comments on commit a7e7421

Please sign in to comment.