assembly-objectfile 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rvmrc.example +1 -0
- data/Gemfile +5 -0
- data/README.rdoc +94 -0
- data/Rakefile +4 -0
- data/assembly-objectfile.gemspec +29 -0
- data/bin/console +8 -0
- data/bin/run_all_tests +3 -0
- data/config/boot.rb +9 -0
- data/lib/assembly-objectfile.rb +35 -0
- data/lib/assembly-objectfile/content_metadata.rb +229 -0
- data/lib/assembly-objectfile/object_file.rb +30 -0
- data/lib/assembly-objectfile/object_fileable.rb +263 -0
- data/lib/assembly-objectfile/version.rb +9 -0
- data/profiles/AdobeRGB1998.icc +0 -0
- data/profiles/DotGain20.icc +0 -0
- data/profiles/sRGBIEC6196621.icc +0 -0
- data/spec/content_metadata_spec.rb +563 -0
- data/spec/object_file_spec.rb +115 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/test_data/input/.empty +0 -0
- data/spec/test_data/input/file_with_no_exif.xml +83 -0
- data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
- data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
- data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
- data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
- data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +1 -0
- data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +1 -0
- data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +1 -0
- data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
- data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +1 -0
- data/spec/test_data/input/res1_image1.jp2 +0 -0
- data/spec/test_data/input/res1_image1.tif +0 -0
- data/spec/test_data/input/res1_image2.jp2 +0 -0
- data/spec/test_data/input/res1_image2.tif +0 -0
- data/spec/test_data/input/res1_teifile.txt +1 -0
- data/spec/test_data/input/res1_textfile.txt +1 -0
- data/spec/test_data/input/res1_transcript.pdf +1 -0
- data/spec/test_data/input/res2_image1.jp2 +0 -0
- data/spec/test_data/input/res2_image1.tif +0 -0
- data/spec/test_data/input/res2_image2.jp2 +0 -0
- data/spec/test_data/input/res2_image2.tif +0 -0
- data/spec/test_data/input/res2_teifile.txt +1 -0
- data/spec/test_data/input/res2_textfile.txt +1 -0
- data/spec/test_data/input/res3_image1.jp2 +0 -0
- data/spec/test_data/input/res3_image1.tif +0 -0
- data/spec/test_data/input/res3_teifile.txt +1 -0
- data/spec/test_data/input/test.jp2 +0 -0
- data/spec/test_data/input/test.pdf +1 -0
- data/spec/test_data/input/test.tif +0 -0
- data/spec/test_data/input/test2.jp2 +0 -0
- data/spec/test_data/input/test2.tif +0 -0
- metadata +260 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
module Assembly
|
2
|
+
|
3
|
+
# This class contains generic methods to operate on any file.
|
4
|
+
class ObjectFile
|
5
|
+
|
6
|
+
include Assembly::ObjectFileable
|
7
|
+
|
8
|
+
# Class level method that given an array of strings, return the longest common initial path. Useful for removing a common path from a set of filenames when producing content metadata
|
9
|
+
#
|
10
|
+
# @param [Array] strings Array of filenames with paths to operate on
|
11
|
+
# @return [String] Common part of path of filenames passed in
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
# puts Assembly::ObjectFile.common_prefix(['/Users/peter/00/test.tif','/Users/peter/05/test.jp2']) # '/Users/peter/0'
|
15
|
+
def self.common_path(strings)
|
16
|
+
return nil if strings.size == 0
|
17
|
+
n = 0
|
18
|
+
x = strings.last
|
19
|
+
n += 1 while strings.all? { |s| s[n] and s[n] == x[n] }
|
20
|
+
common_prefix=x[0...n]
|
21
|
+
if common_prefix[-1,1] != '/' # check if last element of the common string is the end of a directory
|
22
|
+
return common_prefix.split('/')[0..-2].join('/') + "/" # if not, split string along directories, and reject last one
|
23
|
+
else
|
24
|
+
return common_prefix # if it was, then return the common prefix directly
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
require 'mini_exiftool'
|
2
|
+
require 'mime/types'
|
3
|
+
#require 'checksum-tools'
|
4
|
+
|
5
|
+
module Assembly
|
6
|
+
|
7
|
+
# Namespace to include common behaviors we need for other classes in the gem
|
8
|
+
module ObjectFileable
|
9
|
+
|
10
|
+
# path is the full path to the user provided image
|
11
|
+
attr_accessor :path
|
12
|
+
|
13
|
+
# an optional label that can be set for each file -- if provided, this will be used as a resource label when generating content metadata (files bundlded together will just get the first's files label attribute if set)
|
14
|
+
attr_accessor :label
|
15
|
+
|
16
|
+
# an optional hash that is used to set the file attributes (publish,preserve,shelve) for the given file when generating content metadata (if not supplied, mimetype defaults are used)
|
17
|
+
# e.g. {:preserve=>'yes',:shelve=>'no',:publish=>'no'}
|
18
|
+
attr_accessor :file_attributes
|
19
|
+
|
20
|
+
# relative path is useful when generating content metadata, if you want the file ids in the content metadata to be something other than the full path, it can be set
|
21
|
+
# if not, content metadata will get the full path
|
22
|
+
attr_accessor :relative_path
|
23
|
+
|
24
|
+
# provider checksums are optional checksums given by the provider used in content metadata generation
|
25
|
+
attr_accessor :provider_md5, :provider_sha1
|
26
|
+
|
27
|
+
# Initialize file from given path.
|
28
|
+
#
|
29
|
+
# @param [String] path full path to the file to be worked with
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# Assembly::ObjectFile.new('/input/path_to_file.tif')
|
33
|
+
def initialize(path,params={})
|
34
|
+
@path = path
|
35
|
+
@label = params[:label]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns base DPG name for the current file.
|
39
|
+
#
|
40
|
+
# @return [String] DPG base filename, removing the extension and the '00','05', etc. placeholders
|
41
|
+
#
|
42
|
+
# Example:
|
43
|
+
# source_file=Assembly::ObjectFile.new('/input/cy565rm7188_00_001.tif')
|
44
|
+
# puts source_file.dpg_basename # "cy565rm7188_001"
|
45
|
+
def dpg_basename
|
46
|
+
file_parts=File.basename(path,ext).split('_')
|
47
|
+
file_parts.size == 3 ? "#{file_parts[0]}_#{file_parts[2]}" : filename_without_ext
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns DPG subfolder for the current file.
|
51
|
+
#
|
52
|
+
# @return [String] DPG subfolder for the given filename, i.e. '00','05', etc.
|
53
|
+
#
|
54
|
+
# Example:
|
55
|
+
# source_file=Assembly::ObjectFile.new('/input/cy565rm7188_00_001.tif')
|
56
|
+
# puts source_file.dpg_folder # "00"
|
57
|
+
def dpg_folder
|
58
|
+
file_parts=File.basename(path,ext).split('_')
|
59
|
+
file_parts.size == 3 ? file_parts[1] : ''
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns base filename for the current file.
|
63
|
+
#
|
64
|
+
# @return [String] base filename
|
65
|
+
#
|
66
|
+
# Example:
|
67
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
68
|
+
# puts source_file.filename # "path_to_file.tif"
|
69
|
+
def filename
|
70
|
+
File.basename(path)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns base directory path for the current file.
|
74
|
+
#
|
75
|
+
# @return [String] base directory
|
76
|
+
#
|
77
|
+
# Example:
|
78
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
79
|
+
# puts source_file.dirname # "/input"
|
80
|
+
def dirname
|
81
|
+
File.dirname(path)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns filename extension
|
85
|
+
#
|
86
|
+
# @return [String] filename extension
|
87
|
+
#
|
88
|
+
# Example:
|
89
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
90
|
+
# puts source_file.ext # ".tif"
|
91
|
+
def ext
|
92
|
+
File.extname(path)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Returns base filename without extension for the current file.
|
96
|
+
#
|
97
|
+
# @return [String] base filename without extension
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
101
|
+
# puts source_file.filename # "path_to_file"
|
102
|
+
def filename_without_ext
|
103
|
+
File.basename(path,ext)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns exif information for the current file.
|
107
|
+
#
|
108
|
+
# @return [MiniExiftool] exif information stored as a hash and an object
|
109
|
+
#
|
110
|
+
# Example:
|
111
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
112
|
+
# puts source_file.exif # gives hash with exif information
|
113
|
+
def exif
|
114
|
+
check_for_file unless @exif
|
115
|
+
begin
|
116
|
+
@exif ||= MiniExiftool.new @path
|
117
|
+
rescue
|
118
|
+
@exif = nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Compute md5 checksum or return value if already computed
|
123
|
+
#
|
124
|
+
# @return [string] md5 checksum for given file
|
125
|
+
#
|
126
|
+
# Example:
|
127
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
128
|
+
# puts source_file.md5 # gives XXX123XXX1243XX1243
|
129
|
+
def md5
|
130
|
+
check_for_file unless @md5
|
131
|
+
@md5 ||= Digest::MD5.file(path).hexdigest
|
132
|
+
end
|
133
|
+
|
134
|
+
# Compute sha1 checksum or return value if already computed
|
135
|
+
#
|
136
|
+
# @return [string] sha1 checksum for given file
|
137
|
+
#
|
138
|
+
# Example:
|
139
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
140
|
+
# puts source_file.sha1 # gives XXX123XXX1243XX1243
|
141
|
+
def sha1
|
142
|
+
check_for_file unless @sha1
|
143
|
+
@sha1 ||= Digest::SHA1.file(path).hexdigest
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns mimetype information for the current file (only on unix based systems).
|
147
|
+
#
|
148
|
+
# @return [string] mime type for supplied file
|
149
|
+
#
|
150
|
+
# Example:
|
151
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.txt')
|
152
|
+
# puts source_file.mimetype # gives 'text/plain'
|
153
|
+
def mimetype
|
154
|
+
check_for_file unless @mimetype
|
155
|
+
if @mimetype.nil? # if we haven't computed it yet once for this object, try and get the mimetype
|
156
|
+
@mimetype = `file --mime-type "#{@path}"`.gsub(/\n/,"").split(':')[1].strip # first try and get the mimetype from the unix file command
|
157
|
+
@mimetype = exif.mimetype if (!Assembly::TRUSTED_MIMETYPES.include?(@mimetype) && !exif.nil? && !exif.mimetype.nil?) # if it's not a "trusted" mimetype and there is exif data; get the mimetype from the exif
|
158
|
+
end
|
159
|
+
return @mimetype
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns encoding information for the current file (only on unix based systems).
|
163
|
+
#
|
164
|
+
# @return [string] encoding for supplied file
|
165
|
+
#
|
166
|
+
# Example:
|
167
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.txt')
|
168
|
+
# puts source_file.encoding # gives 'us-ascii'
|
169
|
+
def encoding
|
170
|
+
check_for_file unless @encoding
|
171
|
+
@encoding ||= `file --mime-encoding "#{@path}"`.gsub(/\n/,"").split(':')[1].strip
|
172
|
+
end
|
173
|
+
|
174
|
+
# Returns a symbol with the objects type
|
175
|
+
#
|
176
|
+
# @return [symbol] the type of object, could be :application (for PDF or Word, etc), :audio, :image, :message, :model, :multipart, :text or :video
|
177
|
+
#
|
178
|
+
# Example:
|
179
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
180
|
+
# puts source_file.object_type # gives :image
|
181
|
+
def object_type
|
182
|
+
lookup=MIME::Types[mimetype][0]
|
183
|
+
return (lookup.nil? ? "other".to_sym : lookup.media_type.to_sym)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Returns if the object file is an image.
|
187
|
+
#
|
188
|
+
# @return [boolean] if object is an image
|
189
|
+
#
|
190
|
+
# Example:
|
191
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
192
|
+
# puts source_file.image? # gives TRUE
|
193
|
+
def image?
|
194
|
+
object_type == :image
|
195
|
+
end
|
196
|
+
|
197
|
+
# Examines the input image for validity. Used to determine if image is a valid and useful image. If image is not a jp2, also checks for a valid profile.
|
198
|
+
#
|
199
|
+
# @return [boolean] true if image is valid, false if not.
|
200
|
+
#
|
201
|
+
# Example:
|
202
|
+
# source_img=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
203
|
+
# puts source_img.valid_image? # gives true
|
204
|
+
def valid_image?
|
205
|
+
|
206
|
+
result= image? ? true : false
|
207
|
+
result= jp2able? unless mimetype == 'image/jp2' # further checks if we are not already a jp2
|
208
|
+
|
209
|
+
return result
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
# Examines the input image for validity to create a jp2. Same as valid_image? but also confirms the existence of a profile description and further restricts mimetypes.
|
214
|
+
# It is used by the assembly robots to decide if a jp2 will be created and is also called before you create a jp2 using assembly-image.
|
215
|
+
# @return [boolean] true if image should have a jp2 created, false if not.
|
216
|
+
#
|
217
|
+
# Example:
|
218
|
+
# source_img=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
219
|
+
# puts source_img.jp2able? # gives true
|
220
|
+
def jp2able?
|
221
|
+
|
222
|
+
result=false
|
223
|
+
unless exif.nil?
|
224
|
+
result=(Assembly::VALID_IMAGE_MIMETYPES.include?(mimetype)) # check for allowed image mimetypes that can be converted to jp2
|
225
|
+
result=(exif['profiledescription'] != nil) # check for existence of profile description
|
226
|
+
end
|
227
|
+
return result
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
# Returns file size information for the current file in bytes.
|
232
|
+
#
|
233
|
+
# @return [integer] file size in bytes
|
234
|
+
#
|
235
|
+
# Example:
|
236
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
237
|
+
# puts source_file.filesize # gives 1345
|
238
|
+
def filesize
|
239
|
+
check_for_file
|
240
|
+
@filesize ||= File.size @path
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
# Determines if the file exists (and is not a directory)
|
245
|
+
#
|
246
|
+
# @return [boolean] file exists
|
247
|
+
#
|
248
|
+
# Example:
|
249
|
+
# source_file=Assembly::ObjectFile.new('/input/path_to_file.tif')
|
250
|
+
# puts source_file.file_exists? # gives true
|
251
|
+
def file_exists?
|
252
|
+
File.exists?(@path) && !File.directory?(@path)
|
253
|
+
end
|
254
|
+
|
255
|
+
private
|
256
|
+
# private method to check for file existence before operating on it
|
257
|
+
def check_for_file
|
258
|
+
raise "input file #{path} does not exist" unless file_exists?
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,563 @@
|
|
1
|
+
describe Assembly::ContentMetadata do
|
2
|
+
|
3
|
+
it "should generate valid content metadata with exif for a single tif and jp2 of style=simple_image, adding file attributes" do
|
4
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
5
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:add_exif=>true,:add_file_attributes=>true,:objects=>objects)
|
6
|
+
result.class.should be String
|
7
|
+
xml = Nokogiri::XML(result)
|
8
|
+
xml.errors.size.should be 0
|
9
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
10
|
+
xml.xpath("//resource").length.should be 2
|
11
|
+
xml.xpath("//resource/file").length.should be 2
|
12
|
+
xml.xpath("//resource/file/checksum").length.should be 4
|
13
|
+
xml.xpath("//resource/file/checksum")[0].text.should == "8d11fab63089a24c8b17063d29a4b0eac359fb41"
|
14
|
+
xml.xpath("//resource/file/checksum")[1].text.should == "a2400500acf21e43f5440d93be894101"
|
15
|
+
xml.xpath("//resource/file/checksum")[2].text.should == "b965b5787e0100ec2d43733144120feab327e88c"
|
16
|
+
xml.xpath("//resource/file/checksum")[3].text.should == "4eb54050d374291ece622d45e84f014d"
|
17
|
+
xml.xpath("//label").length.should be 2
|
18
|
+
xml.xpath("//label")[0].text.should =~ /Image 1/
|
19
|
+
xml.xpath("//label")[1].text.should =~ /Image 2/
|
20
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "image"
|
21
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "image"
|
22
|
+
xml.xpath("//resource/file")[0].attributes['size'].value.should == "63542"
|
23
|
+
xml.xpath("//resource/file")[0].attributes['mimetype'].value.should == "image/tiff"
|
24
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "no"
|
25
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "yes"
|
26
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no"
|
27
|
+
xml.xpath("//resource/file/imageData")[0].attributes['width'].value.should == "100"
|
28
|
+
xml.xpath("//resource/file/imageData")[0].attributes['height'].value.should == "100"
|
29
|
+
xml.xpath("//resource/file")[1].attributes['size'].value.should == "306"
|
30
|
+
xml.xpath("//resource/file")[1].attributes['mimetype'].value.should == "image/jp2"
|
31
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes"
|
32
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "no"
|
33
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes"
|
34
|
+
xml.xpath("//resource/file/imageData")[1].attributes['width'].value.should == "100"
|
35
|
+
xml.xpath("//resource/file/imageData")[1].attributes['height'].value.should == "100"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should generate valid content metadata with no exif for a single tif and jp2 of style=simple_image, adding specific file attributes for 2 objects, and defaults for 1 object" do
|
39
|
+
obj1=Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
40
|
+
obj2=Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
|
41
|
+
obj3=Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
|
42
|
+
obj1.file_attributes={:publish=>'no',:preserve=>'no',:shelve=>'no'}
|
43
|
+
obj2.file_attributes={:publish=>'yes',:preserve=>'yes',:shelve=>'yes'}
|
44
|
+
objects=[obj1,obj2,obj3]
|
45
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:add_exif=>false,:add_file_attributes=>true,:objects=>objects)
|
46
|
+
result.class.should be String
|
47
|
+
xml = Nokogiri::XML(result)
|
48
|
+
xml.errors.size.should be 0
|
49
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
50
|
+
xml.xpath("//resource").length.should be 3
|
51
|
+
xml.xpath("//resource/file").length.should be 3
|
52
|
+
xml.xpath("//resource/file/checksum").length.should be 0
|
53
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
54
|
+
xml.xpath("//label").length.should be 3
|
55
|
+
xml.xpath("//label")[0].text.should =~ /Image 1/
|
56
|
+
xml.xpath("//label")[1].text.should =~ /Image 2/
|
57
|
+
xml.xpath("//label")[2].text.should =~ /Image 3/
|
58
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "image"
|
59
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "image"
|
60
|
+
xml.xpath("//resource")[2].attributes['type'].value.should == "image"
|
61
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "no" # specificially set in object
|
62
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "no" # specificially set in object
|
63
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no" # specificially set in object
|
64
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes" # specificially set in object
|
65
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "yes" # specificially set in object
|
66
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes" # specificially set in object
|
67
|
+
xml.xpath("//resource/file")[2].attributes['publish'].value.should == "yes" # defaults by mimetype
|
68
|
+
xml.xpath("//resource/file")[2].attributes['preserve'].value.should == "no" # defaults by mimetype
|
69
|
+
xml.xpath("//resource/file")[2].attributes['shelve'].value.should == "yes" # defaults by mimetype
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it "should generate valid content metadata with exif for a single tif and jp2 of style=simple_image overriding file labels" do
|
74
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE,:label=>'Sample tif label!'),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE,:label=>'Sample jp2 label!')]
|
75
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:add_exif=>true,:add_file_attributes=>true,:objects=>objects)
|
76
|
+
result.class.should be String
|
77
|
+
xml = Nokogiri::XML(result)
|
78
|
+
xml.errors.size.should be 0
|
79
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
80
|
+
xml.xpath("//resource").length.should be 2
|
81
|
+
xml.xpath("//resource/file").length.should be 2
|
82
|
+
xml.xpath("//resource/file/checksum").length.should be 4
|
83
|
+
xml.xpath("//resource/file/checksum")[0].text.should == "8d11fab63089a24c8b17063d29a4b0eac359fb41"
|
84
|
+
xml.xpath("//resource/file/checksum")[1].text.should == "a2400500acf21e43f5440d93be894101"
|
85
|
+
xml.xpath("//resource/file/checksum")[2].text.should == "b965b5787e0100ec2d43733144120feab327e88c"
|
86
|
+
xml.xpath("//resource/file/checksum")[3].text.should == "4eb54050d374291ece622d45e84f014d"
|
87
|
+
xml.xpath("//label").length.should be 2
|
88
|
+
xml.xpath("//label")[0].text.should =~ /Sample tif label!/
|
89
|
+
xml.xpath("//label")[1].text.should =~ /Sample jp2 label!/
|
90
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "image"
|
91
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "image"
|
92
|
+
xml.xpath("//resource/file")[0].attributes['size'].value.should == "63542"
|
93
|
+
xml.xpath("//resource/file")[0].attributes['mimetype'].value.should == "image/tiff"
|
94
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "no"
|
95
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "yes"
|
96
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no"
|
97
|
+
xml.xpath("//resource/file/imageData")[0].attributes['width'].value.should == "100"
|
98
|
+
xml.xpath("//resource/file/imageData")[0].attributes['height'].value.should == "100"
|
99
|
+
xml.xpath("//resource/file")[1].attributes['size'].value.should == "306"
|
100
|
+
xml.xpath("//resource/file")[1].attributes['mimetype'].value.should == "image/jp2"
|
101
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes"
|
102
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "no"
|
103
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes"
|
104
|
+
xml.xpath("//resource/file/imageData")[1].attributes['width'].value.should == "100"
|
105
|
+
xml.xpath("//resource/file/imageData")[1].attributes['height'].value.should == "100"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should generate valid content metadata with exif for a single tif and jp2 of style=simple_image overriding file labels for one, and skipping auto labels for the others or for where the label is set but is blank" do
|
109
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE,:label=>'Sample tif label!'),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE,:label=>'')]
|
110
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:auto_labels=>false,:add_file_attributes=>true,:objects=>objects)
|
111
|
+
result.class.should be String
|
112
|
+
xml = Nokogiri::XML(result)
|
113
|
+
xml.errors.size.should be 0
|
114
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
115
|
+
xml.xpath("//resource").length.should be 3
|
116
|
+
xml.xpath("//resource/file").length.should be 3
|
117
|
+
xml.xpath("//label").length.should be 1
|
118
|
+
xml.xpath("//label")[0].text.should =~ /Sample tif label!/
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should generate valid content metadata for a single tif and jp2 of style=simple_image with overriding file attributes and no exif data" do
|
122
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
123
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:add_file_attributes=>true,:file_attributes=>{'image/tiff'=>{:publish=>'no',:preserve=>'no',:shelve=>'no'},'image/jp2'=>{:publish=>'yes',:preserve=>'yes',:shelve=>'yes'}},:objects=>objects)
|
124
|
+
result.class.should be String
|
125
|
+
xml = Nokogiri::XML(result)
|
126
|
+
xml.errors.size.should be 0
|
127
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
128
|
+
xml.xpath("//resource").length.should be 2
|
129
|
+
xml.xpath("//resource/file").length.should be 2
|
130
|
+
xml.xpath("//label").length.should be 2
|
131
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
132
|
+
xml.xpath("//label")[0].text.should =~ /Image 1/
|
133
|
+
xml.xpath("//label")[1].text.should =~ /Image 2/
|
134
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "image"
|
135
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "image"
|
136
|
+
xml.xpath("//resource/file")[0].attributes['size'].should be nil
|
137
|
+
xml.xpath("//resource/file")[0].attributes['mimetype'].should be nil
|
138
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "no"
|
139
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "no"
|
140
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no"
|
141
|
+
xml.xpath("//resource/file")[1].attributes['size'].should be nil
|
142
|
+
xml.xpath("//resource/file")[1].attributes['mimetype'].should be nil
|
143
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes"
|
144
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "yes"
|
145
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should generate valid content metadata for a single tif and jp2 of style=simple_image with overriding file attributes, including a default value, and no exif data" do
|
149
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
150
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:add_file_attributes=>true,:file_attributes=>{'default'=>{:publish=>'yes',:preserve=>'no',:shelve=>'no'},'image/jp2'=>{:publish=>'yes',:preserve=>'yes',:shelve=>'yes'}},:objects=>objects)
|
151
|
+
result.class.should be String
|
152
|
+
xml = Nokogiri::XML(result)
|
153
|
+
xml.errors.size.should be 0
|
154
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
155
|
+
xml.xpath("//resource/file").length.should be 2
|
156
|
+
xml.xpath("//resource/file")[0].attributes['mimetype'].should be nil
|
157
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "yes"
|
158
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "no"
|
159
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no"
|
160
|
+
xml.xpath("//resource/file")[1].attributes['mimetype'].should be nil
|
161
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes"
|
162
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "yes"
|
163
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes"
|
164
|
+
for i in 0..1 do
|
165
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 1
|
166
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
167
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should generate valid content metadata for a single tif and jp2 of style=map with overriding file attributes, including a default value, and no exif data" do
|
172
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
173
|
+
result = Assembly::ContentMetadata.create_content_metadata(:style=>:map,:druid=>TEST_DRUID,:add_file_attributes=>true,:file_attributes=>{'default'=>{:publish=>'yes',:preserve=>'no',:shelve=>'no'},'image/jp2'=>{:publish=>'yes',:preserve=>'yes',:shelve=>'yes'}},:objects=>objects)
|
174
|
+
result.class.should be String
|
175
|
+
xml = Nokogiri::XML(result)
|
176
|
+
xml.errors.size.should be 0
|
177
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "map"
|
178
|
+
xml.xpath("//resource/file").length.should be 2
|
179
|
+
xml.xpath("//resource/file")[0].attributes['mimetype'].should be nil
|
180
|
+
xml.xpath("//resource/file")[0].attributes['publish'].value.should == "yes"
|
181
|
+
xml.xpath("//resource/file")[0].attributes['preserve'].value.should == "no"
|
182
|
+
xml.xpath("//resource/file")[0].attributes['shelve'].value.should == "no"
|
183
|
+
xml.xpath("//resource/file")[1].attributes['mimetype'].should be nil
|
184
|
+
xml.xpath("//resource/file")[1].attributes['publish'].value.should == "yes"
|
185
|
+
xml.xpath("//resource/file")[1].attributes['preserve'].value.should == "yes"
|
186
|
+
xml.xpath("//resource/file")[1].attributes['shelve'].value.should == "yes"
|
187
|
+
for i in 0..1 do
|
188
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 1
|
189
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
190
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should generate valid content metadata for two tifs two associated jp2s of style=simple_image using bundle=filename and no exif data" do
|
195
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
|
196
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:filename,:objects=>objects)
|
197
|
+
result.class.should be String
|
198
|
+
xml = Nokogiri::XML(result)
|
199
|
+
xml.errors.size.should be 0
|
200
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
201
|
+
xml.xpath("//resource").length.should be 2
|
202
|
+
xml.xpath("//resource/file").length.should be 4
|
203
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == 'test.tif'
|
204
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == 'test.jp2'
|
205
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == 'test2.tif'
|
206
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == 'test2.jp2'
|
207
|
+
xml.xpath("//label").length.should be 2
|
208
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
209
|
+
for i in 0..1 do
|
210
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 2
|
211
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
212
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should generate valid content metadata for two tifs two associated jp2s of style=simple_image using bundle=dpg and no exif data and no root xml node" do
|
217
|
+
objects=[Assembly::ObjectFile.new(TEST_DPG_TIF),Assembly::ObjectFile.new(TEST_DPG_JP),Assembly::ObjectFile.new(TEST_DPG_TIF2),Assembly::ObjectFile.new(TEST_DPG_JP2)]
|
218
|
+
test_druid="#{TEST_DRUID}"
|
219
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>test_druid,:bundle=>:dpg,:objects=>objects,:include_root_xml=>false)
|
220
|
+
result.class.should be String
|
221
|
+
result.include?('<?xml').should be false
|
222
|
+
xml = Nokogiri::XML(result)
|
223
|
+
xml.errors.size.should be 0
|
224
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
225
|
+
test_druid.should == TEST_DRUID
|
226
|
+
xml.xpath("//contentMetadata")[0].attributes['objectId'].value.should == "#{TEST_DRUID}"
|
227
|
+
xml.xpath("//resource").length.should be 2
|
228
|
+
xml.xpath("//resource/file").length.should be 4
|
229
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == "00/oo000oo0001_00_001.tif"
|
230
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == "05/oo000oo0001_05_001.jp2"
|
231
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == "00/oo000oo0001_00_002.tif"
|
232
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == "05/oo000oo0001_05_002.jp2"
|
233
|
+
xml.xpath("//label").length.should be 2
|
234
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
235
|
+
for i in 0..1 do
|
236
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 2
|
237
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
238
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should generate valid content metadata for two tifs, two associated jp2s, one combined pdf and one special tif of style=simple_book using bundle=dpg and no exif data and no root xml node, flattening folder structure" do
|
243
|
+
objects=[Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF2),Assembly::ObjectFile.new(TEST_DPG_SPECIAL_TIF),Assembly::ObjectFile.new(TEST_DPG_TIF),Assembly::ObjectFile.new(TEST_DPG_JP),Assembly::ObjectFile.new(TEST_DPG_TIF2),Assembly::ObjectFile.new(TEST_DPG_JP2)]
|
244
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:simple_book,:bundle=>:dpg,:objects=>objects,:include_root_xml=>false,:flatten_folder_structure=>true)
|
245
|
+
result.class.should be String
|
246
|
+
result.include?('<?xml').should be false
|
247
|
+
xml = Nokogiri::XML(result)
|
248
|
+
xml.errors.size.should be 0
|
249
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
250
|
+
xml.xpath("//contentMetadata")[0].attributes['objectId'].value.should == "#{TEST_DRUID}"
|
251
|
+
xml.xpath("//resource").length.should be 4
|
252
|
+
xml.xpath("//resource/file").length.should be 6
|
253
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == "oo000oo0001_00_001.tif"
|
254
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == "oo000oo0001_05_001.jp2"
|
255
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == "oo000oo0001_00_002.tif"
|
256
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == "oo000oo0001_05_002.jp2"
|
257
|
+
xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value.should == "oo000oo0001_31_001.pdf"
|
258
|
+
xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value.should == "oo000oo0001_50_001.tif"
|
259
|
+
xml.xpath("//label").length.should be 4
|
260
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
261
|
+
for i in 0..1 do
|
262
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 2
|
263
|
+
xml.xpath("//label")[i].text.should == "Page #{i+1}"
|
264
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "page"
|
265
|
+
end
|
266
|
+
xml.xpath("//resource[@sequence='3']/file").length.should be 1
|
267
|
+
xml.xpath("//label")[2].text.should == "Object 1"
|
268
|
+
xml.xpath("//resource")[2].attributes['type'].value.should == "object"
|
269
|
+
xml.xpath("//resource[@sequence='4']/file").length.should be 1
|
270
|
+
xml.xpath("//label")[3].text.should == "Object 2"
|
271
|
+
xml.xpath("//resource")[3].attributes['type'].value.should == "object"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should generate valid content metadata with item having a 'druid:' prefix for two tifs,two associated jp2s,two associated pdfs, and one lingering PDF of style=simple_book using bundle=dpg, flattening folder structure" do
|
275
|
+
objects=[Assembly::ObjectFile.new(TEST_DPG_TIF),Assembly::ObjectFile.new(TEST_DPG_JP),Assembly::ObjectFile.new(TEST_DPG_PDF),Assembly::ObjectFile.new(TEST_DPG_TIF2),Assembly::ObjectFile.new(TEST_DPG_JP2),Assembly::ObjectFile.new(TEST_DPG_PDF2),Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
|
276
|
+
test_druid="druid:#{TEST_DRUID}"
|
277
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>test_druid,:bundle=>:dpg,:objects=>objects,:style=>:simple_book,:flatten_folder_structure=>true)
|
278
|
+
result.class.should be String
|
279
|
+
result.include?('<?xml').should be true
|
280
|
+
xml = Nokogiri::XML(result)
|
281
|
+
xml.errors.size.should be 0
|
282
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
283
|
+
xml.xpath("//contentMetadata")[0].attributes['objectId'].value.should == "#{TEST_DRUID}"
|
284
|
+
test_druid.should == "druid:#{TEST_DRUID}"
|
285
|
+
xml.xpath("//resource").length.should be 3
|
286
|
+
xml.xpath("//resource/file").length.should be 7
|
287
|
+
|
288
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == "oo000oo0001_00_001.tif"
|
289
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == "oo000oo0001_05_001.jp2"
|
290
|
+
xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value.should == "oo000oo0001_15_001.pdf"
|
291
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == "oo000oo0001_00_002.tif"
|
292
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == "oo000oo0001_05_002.jp2"
|
293
|
+
xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value.should == "oo000oo0001_15_002.pdf"
|
294
|
+
xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value.should == "oo000oo0001_book.pdf"
|
295
|
+
xml.xpath("//label").length.should be 3
|
296
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
297
|
+
for i in 0..1 do
|
298
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 3
|
299
|
+
xml.xpath("//label")[i].text.should == "Page #{i+1}"
|
300
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "page"
|
301
|
+
end
|
302
|
+
xml.xpath("//resource[@sequence='3']/file").length.should be 1
|
303
|
+
xml.xpath("//label")[2].text.should == "Object 1"
|
304
|
+
xml.xpath("//resource")[2].attributes['type'].value.should == "object"
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should generate valid content metadata for two tifs,two associated jp2s,two associated pdfs, and one lingering PDF of style=book_with_pdf using bundle=dpg" do
|
308
|
+
objects=[Assembly::ObjectFile.new(TEST_DPG_TIF),Assembly::ObjectFile.new(TEST_DPG_JP),Assembly::ObjectFile.new(TEST_DPG_PDF),Assembly::ObjectFile.new(TEST_DPG_TIF2),Assembly::ObjectFile.new(TEST_DPG_JP2),Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
|
309
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:dpg,:objects=>objects,:style=>:book_with_pdf)
|
310
|
+
result.class.should be String
|
311
|
+
xml = Nokogiri::XML(result)
|
312
|
+
xml.errors.size.should be 0
|
313
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
314
|
+
xml.xpath("//resource").length.should be 3
|
315
|
+
xml.xpath("//resource/file").length.should be 6
|
316
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == "00/oo000oo0001_00_001.tif"
|
317
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == "05/oo000oo0001_05_001.jp2"
|
318
|
+
xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value.should == "15/oo000oo0001_15_001.pdf"
|
319
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == "00/oo000oo0001_00_002.tif"
|
320
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == "05/oo000oo0001_05_002.jp2"
|
321
|
+
xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value.should == "oo000oo0001_book.pdf"
|
322
|
+
xml.xpath("//label").length.should be 3
|
323
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
324
|
+
xml.xpath("//resource[@sequence='1']/file").length.should be 3
|
325
|
+
xml.xpath("//label")[0].text.should == "Object 1"
|
326
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "object"
|
327
|
+
xml.xpath("//resource[@sequence='2']/file").length.should be 2
|
328
|
+
xml.xpath("//label")[1].text.should == "Page 1"
|
329
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "page"
|
330
|
+
xml.xpath("//resource[@sequence='3']/file").length.should be 1
|
331
|
+
xml.xpath("//label")[2].text.should == "Object 2"
|
332
|
+
xml.xpath("//resource")[2].attributes['type'].value.should == "object"
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should generate valid content metadata for two tifs two associated jp2s of style=simple_image using bundle=default and no exif data" do
|
336
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
|
337
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:default,:objects=>objects)
|
338
|
+
result.class.should be String
|
339
|
+
xml = Nokogiri::XML(result)
|
340
|
+
xml.errors.size.should be 0
|
341
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
342
|
+
xml.xpath("//resource").length.should be 4
|
343
|
+
xml.xpath("//resource/file").length.should be 4
|
344
|
+
xml.xpath("//resource/file")[0].attributes['id'].value.should == 'test.tif'
|
345
|
+
xml.xpath("//resource/file")[1].attributes['id'].value.should == 'test.jp2'
|
346
|
+
xml.xpath("//resource/file")[2].attributes['id'].value.should == 'test2.tif'
|
347
|
+
xml.xpath("//resource/file")[3].attributes['id'].value.should == 'test2.jp2'
|
348
|
+
xml.xpath("//label").length.should be 4
|
349
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
350
|
+
for i in 0..3 do
|
351
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 1
|
352
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
353
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should generate valid content metadata for two tifs two associated jp2s of style=simple_image using bundle=default and no exif data, preserving full paths" do
|
358
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
|
359
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:default,:objects=>objects,:preserve_common_paths=>true)
|
360
|
+
result.class.should be String
|
361
|
+
xml = Nokogiri::XML(result)
|
362
|
+
xml.errors.size.should be 0
|
363
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
364
|
+
xml.xpath("//resource").length.should be 4
|
365
|
+
xml.xpath("//resource/file").length.should be 4
|
366
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == TEST_TIF_INPUT_FILE
|
367
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == TEST_JP2_INPUT_FILE
|
368
|
+
xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value.should == TEST_TIF_INPUT_FILE2
|
369
|
+
xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value.should == TEST_JP2_INPUT_FILE2
|
370
|
+
xml.xpath("//label").length.should be 4
|
371
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
372
|
+
for i in 0..3 do
|
373
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 1
|
374
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
375
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should generate valid content metadata for two tifs two associated jp2s of style=file using specific content metadata paths" do
|
380
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)]
|
381
|
+
objects[0].relative_path='input/test.tif'
|
382
|
+
objects[1].relative_path='input/test.jp2'
|
383
|
+
objects[2].relative_path='input/test2.tif'
|
384
|
+
objects[3].relative_path='input/test2.jp2'
|
385
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:file,:objects=>objects)
|
386
|
+
result.class.should be String
|
387
|
+
xml = Nokogiri::XML(result)
|
388
|
+
xml.errors.size.should be 0
|
389
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "file"
|
390
|
+
xml.xpath("//resource").length.should be 4
|
391
|
+
xml.xpath("//resource/file").length.should be 4
|
392
|
+
xml.xpath("//label").length.should be 4
|
393
|
+
xml.xpath("//resource/file")[0].attributes['id'].value.should == 'input/test.tif'
|
394
|
+
xml.xpath("//resource/file")[1].attributes['id'].value.should == 'input/test.jp2'
|
395
|
+
xml.xpath("//resource/file")[2].attributes['id'].value.should == 'input/test2.tif'
|
396
|
+
xml.xpath("//resource/file")[3].attributes['id'].value.should == 'input/test2.jp2'
|
397
|
+
for i in 0..3 do
|
398
|
+
xml.xpath("//resource[@sequence='#{i+1}']/file").length.should be 1
|
399
|
+
xml.xpath("//label")[i].text.should == "File #{i+1}"
|
400
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "file"
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should generate valid content metadata for two tifs of style=simple_book" do
|
405
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
406
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:simple_book,:objects=>objects)
|
407
|
+
result.class.should be String
|
408
|
+
xml = Nokogiri::XML(result)
|
409
|
+
xml.errors.size.should be 0
|
410
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
411
|
+
xml.xpath("//resource").length.should be 2
|
412
|
+
xml.xpath("//resource/file").length.should be 2
|
413
|
+
xml.xpath("//label").length.should be 2
|
414
|
+
xml.xpath("//label")[0].text.should =~ /Page 1/
|
415
|
+
xml.xpath("//label")[1].text.should =~ /Page 2/
|
416
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
417
|
+
for i in 0..1 do
|
418
|
+
xml.xpath("//resource/file")[i].attributes['size'].should be nil
|
419
|
+
xml.xpath("//resource/file")[i].attributes['mimetype'].should be nil
|
420
|
+
xml.xpath("//resource/file")[i].attributes['publish'].should be nil
|
421
|
+
xml.xpath("//resource/file")[i].attributes['preserve'].should be nil
|
422
|
+
xml.xpath("//resource/file")[i].attributes['shelve'].should be nil
|
423
|
+
end
|
424
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "page"
|
425
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "page"
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should generate valid content metadata for two tifs and one pdf of style=book_with_pdf" do
|
429
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),Assembly::ObjectFile.new(TEST_PDF_FILE)]
|
430
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:book_with_pdf,:objects=>objects)
|
431
|
+
result.class.should be String
|
432
|
+
xml = Nokogiri::XML(result)
|
433
|
+
xml.errors.size.should be 0
|
434
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
435
|
+
xml.xpath("//resource").length.should be 3
|
436
|
+
xml.xpath("//resource/file").length.should be 3
|
437
|
+
xml.xpath("//label").length.should be 3
|
438
|
+
xml.xpath("//label")[0].text.should =~ /Page 1/
|
439
|
+
xml.xpath("//label")[1].text.should =~ /Page 2/
|
440
|
+
xml.xpath("//label")[2].text.should =~ /Object 1/
|
441
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
442
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "page"
|
443
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "page"
|
444
|
+
xml.xpath("//resource")[2].attributes['type'].value.should == "object"
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should generate valid content metadata for two tifs of style=book_as_image" do
|
448
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
449
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:book_as_image,:objects=>objects)
|
450
|
+
result.class.should be String
|
451
|
+
xml = Nokogiri::XML(result)
|
452
|
+
xml.errors.size.should be 0
|
453
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
454
|
+
xml.xpath("//resource").length.should be 2
|
455
|
+
xml.xpath("//resource/file").length.should be 2
|
456
|
+
xml.xpath("//label").length.should be 2
|
457
|
+
xml.xpath("//label")[0].text.should =~ /Image 1/
|
458
|
+
xml.xpath("//label")[1].text.should =~ /Image 2/
|
459
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
460
|
+
for i in 0..1 do
|
461
|
+
xml.xpath("//resource/file")[i].attributes['size'].should be nil
|
462
|
+
xml.xpath("//resource/file")[i].attributes['mimetype'].should be nil
|
463
|
+
xml.xpath("//resource/file")[i].attributes['publish'].should be nil
|
464
|
+
xml.xpath("//resource/file")[i].attributes['preserve'].should be nil
|
465
|
+
xml.xpath("//resource/file")[i].attributes['shelve'].should be nil
|
466
|
+
end
|
467
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "image"
|
468
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "image"
|
469
|
+
end
|
470
|
+
|
471
|
+
it "should generate valid content metadata with no exif but with user supplied checksums for two tifs of style=simple_book" do
|
472
|
+
obj1=Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
473
|
+
obj1.provider_md5='123456789'
|
474
|
+
obj1.provider_sha1='abcdefgh'
|
475
|
+
obj2=Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)
|
476
|
+
obj2.provider_md5='qwerty'
|
477
|
+
objects=[obj1,obj2]
|
478
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:style=>:simple_book,:objects=>objects)
|
479
|
+
result.class.should be String
|
480
|
+
xml = Nokogiri::XML(result)
|
481
|
+
xml.errors.size.should be 0
|
482
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "book"
|
483
|
+
xml.xpath("//resource").length.should be 2
|
484
|
+
xml.xpath("//resource/file").length.should be 2
|
485
|
+
xml.xpath("//resource/file/checksum").length.should be 3
|
486
|
+
xml.xpath("//label").length.should be 2
|
487
|
+
xml.xpath("//label")[0].text.should =~ /Page 1/
|
488
|
+
xml.xpath("//label")[1].text.should =~ /Page 2/
|
489
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
490
|
+
xml.xpath("//resource/file/checksum")[0].text.should == "abcdefgh"
|
491
|
+
xml.xpath("//resource/file/checksum")[1].text.should == "123456789"
|
492
|
+
xml.xpath("//resource/file/checksum")[2].text.should == "qwerty"
|
493
|
+
for i in 0..1 do
|
494
|
+
xml.xpath("//resource/file")[i].attributes['size'].should be nil
|
495
|
+
xml.xpath("//resource/file")[i].attributes['mimetype'].should be nil
|
496
|
+
xml.xpath("//resource/file")[i].attributes['publish'].should be nil
|
497
|
+
xml.xpath("//resource/file")[i].attributes['preserve'].should be nil
|
498
|
+
xml.xpath("//resource/file")[i].attributes['shelve'].should be nil
|
499
|
+
end
|
500
|
+
xml.xpath("//resource")[0].attributes['type'].value.should == "page"
|
501
|
+
xml.xpath("//resource")[1].attributes['type'].value.should == "page"
|
502
|
+
end
|
503
|
+
|
504
|
+
it "should not generate valid content metadata if not all input files exist" do
|
505
|
+
File.exists?(TEST_TIF_INPUT_FILE).should be true
|
506
|
+
junk_file='/tmp/flim_flam_floom.jp2'
|
507
|
+
File.exists?(junk_file).should be false
|
508
|
+
objects=[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),Assembly::ObjectFile.new(junk_file)]
|
509
|
+
lambda {Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:objects=>objects)}.should raise_error
|
510
|
+
end
|
511
|
+
|
512
|
+
it "should generate valid content metadata for images and associated text files, of style=simple_image using bundle=prebundled, and no exif data" do
|
513
|
+
files=[[TEST_RES1_TIF1,TEST_RES1_JP1,TEST_RES1_TIF2,TEST_RES1_JP2,TEST_RES1_TEI,TEST_RES1_TEXT,TEST_RES1_PDF],[TEST_RES2_TIF1,TEST_RES2_JP1,TEST_RES2_TIF2,TEST_RES2_JP2,TEST_RES2_TEI,TEST_RES2_TEXT],[TEST_RES3_TIF1,TEST_RES3_JP1,TEST_RES3_TEI]]
|
514
|
+
objects=files.collect {|resource| resource.collect {|file| Assembly::ObjectFile.new(file)} }
|
515
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:prebundled,:style=>:simple_image,:objects=>objects)
|
516
|
+
result.class.should be String
|
517
|
+
xml = Nokogiri::XML(result)
|
518
|
+
xml.errors.size.should be 0
|
519
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "image"
|
520
|
+
xml.xpath("//resource").length.should be 3
|
521
|
+
xml.xpath("//resource/file").length.should be 16
|
522
|
+
xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value.should == 'res1_image1.tif'
|
523
|
+
xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value.should == 'res1_image1.jp2'
|
524
|
+
xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value.should == 'res1_image2.tif'
|
525
|
+
xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value.should == 'res1_image2.jp2'
|
526
|
+
xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value.should == 'res1_teifile.txt'
|
527
|
+
xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value.should == 'res1_textfile.txt'
|
528
|
+
xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value.should == 'res1_transcript.pdf'
|
529
|
+
xml.xpath("//resource[@sequence='1']/file").length.should be 7
|
530
|
+
|
531
|
+
xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value.should == 'res2_image1.tif'
|
532
|
+
xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value.should == 'res2_image1.jp2'
|
533
|
+
xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value.should == 'res2_image2.tif'
|
534
|
+
xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value.should == 'res2_image2.jp2'
|
535
|
+
xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value.should == 'res2_teifile.txt'
|
536
|
+
xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value.should == 'res2_textfile.txt'
|
537
|
+
xml.xpath("//resource[@sequence='2']/file").length.should be 6
|
538
|
+
|
539
|
+
xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value.should == 'res3_image1.tif'
|
540
|
+
xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value.should == 'res3_image1.jp2'
|
541
|
+
xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value.should == 'res3_teifile.txt'
|
542
|
+
xml.xpath("//resource[@sequence='3']/file").length.should be 3
|
543
|
+
|
544
|
+
xml.xpath("//label").length.should be 3
|
545
|
+
xml.xpath("//resource/file/imageData").length.should be 0
|
546
|
+
for i in 0..2 do
|
547
|
+
xml.xpath("//label")[i].text.should == "Image #{i+1}"
|
548
|
+
xml.xpath("//resource")[i].attributes['type'].value.should == "image"
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
it "should generate content metadata even when no objects are passed in" do
|
553
|
+
objects=[]
|
554
|
+
result = Assembly::ContentMetadata.create_content_metadata(:druid=>TEST_DRUID,:bundle=>:prebundled,:style=>:file,:objects=>objects)
|
555
|
+
result.class.should be String
|
556
|
+
xml = Nokogiri::XML(result)
|
557
|
+
xml.errors.size.should be 0
|
558
|
+
xml.xpath("//contentMetadata")[0].attributes['type'].value.should == "file"
|
559
|
+
xml.xpath("//resource").length.should be 0
|
560
|
+
xml.xpath("//resource/file").length.should be 0
|
561
|
+
end
|
562
|
+
|
563
|
+
end
|