lib/assembly-objectfile/content_metadata.rb in assembly-objectfile-1.6.8 vs lib/assembly-objectfile/content_metadata.rb in assembly-objectfile-1.7.0
- old
+ new
@@ -1,12 +1,14 @@
require 'nokogiri'
module Assembly
- SPECIAL_DPG_FOLDERS=['31','44','50'] # these special dpg folders will force any files contained in them into their own resources, regardless of filenaming convention
+ SPECIAL_DPG_FOLDERS = ['31', '44', '50'] # these special dpg folders will force any files contained in them into their own resources, regardless of filenaming convention
# these are used when :bundle=>:dpg only
-
+
+ DEPRECATED_STYLES = [:book_with_pdf, :book_as_image]
+
# This class generates content metadata for image files
class ContentMetadata
# Generates image content XML metadata for a repository object.
# This method only produces content metadata for images
@@ -18,32 +20,32 @@
# NOTE: if you set the :bundle option to :prebundled, you will need to pass in an array of arrays, and not a flat array, as noted below
# :style = optional - a symbol containing the style of metadata to create, allowed values are
# :simple_image (default), contentMetadata type="image", resource type="image"
# :file, contentMetadata type="file", resource type="file"
# :simple_book, contentMetadata type="book", resource type="page", but any resource which has file(s) other than an image, and also contains no images at all, will be resource type="object"
- # :book_with_pdf, contentMetadata type="book", resource type="page", but any resource which has any file(s) other than an image will be resource type="object"
- # :book_as_image, as simple_book, but with contentMetadata type="book", resource type="image" (same rule applies for resources with non images)
+ # :book_with_pdf, contentMetadata type="book", resource type="page", but any resource which has any file(s) other than an image will be resource type="object" - NOTE: THIS IS DEPRECATED
+ # :book_as_image, as simple_book, but with contentMetadata type="book", resource type="image" (same rule applies for resources with non images) - NOTE: THIS IS DEPRECATED
# :map, like simple_image, but with contentMetadata type="map", resource type="image"
# :bundle = optional - a symbol containing the method of bundling files into resources, allowed values are
# :default = all files get their own resources (default)
# :filename = files with the same filename but different extensions get bundled together in a single resource
# :dpg = files representing the same image but of different mimetype that use the SULAIR DPG filenaming standard (00 vs 05) get bundled together in a single resource
# :prebundlded = this option requires you to prebundled the files passed in as an array of arrays, indicating how files are bundlded into resources; this is the most flexible option since it gives you full control
# :add_exif = optional - a boolean to indicate if exif data should be added (mimetype, filesize, image height/width, etc.) to each file, defaults to false and is not required if project goes through assembly
- # :add_file_attributes = optional - a boolean to indicate if publish/preserve/shelve attributes should be added using defaults or by supplied override by mime/type, defaults to false and is not required if project goes through assembly
- # :file_attributes = optional - a hash of file attributes by mimetype to use instead of defaults, only used if add_file_attributes is also true,
+ # :add_file_attributes = optional - a boolean to indicate if publish/preserve/shelve/role attributes should be added using defaults or by supplied override by mime/type, defaults to false and is not required if project goes through assembly
+ # :file_attributes = optional - a hash of file attributes by mimetype to use instead of defaults, only used if add_file_attributes is also true,
# If a mimetype match is not found in your hash, the default is used (either your supplied default or the gems).
# e.g. {'default'=>{:preserve=>'yes',:shelve=>'yes',:publish=>'yes'},'image/tif'=>{:preserve=>'yes',:shelve=>'no',:publish=>'no'},'application/pdf'=>{:preserve=>'yes',:shelve=>'yes',:publish=>'yes'}}
# :include_root_xml = optional - a boolean to indicate if the contentMetadata returned includes a root <?xml version="1.0"?> tag, defaults to true
# :preserve_common_paths = optional - When creating the file "id" attribute, content metadata uses the "relative_path" attribute of the ObjectFile objects passed in. If the "relative_path" attribute is not set, the "path" attribute is used instead,
# which includes a full path to the file. If the "preserve_common_paths" parameter is set to false or left off, then the common paths of all of the ObjectFile's passed in are removed from any "path" attributes. This should turn full paths into
# the relative paths that are required in content metadata file id nodes. If you do not want this behavior, set "preserve_common_paths" to true. The default is false.
# :flatten_folder_structure = optional - Will remove *all* folder structure when genearting file IDs (e.g. DPG subfolders like '00','05' will be removed) when generating file IDs. This is useful if the folder structure is flattened when staging files (like for DPG).
# The default is false. If set to true, will override the "preserve_common_paths" parameter.
# :auto_labels = optional - Will add automated resource labels (e.g. "File 1") when labels are not provided by the user. The default is true.
# Example:
- # Assembly::Image.create_content_metadata(:druid=>'druid:nx288wh8889',:style=>:simple_image,:objects=>object_files,:add_file_attributes=>false)
+ # Assembly::ContentMetadata.create_content_metadata(:druid=>'druid:nx288wh8889',:style=>:simple_image,:objects=>object_files,:add_file_attributes=>false)
def self.create_content_metadata(params={})
druid=params[:druid]
objects=params[:objects]
@@ -91,10 +93,11 @@
content_type_description = content_type_descriptions[:map]
else
raise "Supplied style not valid"
end
+ puts "WARNING - the style #{style} is now deprecated and should not be used." if DEPRECATED_STYLES.include? style
# determine how many resources to create
# setup an array of arrays, where the first array is the number of resources, and the second array is the object files containined in that resource
case bundle
when :default # one resource per object
@@ -186,9 +189,10 @@
file_attributes_hash=obj.file_attributes || file_attributes[mimetype] || file_attributes['default'] || Assembly::FILE_ATTRIBUTES[mimetype] || Assembly::FILE_ATTRIBUTES['default']
xml_file_params.merge!({
:preserve => file_attributes_hash[:preserve],
:publish => file_attributes_hash[:publish],
:shelve => file_attributes_hash[:shelve],
+ :role => file_attributes_hash[:role],
})
end
xml_file_params.merge!({:mimetype => mimetype,:size => obj.filesize}) if add_exif
xml.file(xml_file_params) {