Skip to content

Commit

Permalink
normalize content types in pre-assembly to match current set
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Mar 15, 2021
1 parent 32cf089 commit d5bda39
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def content_md_creation_style
Cocina::Models::Vocab.object => :file,
Cocina::Models::Vocab.book => :simple_book,
Cocina::Models::Vocab.manuscript => :simple_book,
Cocina::Models::Vocab.document => :document,
Cocina::Models::Vocab.map => :map,
Cocina::Models::Vocab.three_dimensional => :'3d'
}.fetch(object_type, content_structure.to_sym)
Expand Down
3 changes: 2 additions & 1 deletion app/models/batch_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class BatchContext < ApplicationRecord
'file' => 3,
'media' => 4,
'3d' => 5,
'document' => 6
'document' => 6,
'maps' => 7
}

enum content_metadata_creation: {
Expand Down
1 change: 1 addition & 0 deletions app/views/batch_contexts/_new_bc_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
['File', 'file'],
['Media', 'media'],
['3D', '3d'],
['Map', 'maps']
]
%>

Expand Down
2 changes: 1 addition & 1 deletion spec/features/dark_file_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:bare_druid) { 'tx666tx9999' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'tx', '666', 'tx', '9999', bare_druid) }
let(:cocina_model_dark_access) { instance_double(Cocina::Models::Access, access: 'dark') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_dark_access) }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.object, access: cocina_model_dark_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:bare_druid) { 'pr666rr9999' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'pr', '666', 'rr', '9999', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_world_access) }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.document, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
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 @@ -8,7 +8,7 @@
let(:bare_druid) { 'pr666rr9999' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'pr', '666', 'rr', '9999', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_world_access) }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.image, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
Expand Down
75 changes: 75 additions & 0 deletions spec/features/map_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

RSpec.describe 'Create Map object', type: :feature do
let(:user) { create(:user) }
let(:user_id) { "#{user.sunet_id}@stanford.edu" }
let(:project_name) { "image-#{RandomWord.nouns.next}" }
let(:bundle_dir) { Rails.root.join('spec/test_data/image_jpg') }
let(:bare_druid) { 'pr666rr9999' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'pr', '666', 'rr', '9999', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.map, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
<<~XML
<contentMetadata objectId="pr666rr9999" type="map">
<resource id="pr666rr9999_1" sequence="1" type="image">
<label>Image 1</label>
<file id="image.jpg">
<checksum type="md5">3e9498107f73ff827e718d5c743f8813</checksum>
</file>
</resource>
</contentMetadata>
XML
end

before do
FileUtils.remove_dir(object_staging_dir) if Dir.exist?(object_staging_dir)

login_as(user, scope: :user)

allow(Dor::Services::Client).to receive(:object).and_return(dsc_object)
allow(StartAccession).to receive(:run).with(druid: "druid:#{bare_druid}", user: user.sunet_id)
end

# have background jobs run synchronously
include ActiveJob::TestHelper
around do |example|
perform_enqueued_jobs do
example.run
end
end

it do
visit '/'
expect(page).to have_selector('h3', text: 'Complete the form below')

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

click_button 'Submit'
exp_str = 'Success! Your job is queued. A link to job output will be emailed to you upon completion.'
expect(page).to have_content exp_str

# go to job details page, wait for preassembly to finish
first('td > a').click
expect(page).to have_content project_name
expect(page).to have_link('Download')

result_file = Rails.root.join(Settings.job_output_parent_dir, user_id, project_name, "#{project_name}_progress.yml")
yaml = YAML.load_file(result_file)
expect(yaml[:status]).to eq 'success'

# we got all the expected content files
expect(Dir.children(File.join(object_staging_dir, 'content')).size).to eq 1

metadata_dir = File.join(object_staging_dir, 'metadata')
expect(Dir.children(metadata_dir).size).to eq 1

content_md_xml = File.open(File.join(metadata_dir, 'contentMetadata.xml')).read
expect(noko_doc(content_md_xml)).to be_equivalent_to exp_content_md
end
end
2 changes: 1 addition & 1 deletion spec/features/public_tif_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:bare_druid) { 'tf111tf2222' }
let(:object_staging_dir) { Rails.root.join(Settings.assembly_staging_dir, 'tf', '111', 'tf', '2222', bare_druid) }
let(:cocina_model_world_access) { instance_double(Cocina::Models::Access, access: 'world') }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.media, access: cocina_model_world_access) }
let(:item) { instance_double(Cocina::Models::DRO, type: Cocina::Models::Vocab.image, access: cocina_model_world_access) }
let(:dsc_object_version) { instance_double(Dor::Services::Client::ObjectVersion, openable?: true) }
let(:dsc_object) { instance_double(Dor::Services::Client::Object, version: dsc_object_version, find: item) }
let(:exp_content_md) do
Expand Down
3 changes: 2 additions & 1 deletion spec/models/batch_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
'file' => 3,
'media' => 4,
'3d' => 5,
'document' => 6
'document' => 6,
'maps' => 7
)
end

Expand Down

0 comments on commit d5bda39

Please sign in to comment.