Skip to content

Commit

Permalink
Merge pull request #521 from sul-dlss/media-not-smpl
Browse files Browse the repository at this point in the history
'media' content-type, not 'smpl'
  • Loading branch information
jmartin-sul committed Aug 16, 2019
2 parents 58245ab + 8db061b commit 5579b03
Show file tree
Hide file tree
Showing 69 changed files with 146 additions and 153 deletions.
19 changes: 6 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-21 16:08:12 -0800 using RuboCop version 0.60.0.
# on 2019-08-15 10:28:27 -0700 using RuboCop version 0.60.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -14,18 +14,18 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 310
Max: 307

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 188
Max: 174

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 20

# Offense count: 10
# Offense count: 11
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 44
Expand All @@ -34,13 +34,12 @@ Metrics/MethodLength:
Metrics/PerceivedComplexity:
Max: 20

# Offense count: 7
# Offense count: 4
# Configuration parameters: Blacklist.
# Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'spec/lib/pre_assembly/digital_object_spec.rb'
- 'spec/lib/pre_assembly/smpl_spec.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
Expand Down Expand Up @@ -75,13 +74,7 @@ RSpec/ExampleLength:
Exclude:
- 'spec/lib/pre_assembly/bundle_spec.rb'

# Offense count: 3
RSpec/MessageChain:
Exclude:
- 'spec/lib/pre_assembly/bundle_spec.rb'
- 'spec/lib/pre_assembly/digital_object_spec.rb'

# Offense count: 28
# Offense count: 26
RSpec/SubjectStub:
Exclude:
- 'spec/lib/pre_assembly/digital_object_spec.rb'
Expand Down
4 changes: 2 additions & 2 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Bundle
attr_writer :digital_objects
attr_accessor :user_params,
:skippables,
:smpl_manifest
:media_manifest

delegate :apo_druid_id,
:apply_tag,
Expand All @@ -26,7 +26,7 @@ class Bundle

def initialize(bundle_context)
@bundle_context = bundle_context
self.smpl_manifest = PreAssembly::Smpl.new(csv_filename: bundle_context.smpl_manifest, bundle_dir: bundle_dir) if bundle_context.smpl_cm_style?
self.media_manifest = PreAssembly::Media.new(csv_filename: bundle_context.media_manifest, bundle_dir: bundle_dir) if bundle_context.media_cm_style?
self.skippables = {}
load_skippables
end
Expand Down
12 changes: 6 additions & 6 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DigitalObject
:content_md_creation,
:content_structure,
:project_name,
:smpl_manifest,
:media_manifest,
:staging_style_symlink,
to: :bundle

Expand Down Expand Up @@ -160,15 +160,15 @@ def stage_files
end
end

# Technical metadata combined file for SMPL.
# Technical metadata combined file for Media.
def generate_technical_metadata
create_technical_metadata
write_technical_metadata
end

# create technical metadata for smpl projects only
# create technical metadata for media projects only
def create_technical_metadata
return unless content_md_creation == 'smpl_cm_style'
return unless content_md_creation == 'media_cm_style'

tm = Nokogiri::XML::Document.new
tm_node = Nokogiri::XML::Node.new('technicalMetadata', tm)
Expand Down Expand Up @@ -204,8 +204,8 @@ def generate_content_metadata

# Invoke the contentMetadata creation method used by the project
def create_content_metadata
if content_md_creation == 'smpl_cm_style'
self.content_md_xml = smpl_manifest.generate_cm(druid.id)
if content_md_creation == 'media_cm_style'
self.content_md_xml = media_manifest.generate_cm(druid.id)
else
# otherwise use the content metadata generation gem
params = { druid: druid.id, objects: content_object_files, add_exif: false, bundle: content_md_creation.to_sym, style: content_md_creation_style }
Expand Down
12 changes: 6 additions & 6 deletions app/lib/pre_assembly/smpl.rb → app/lib/pre_assembly/media.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# This class generates contentMetadata from a SMPL supplied manifest
# This class generates contentMetadata from a Media supplied manifest
# see the "SMPL Content" section here for a description of the manifest:
# https://consul.stanford.edu/pages/viewpage.action?pageId=136365158#AutomatedAccessioningandObjectRemediation(pre-assemblyandassembly)-SMPLContent

# It is used by pre-assembly during the accessioning process in an automated way based on the pre-assembly config .yml file setting of content_md_creation

# Test with
# cm=PreAssembly::Smpl.new(:bundle_dir=>'/thumpers/dpgthumper2-smpl/ARS0022_speech/content_ready_for_accessioning/content',:csv_filename=>'smpl_manifest.csv',:verbose=>true)
# cm=PreAssembly::Media.new(:bundle_dir=>'/thumpers/dpgthumper2-media/ARS0022_speech/content_ready_for_accessioning/content',:csv_filename=>'media_manifest.csv',:verbose=>true)
# cm.generate_cm('zx248jc1918')

# or in the context of a bundle object:
# cm=PreAssembly::Smpl.new(:csv_filename=>@content_md_creation[:smpl_manifest],:bundle_dir=>@bundle_dir,:verbose=>false)
# cm=PreAssembly::Media.new(:csv_filename=>@content_md_creation[:media_manifest],:bundle_dir=>@bundle_dir,:verbose=>false)
# cm.generate_cm('oo000oo0001')

module PreAssembly
class Smpl
class Media
attr_reader :file_attributes, :manifest, :rows, :csv_filename, :bundle_dir

def initialize(params)
@bundle_dir = params[:bundle_dir]
csv_file = params[:csv_filename] || 'smpl_manifest.csv'
csv_file = params[:csv_filename] || 'media_manifest.csv'
@csv_filename = File.join(@bundle_dir, csv_file)

# default publish/shelve/preserve attributes per "type" as defined in smpl filenames
# default publish/shelve/preserve attributes per "type" as defined in media filenames
@file_attributes = {
'default' => { publish: 'no', shelve: 'no', preserve: 'yes' },
'pm' => { publish: 'no', shelve: 'no', preserve: 'yes' },
Expand Down
14 changes: 7 additions & 7 deletions app/models/bundle_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class BundleContext < ApplicationRecord
'simple_book' => 1,
'book_as_image' => 2,
'file' => 3,
'smpl' => 4,
'media' => 4,
'3d' => 5
}

enum content_metadata_creation: {
'default' => 0,
'filename' => 1,
'smpl_cm_style' => 2
'media_cm_style' => 2
}

accepts_nested_attributes_for :job_runs
Expand Down Expand Up @@ -56,14 +56,14 @@ def progress_log_file
@progress_log_file ||= File.join(output_dir, "#{project_name}_progress.yml")
end

# TODO: See #274. Possibly need to keep for SMPL style projects (if they don't use manifest?)
# TODO: See #274. Possibly need to keep for Media style projects (if they don't use manifest?)
# @deprecated - since it's not currently configurable, and non-default usage isn't tested anyway
def stageable_discovery
{}
end

def smpl_manifest
'smpl_manifest.csv'
def media_manifest
'media_manifest.csv'
end

def manifest
Expand Down Expand Up @@ -118,8 +118,8 @@ def verify_bundle_directory
return if errors.key?(:bundle_dir)
return errors.add(:bundle_dir, "'#{bundle_dir}' not found.") unless File.directory?(bundle_dir)
errors.add(:bundle_dir, "missing manifest: #{bundle_dir}/#{manifest}") unless File.exist?(File.join(bundle_dir, manifest))
return unless smpl_cm_style? # only smpl objects require smpl_manifest.csv
errors.add(:bundle_dir, "missing Media (SMPL) manifest: #{bundle_dir}/#{smpl_manifest}") unless File.exist?(File.join(bundle_dir, smpl_manifest))
return unless media_cm_style? # only media objects require media_manifest.csv
errors.add(:bundle_dir, "missing Media manifest: #{bundle_dir}/#{media_manifest}") unless File.exist?(File.join(bundle_dir, media_manifest))
end

def verify_bundle_dir_path
Expand Down
14 changes: 7 additions & 7 deletions app/services/discovery_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def process_dobj(dobj)
empty_files = dobj.object_files.count { |obj| obj.filesize == 0 }
errors[:empty_files] = empty_files if empty_files > 0

if using_smpl_manifest? # if we are using a SMPL manifest, let's add how many files were found
if using_media_manifest? # if we are using a media manifest, let's add how many files were found
bundle_id = File.basename(dobj.container)
cm_files = smpl.manifest[bundle_id].fetch(:files, [])
cm_files = media.manifest[bundle_id].fetch(:files, [])
counts[:files_in_manifest] = cm_files.count
relative_paths = dobj.object_files.map(&:relative_path)
counts[:files_found] = (cm_files.pluck(:filename) & relative_paths).count
Expand Down Expand Up @@ -83,13 +83,13 @@ def registration_check(druid)
end

# @return [Boolean]
def using_smpl_manifest?
content_md_creation == 'smpl_cm_style' && File.exist?(File.join(bundle_dir, bundle.bundle_context.smpl_manifest))
def using_media_manifest?
content_md_creation == 'media_cm_style' && File.exist?(File.join(bundle_dir, bundle.bundle_context.media_manifest))
end

# @return [PreAssembly::Smpl]
def smpl
@smpl ||= PreAssembly::Smpl.new(csv_filename: bundle.bundle_context.smpl_manifest, bundle_dir: bundle_dir)
# @return [PreAssembly::Media]
def media
@media ||= PreAssembly::Media.new(csv_filename: bundle.bundle_context.media_manifest, bundle_dir: bundle_dir)
end

# By using jbuilder on an enumerator, we reduce memory footprint (vs. to_a)
Expand Down
4 changes: 2 additions & 2 deletions app/views/bundle_contexts/_new_bc_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
['Simple Book', 'simple_book'],
['Book as Image','book_as_image'],
['File', 'file'],
['Media', 'smpl'],
['Media', 'media'],
['3D', '3d'],
]
%>
Expand All @@ -53,7 +53,7 @@
[
["Default", "default"],
["Filename", "filename"],
["Media", "smpl_cm_style"]
["Media", "media_cm_style"]
]
%>
</div>
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/bundle_contexts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{
bundle_context:
{
project_name: 'SMPL-multimedia',
project_name: 'Multimedia',
content_structure: 'simple_image',
content_metadata_creation: 'default',
bundle_dir: 'spec/test_data/smpl_multimedia',
bundle_dir: 'spec/test_data/multimedia',
job_runs_attributes: { '0' => { job_type: 'preassembly' } }
}
}
Expand Down Expand Up @@ -44,7 +44,7 @@

context '#create' do
context 'Valid Parameters' do
let(:output_dir) { "#{Settings.job_output_parent_dir}/#{subject.current_user.email}/SMPL-multimedia" }
let(:output_dir) { "#{Settings.job_output_parent_dir}/#{subject.current_user.email}/Multimedia" }

before { Dir.delete(output_dir) if Dir.exist?(output_dir) }

Expand All @@ -58,10 +58,10 @@
it 'has the correct attributes' do
post :create, params: params
bc = assigns(:bundle_context)
expect(bc.project_name).to eq 'SMPL-multimedia'
expect(bc.project_name).to eq 'Multimedia'
expect(bc.content_structure).to eq 'simple_image'
expect(bc.content_metadata_creation).to eq 'default'
expect(bc.bundle_dir).to eq 'spec/test_data/smpl_multimedia'
expect(bc.bundle_dir).to eq 'spec/test_data/multimedia'
end
it 'persists the first JobRun, rejects dups' do
expect { post :create, params: params }.to change(JobRun, :count).by(1)
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/bundle_contexts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :bundle_context do
bundle_dir { 'spec/test_data/smpl_multimedia' }
bundle_dir { 'spec/test_data/multimedia' }
content_metadata_creation { 'default' }
content_structure { 'simple_image' }
project_name { 'Test_Project' }
Expand Down
22 changes: 11 additions & 11 deletions spec/lib/pre_assembly/bundle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let(:md5_regex) { /^[0-9a-f]{32}$/ }
let(:flat_dir_images) { bundle_setup(:flat_dir_images) }
let(:images_jp2_tif) { bundle_setup(:images_jp2_tif) }
let(:smpl_multimedia) { bundle_setup(:smpl_multimedia) }
let(:multimedia) { bundle_setup(:multimedia) }
let(:b) { create(:bundle_context_with_deleted_output_dir).bundle }

after { FileUtils.rm_rf(b.bundle_context.output_dir) if Dir.exist?(b.bundle_context.output_dir) } # cleanup
Expand Down Expand Up @@ -41,10 +41,10 @@

describe '#load_skippables' do
it 'returns expected hash of skippable items' do
allow(smpl_multimedia).to receive(:progress_log_file).and_return('spec/test_data/input/mock_progress_log.yaml')
expect(smpl_multimedia.skippables).to eq({})
smpl_multimedia.load_skippables
expect(smpl_multimedia.skippables).to eq('aa' => true, 'bb' => true)
allow(multimedia).to receive(:progress_log_file).and_return('spec/test_data/input/mock_progress_log.yaml')
expect(multimedia.skippables).to eq({})
multimedia.load_skippables
expect(multimedia.skippables).to eq('aa' => true, 'bb' => true)
end
end

Expand Down Expand Up @@ -77,15 +77,15 @@
end

it 'handles containers correctly' do
expect(smpl_multimedia.digital_objects.first.container.size).to be > smpl_multimedia.bundle_dir.size
expect(multimedia.digital_objects.first.container.size).to be > multimedia.bundle_dir.size
end
end

describe '#load_checksums' do
it 'loads checksums and attach them to the ObjectFiles' do
smpl_multimedia.send(:all_object_files).each { |f| expect(f.checksum).to be_nil }
smpl_multimedia.digital_objects.each { |dobj| smpl_multimedia.load_checksums(dobj) }
smpl_multimedia.send(:all_object_files).each { |f| expect(f.checksum).to match(md5_regex) }
multimedia.send(:all_object_files).each { |f| expect(f.checksum).to be_nil }
multimedia.digital_objects.each { |dobj| multimedia.load_checksums(dobj) }
multimedia.send(:all_object_files).each { |f| expect(f.checksum).to match(md5_regex) }
end
end

Expand Down Expand Up @@ -218,8 +218,8 @@
describe '#exclude_from_content' do
it 'behaves correctly' do
skip 'web app does not need to support exclude_from_content'
expect(smpl_multimedia.send(:exclude_from_content, smpl_multimedia.path_in_bundle('image1.tif'))).to be_falsey
expect(smpl_multimedia.send(:exclude_from_content, smpl_multimedia.path_in_bundle('descMetadata.xml'))).to be_truthy
expect(multimedia.send(:exclude_from_content, multimedia.path_in_bundle('image1.tif'))).to be_falsey
expect(multimedia.send(:exclude_from_content, multimedia.path_in_bundle('descMetadata.xml'))).to be_truthy
end
end

Expand Down
Loading

0 comments on commit 5579b03

Please sign in to comment.