Skip to content

Commit

Permalink
Merge pull request #256 from sul-dlss/ar-bc-with-bundle
Browse files Browse the repository at this point in the history
Replace BundleContextTemporary with BundleContext
  • Loading branch information
jmartin-sul committed Sep 13, 2018
2 parents 8d6c27d + da2bbbf commit 4018f78
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 159 deletions.
16 changes: 8 additions & 8 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class Bundle
:config_filename,
:content_exclusion,
:content_md_creation,
:content_structure,
:file_attr,
:manifest_cols,
:manifest_rows,
:path_in_bundle,
:progress_log_file,
:project_name,
:project_style,
:set_druid_id,
:stageable_discovery,
:staging_dir,
:staging_style,
:staging_style_symlink,
:validate_files?,
to: :bundle_context

Expand Down Expand Up @@ -61,8 +61,8 @@ def run_pre_assembly
puts "#{Time.now}: Pre-assembly started for #{project_name}"

# load up the SMPL manifest if we are using that style
if content_md_creation[:style] == :smpl
self.smpl_manifest = PreAssembly::Smpl.new(:csv_filename => content_md_creation[:smpl_manifest], :bundle_dir => bundle_dir)
if bundle_context.smpl_cm_style?
self.smpl_manifest = PreAssembly::Smpl.new(:csv_filename => bundle_context.smpl_manifest, :bundle_dir => bundle_dir)
end
process_digital_objects
puts "#{Time.now}: Pre-assembly completed for #{project_name}"
Expand All @@ -71,7 +71,7 @@ def run_pre_assembly

def run_log_msg
log_params = {
:project_style => project_style,
:content_structure => content_structure,
:project_name => project_name,
:bundle_dir => bundle_dir,
:staging_dir => staging_dir,
Expand Down Expand Up @@ -120,10 +120,10 @@ def digital_object_base_params
:content_md_creation => content_md_creation,
:file_attr => file_attr,
:project_name => project_name,
:project_style => project_style,
:project_style => content_structure,
:smpl_manifest => smpl_manifest,
:staging_dir => staging_dir,
:staging_style => staging_style
:staging_style => staging_style_symlink
}
end

Expand All @@ -133,7 +133,7 @@ def digital_object_base_params
# user invoking the pre-assembly script.
def discover_containers_via_manifest
raise BundleUsageError, ':manifest_cols must be specified' unless manifest_cols
col_name = manifest_cols[:object_container]
col_name = manifest_cols[:object_container].to_sym
raise BundleUsageError, "object_container must be specified in manifest_cols: #{manifest_cols}" unless col_name
manifest_rows.each_with_index { |r, i| raise "Missing #{col_name} in row #{i}: #{r}" unless r[col_name] }
manifest_rows.map { |r| path_in_bundle r[col_name] }
Expand Down
34 changes: 12 additions & 22 deletions app/lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module PreAssembly

class DigitalObject
include PreAssembly::Logging
include PreAssembly::Project::Smpl

INIT_PARAMS = [
:container,
Expand Down Expand Up @@ -53,14 +52,14 @@ def setup
self.technical_md_file = 'technicalMetadata.xml'
self.content_md_xml = ''
self.technical_md_xml = ''
self.content_structure = (project_style ? project_style[:content_structure] : 'file')
self.content_structure = (project_style ? project_style : 'file')
end

def stager(source, destination)
if staging_style.nil? || staging_style == 'copy'
FileUtils.cp_r source, destination
else
if staging_style
FileUtils.ln_s source, destination, :force => true
else
FileUtils.cp_r source, destination
end
end

Expand All @@ -77,16 +76,11 @@ def content_md_creation_style
'Manuscript (image-only)' => :book_as_image,
'Map' => :map
}
# if this object needs to be registered or has no content type tag for a registered object, use the default set in the YAML file
if !project_style[:content_tag_override] || content_type_tag.blank?
default_content_md_creation_style
else # if the object is already registered and there is a content type tag and we allow overrides, use it if we know what it means (else use the default)
content_type_tag_mapping[content_type_tag] || default_content_md_creation_style
end
content_type_tag_mapping[content_type_tag] || default_content_md_creation_style
end

def default_content_md_creation_style
project_style[:content_structure].to_sym
project_style.to_sym
end

# compute the base druid tree folder for this object
Expand All @@ -110,7 +104,7 @@ def metadata_dir
def pre_assemble
log " - pre_assemble(#{source_id}) started"
stage_files
generate_content_metadata unless content_md_creation[:style].to_s == 'none'
generate_content_metadata
generate_technical_metadata
initialize_assembly_workflow
log " - pre_assemble(#{pid}) finished"
Expand Down Expand Up @@ -189,7 +183,7 @@ def generate_technical_metadata

# create technical metadata for smpl projects only
def create_technical_metadata
return unless @content_md_creation[:style].to_s == 'smpl'
return unless content_md_creation == 'smpl_cm_style'

tm = Nokogiri::XML::Document.new
tm_node = Nokogiri::XML::Node.new("technicalMetadata", tm)
Expand Down Expand Up @@ -225,15 +219,13 @@ def generate_content_metadata
end

# Invoke the contentMetadata creation method used by the project
# The name of the method invoked must be "create_content_metadata_xml_#{content_md_creation--style}", as defined in the YAML configuration
# Custom methods are defined in the project_specific.rb file
# if we are not using a standard known style of content metadata generation, pass the task off to a custom method
def create_content_metadata
if !['default', 'filename', 'dpg', 'none'].include? @content_md_creation[:style].to_s
self.content_md_xml = method("create_content_metadata_xml_#{@content_md_creation[:style]}").call
elsif content_md_creation[:style].to_s != 'none' # and assuming we don't want any contentMetadata, then use the Assembly gem to generate CM
if content_md_creation == "smpl_cm_style"
self.content_md_xml = smpl_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[:style].to_sym, :style => content_md_creation_style }
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?

Expand All @@ -243,9 +235,7 @@ def create_content_metadata

# write content metadata out to a file
def write_content_metadata
return if content_md_creation[:style].to_s == 'none'
file_name = File.join(metadata_dir, content_md_file)
log " - write_content_metadata_xml(#{file_name})"
create_object_directories

File.open(file_name, 'w') { |fh| fh.puts content_md_xml }
Expand Down
21 changes: 0 additions & 21 deletions app/lib/pre_assembly/project/README.txt

This file was deleted.

10 changes: 0 additions & 10 deletions app/lib/pre_assembly/project/smpl.rb

This file was deleted.

54 changes: 36 additions & 18 deletions app/models/bundle_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BundleContext < ApplicationRecord
validates :project_name, presence: true, null: false
validates :content_structure, presence: true, null: false
validates :bundle_dir, presence: true, null: false
validates :staging_style_symlink, inclusion: { in: [ true, false ] }
validates :staging_style_symlink, inclusion: { in: [true, false] }
validates :content_metadata_creation, presence: true, null: false

validate :verify_bundle_directory
Expand All @@ -14,44 +14,62 @@ class BundleContext < ApplicationRecord
after_initialize :normalize_bundle_dir

enum content_structure: {
"simple_image_structure" => 0,
"simple_book_structure" => 1,
"book_as_iamge_structure" => 2,
"file_structure" => 3,
"smpl_structure" => 4
"simple_image" => 0,
"simple_book" => 1,
"book_as_image" => 2,
"file" => 3,
"smpl" => 4
}

enum content_metadata_creation: {
"default_style" => 0,
"filename_style" => 1,
"smpl_style" => 2
"default" => 0,
"filename" => 1,
"smpl_cm_style" => 2
}

def content_md_creation
content_metadata_creation
end

def project_style
content_structure
end

def staging_dir
'/dor/assembly'
'/tmp/assembly'
end

def normalize_bundle_dir
self[:bundle_dir].chomp("/") if bundle_dir
end

def progress_log_file
Tempfile.new.path(id) #FIXME: (#78)
'/dor/preassembly' # FIXME: (#78)
end

def stageable_discovery
{}
end

def accession_items
nil
end

def content_exclusion #FIXME: Delete everywhere in code (#227)
def content_exclusion
# FIXME: Delete everywhere in code (#227)
nil
end

def file_attr
nil # FIXME can get rid of this (#228)
nil # FIXME: can get rid of this (#228)
end

def validate_files?
false #FIXME delete everwhere in code (#230)
false # FIXME: delete everwhere in code (#230)
end

def content_tag_override? #TODO: find where this is used as a conditional and delete code that won't be executed (#231)
def content_tag_override?
# TODO: find where this is used as a conditional and delete code that won't be executed (#231)
true
end

Expand All @@ -77,7 +95,7 @@ def manifest_cols
{
label: 'label',
source_id: 'sourceid',
object_container: 'object', #object referring to filename or foldername
object_container: 'object', # object referring to filename or foldername
druid: 'druid'
}
end
Expand All @@ -86,10 +104,10 @@ def manifest_cols

def verify_bundle_directory
return if errors.key?(:bundle_dir)
errors.add(:bundle_dir, "Bundle directory: #{bundle_dir} not found.") unless File.directory?(bundle_dir)
errors.add(:bundle_dir, "Bundle directory: #{bundle_dir} not found.") unless File.directory?(bundle_dir)
end

def verify_content_metadata_creation
errors.add(:content_metadata_creation, "The SMPL manifest #{smpl_manifest} was not found in #{bundle_dir}.") if smpl_style? && !File.exist?(File.join(bundle_dir, smpl_manifest))
errors.add(:content_metadata_creation, "The SMPL manifest #{smpl_manifest} was not found in #{bundle_dir}.") if smpl_cm_style? && !File.exist?(File.join(bundle_dir, smpl_manifest))
end
end
2 changes: 1 addition & 1 deletion app/services/discovery_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def skipped_files

# @return [Boolean]
def using_smpl_manifest?
content_md_creation[:style] == :smpl && File.exist?(File.join(bundle_dir, content_md_creation[:smpl_manifest]))
content_md_creation == :smpl && File.exist?(File.join(bundle_dir, bundle.bundle_context.smpl_manifest))
end

# @return [PreAssembly::Smpl]
Expand Down
Loading

0 comments on commit 4018f78

Please sign in to comment.