Skip to content

Commit

Permalink
Remove file_attr
Browse files Browse the repository at this point in the history
Fixes #228

This functionality relates to content metadata generation and was well
tested, so it is probably wise to have Ben sign off that some
other part of the ecosystem is responsible for this or that indeed it is
unneeded for the app MVP.
  • Loading branch information
atz committed Sep 25, 2018
1 parent a9a3a8d commit ef152f2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 63 deletions.
2 changes: 0 additions & 2 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Bundle
:content_exclusion,
:content_md_creation,
:content_structure,
:file_attr,
:manifest_cols,
:manifest_rows,
:path_in_bundle,
Expand Down Expand Up @@ -107,7 +106,6 @@ def digital_object_base_params
{
:bundle_dir => bundle_dir,
:content_md_creation => content_md_creation,
:file_attr => file_attr,
:project_name => project_name,
:project_style => content_structure,
:smpl_manifest => smpl_manifest,
Expand Down
52 changes: 20 additions & 32 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,42 @@ class DigitalObject
include PreAssembly::Logging

INIT_PARAMS = [
:assembly_staging_dir,
:bundle_dir,
:container,
:unadjusted_container,
:stageable_items,
:content_md_creation,
:object_files,
:project_style,
:project_name,
:file_attr,
:bundle_dir,
:assembly_staging_dir,
:content_md_creation,
:project_style,
:smpl_manifest,
:stageable_items,
:staging_style,
:smpl_manifest
:unadjusted_container
]

attr_accessor :label,
:content_md_file,
:technical_md_file,
attr_accessor :content_md_file,
:content_md_xml,
:technical_md_xml,
:pre_assem_finished,
:content_structure,
:label,
:manifest_row,
:pre_assem_finished,
:source_id,
:manifest_row
:technical_md_file,
:technical_md_xml

attr_writer :dor_object, :druid_tree_dir

INIT_PARAMS.each { |p| attr_accessor p }

####
# Initialization.
####

# @param [Hash] params
def initialize(params = {})
INIT_PARAMS.each { |p| instance_variable_set "@#{p}", params[p] }
self.file_attr ||= params[:publish_attr]
setup
end

def setup
self.label = 'Unknown' # used for registration when no label is provided in the manifest
self.content_md_file = 'contentMetadata.xml'
self.technical_md_file = 'technicalMetadata.xml'
self.content_md_xml = ''
self.technical_md_xml = ''
self.content_structure = (project_style ? project_style : 'file')
self.label = 'Unknown' # used for registration when no label is provided in the manifest
self.content_md_file = 'contentMetadata.xml'
self.technical_md_file = 'technicalMetadata.xml'
self.content_md_xml = ''
self.technical_md_xml = ''
self.content_structure = (project_style ? project_style : 'file')
end

def stager(source, destination)
Expand Down Expand Up @@ -223,9 +214,6 @@ def create_content_metadata
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 }

params.merge!(:add_file_attributes => true, :file_attributes => file_attr.stringify_keys) unless file_attr.nil?

self.content_md_xml = Assembly::ContentMetadata.create_content_metadata(params)
end
end
Expand Down
36 changes: 13 additions & 23 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
let(:dru) { 'gn330dv6119' }
let(:pid) { "druid:#{dru}" }
let(:context_params) do
{
:file_attr => { 'default' => { :publish => 'yes', :shelve => 'yes', :preserve => 'yes' } },
:source_id => 'SourceIDFoo'
}
{ :source_id => 'SourceIDFoo' }
end
let(:ps) do
context_params.merge(
Expand Down Expand Up @@ -101,29 +98,28 @@ def add_object_files(extension = 'tif')
describe "default content metadata" do
let(:exp_xml) do
noko_doc <<-END
<?xml version="1.0"?>
<contentMetadata type="image" objectId="gn330dv6119">
<resource type="image" id="gn330dv6119_1" sequence="1">
<label>Image 1</label>
<file publish="yes" shelve="yes" id="image1.jp2" preserve="yes">
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" id="gn330dv6119_2" sequence="2">
<label>Image 2</label>
<file publish="yes" shelve="yes" id="image1.tif" preserve="yes">
<file id="image1.tif">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" id="gn330dv6119_3" sequence="3">
<label>Image 3</label>
<file publish="yes" shelve="yes" id="image2.jp2" preserve="yes">
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
<resource type="image" id="gn330dv6119_4" sequence="4">
<label>Image 4</label>
<file publish="yes" shelve="yes" id="image2.tif" preserve="yes">
<file id="image2.tif">
<checksum type="md5">2222</checksum>
</file>
</resource>
Expand Down Expand Up @@ -213,7 +209,6 @@ def add_object_files(extension = 'tif')
allow(dobj).to receive(:content_type_tag).and_return("")
dobj.content_md_creation = 'filename'
dobj.project_style = 'simple_book'
dobj.file_attr = nil
add_object_files('tif')
add_object_files('jp2')
dobj.create_content_metadata
Expand All @@ -227,7 +222,6 @@ def add_object_files(extension = 'tif')
describe "content metadata generated from object tag in DOR if present and overriding is allowed" do
let(:exp_xml) do
noko_doc <<-END
<?xml version="1.0"?>
<contentMetadata type="file" objectId="gn330dv6119">
<resource type="file" id="gn330dv6119_1" sequence="1">
<label>File 1</label>
Expand Down Expand Up @@ -262,7 +256,6 @@ def add_object_files(extension = 'tif')
dobj.project_style[:content_structure] = 'simple_image' # this is the default
dobj.project_style[:content_tag_override] = true # this allows override of content structure
allow(dobj).to receive(:content_type_tag).and_return('File') # this is what the object tag says, so we should get the file type out
dobj.file_attr = nil
add_object_files('tif')
add_object_files('jp2')
dobj.create_content_metadata
Expand Down Expand Up @@ -295,29 +288,28 @@ def add_object_files(extension = 'tif')
describe "content metadata generated from object tag in DOR if present but overriding is not allowed" do
let(:exp_xml) do
noko_doc <<-END
<?xml version="1.0"?>
<contentMetadata type="image" objectId="gn330dv6119">
<resource type="image" sequence="1" id="gn330dv6119_1">
<label>Image 1</label>
<file publish="yes" preserve="no" shelve="yes" id="image1.jp2">
<file id="image1.jp2">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" sequence="2" id="gn330dv6119_2">
<label>Image 2</label>
<file publish="no" preserve="yes" shelve="no" id="image1.tif">
<file id="image1.tif">
<checksum type="md5">1111</checksum>
</file>
</resource>
<resource type="image" sequence="3" id="gn330dv6119_3">
<label>Image 3</label>
<file publish="yes" preserve="no" shelve="yes" id="image2.jp2">
<file id="image2.jp2">
<checksum type="md5">2222</checksum>
</file>
</resource>
<resource type="image" sequence="4" id="gn330dv6119_4">
<label>Image 4</label>
<file publish="no" preserve="yes" shelve="no" id="image2.tif">
<file id="image2.tif">
<checksum type="md5">2222</checksum>
</file>
</resource>
Expand All @@ -329,7 +321,6 @@ def add_object_files(extension = 'tif')
allow(dobj).to receive(:druid).and_return(druid)
dobj.project_style[:content_structure] = 'simple_image' # this is the default
allow(dobj).to receive(:content_type_tag).and_return('File') # this is what the object tag says, but it should be ignored since overriding is not allowed
dobj.file_attr = { 'image/jp2' => { :publish => 'yes', :shelve => 'yes', :preserve => 'no' }, 'image/tiff' => { :publish => 'no', :shelve => 'no', :preserve => 'yes' } }
add_object_files('tif')
add_object_files('jp2')
dobj.create_content_metadata
Expand All @@ -338,19 +329,18 @@ def add_object_files(extension = 'tif')
it "content_object_files() should filter @object_files correctly" do
# Generate some object_files.
files = %w(file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif)
n = files.size
m = n / 2
dobj.object_files = files.map do |f|
PreAssembly::ObjectFile.new(:exclude_from_content => false, :relative_path => f)
end
# All of them are included in content.
expect(dobj.content_object_files.size).to eq(n)
# Now exclude some. Make sure we got correct N of items.
expect(dobj.content_object_files.size).to eq(files.size)
m = files.size / 2
# Now exclude some. Make sure we got correct M of items.
(0...m).each { |i| dobj.object_files[i].exclude_from_content = true }
ofiles = dobj.content_object_files
expect(ofiles.size).to eq(m)
# Also check their ordering.
expect(ofiles.map { |f| f.relative_path }).to eq(files[m..-1].sort)
expect(ofiles.map(&:relative_path)).to eq(files[m..-1].sort)
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/lib/pre_assembly/smpl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@

def setup_dobj(druid, smpl_manifest)
ps = {
# :apo_druid_id => 'qq333xx4444',
# :set_druid_id => 'mm111nn2222',
:source_id => 'SourceIDFoo',
:project_name => 'ProjectBar',
:label => 'LabelQuux',
:publish_attr => { :publish => 'no', :shelve => 'no', :preserve => 'yes' },
# :publish_attr => { :publish => 'no', :shelve => 'no', :preserve => 'yes' },
:project_style => {},
:bundle_dir => bundle_dir,
:smpl_manifest => smpl_manifest,
Expand All @@ -82,7 +80,7 @@ def setup_dobj(druid, smpl_manifest)
end

def exp_xml_object_aa111aa1111
<<-END.gsub(/^ {8}/, '')
<<-END
<?xml version="1.0"?>
<contentMetadata type="media" objectId="aa111aa1111">
<resource type="media" sequence="1" id="aa111aa1111_1">
Expand Down Expand Up @@ -122,7 +120,7 @@ def exp_xml_object_aa111aa1111
end

def exp_xml_object_aa111aa1111_with_thumb
<<-END.gsub(/^ {8}/, '')
<<-END
<?xml version="1.0"?>
<contentMetadata type="media" objectId="aa111aa1111">
<resource type="media" sequence="1" id="aa111aa1111_1" thumb="yes">
Expand Down Expand Up @@ -162,7 +160,7 @@ def exp_xml_object_aa111aa1111_with_thumb
end

def exp_xml_object_bb222bb2222
<<-END.gsub(/^ {8}/, '')
<<-END
<?xml version="1.0"?>
<contentMetadata objectId="bb222bb2222" type="media">
<resource sequence="1" id="bb222bb2222_1" type="media">
Expand Down

0 comments on commit ef152f2

Please sign in to comment.