assembly-objectfile 1.13.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +34 -1
  5. data/.rubocop_todo.yml +3 -120
  6. data/Gemfile.lock +97 -0
  7. data/README.md +6 -6
  8. data/assembly-objectfile.gemspec +4 -8
  9. data/config/boot.rb +0 -1
  10. data/lib/{assembly-objectfile → assembly/object_file}/version.rb +1 -1
  11. data/lib/{assembly-objectfile/object_fileable.rb → assembly/object_file.rb} +116 -101
  12. data/lib/assembly-objectfile.rb +14 -19
  13. data/spec/assembly/object_file_spec.rb +452 -0
  14. data/spec/spec_helper.rb +3 -37
  15. metadata +10 -143
  16. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  17. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  18. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  19. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  20. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  21. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  22. data/lib/assembly-objectfile/object_file.rb +0 -29
  23. data/profiles/AdobeRGB1998.icc +0 -0
  24. data/profiles/DotGain20.icc +0 -0
  25. data/profiles/sRGBIEC6196621.icc +0 -0
  26. data/spec/content_metadata_spec.rb +0 -809
  27. data/spec/object_file_spec.rb +0 -222
  28. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  29. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  30. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  31. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  32. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  33. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  34. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  35. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  36. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  37. data/spec/test_data/input/res1_image1.jp2 +0 -0
  38. data/spec/test_data/input/res1_image2.jp2 +0 -0
  39. data/spec/test_data/input/res1_image2.tif +0 -0
  40. data/spec/test_data/input/res1_teifile.txt +0 -1
  41. data/spec/test_data/input/res2_image1.jp2 +0 -0
  42. data/spec/test_data/input/res2_image1.tif +0 -0
  43. data/spec/test_data/input/res2_image2.jp2 +0 -0
  44. data/spec/test_data/input/res2_image2.tif +0 -0
  45. data/spec/test_data/input/res2_teifile.txt +0 -1
  46. data/spec/test_data/input/res2_textfile.txt +0 -1
  47. data/spec/test_data/input/res3_image1.jp2 +0 -0
  48. data/spec/test_data/input/res3_image1.tif +0 -0
  49. data/spec/test_data/input/res3_teifile.txt +0 -1
  50. data/spec/test_data/input/test.pdf +0 -1
  51. data/spec/test_data/input/test.svg +0 -2
  52. data/spec/test_data/input/test2.jp2 +0 -0
  53. data/spec/test_data/input/test2.tif +0 -0
@@ -1,809 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Assembly::ContentMetadata do
6
- describe '#create_content_metadata' do
7
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, style: style, objects: objects) }
8
-
9
- let(:xml) { Nokogiri::XML(result) }
10
-
11
- context 'when style=simple_image' do
12
- context 'when using a single tif and jp2 with add_exif: true' do
13
- it 'generates valid content metadata with exif, adding file attributes' do
14
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
15
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
16
- expect(result.class).to be String
17
- xml = Nokogiri::XML(result)
18
- expect(xml.errors.size).to eq 0
19
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
20
- expect(xml.xpath('//resource').length).to eq 2
21
- expect(xml.xpath('//resource/file').length).to eq 2
22
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
23
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
24
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
25
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
26
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
27
- expect(xml.xpath('//label').length).to eq 2
28
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
29
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
30
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
31
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
32
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
33
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
34
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
35
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
36
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
37
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
38
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
39
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
40
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
41
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
42
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
43
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
44
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
45
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
46
- end
47
-
48
- it 'generates valid content metadata, overriding file labels' do
49
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
50
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
51
- expect(result.class).to be String
52
- xml = Nokogiri::XML(result)
53
- expect(xml.errors.size).to eq 0
54
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
55
- expect(xml.xpath('//resource').length).to eq 2
56
- expect(xml.xpath('//resource/file').length).to eq 2
57
- expect(xml.xpath('//resource/file/checksum').length).to eq 4
58
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
59
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
60
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
61
- expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
62
- expect(xml.xpath('//label').length).to eq 2
63
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
64
- expect(xml.xpath('//label')[1].text).to match(/Sample jp2 label!/)
65
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
66
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
67
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
68
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
69
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
70
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
71
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
72
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
73
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
74
- expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
75
- expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
76
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
77
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
78
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
79
- expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
80
- expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
81
- end
82
- end
83
-
84
- context 'when using a single tif and jp2 with add_exif: false' do
85
- it 'generates valid content metadata adding specific file attributes for 2 objects, and defaults for 1 object' do
86
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
87
- obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
88
- obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
89
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
90
- obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
91
- objects = [obj1, obj2, obj3]
92
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
93
- expect(result.class).to be String
94
- xml = Nokogiri::XML(result)
95
- expect(xml.errors.size).to eq 0
96
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
97
- expect(xml.xpath('//resource').length).to eq 3
98
- expect(xml.xpath('//resource/file').length).to eq 3
99
- expect(xml.xpath('//resource/file/checksum').length).to eq 0
100
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
101
- expect(xml.xpath('//label').length).to eq 3
102
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
103
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
104
- expect(xml.xpath('//label')[2].text).to match(/Image 3/)
105
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
106
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
107
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
108
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
109
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
110
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
111
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
112
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
113
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
114
- expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
115
- expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
116
- expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
117
- end
118
- end
119
-
120
- context 'when using a single tif and jp2' do
121
- it 'generates valid content metadata with exif, overriding file labels for one, and skipping auto labels for the others or for where the label is set but is blank' do
122
- 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: '')]
123
- result = described_class.create_content_metadata(druid: TEST_DRUID, auto_labels: false, add_file_attributes: true, objects: objects)
124
- expect(result.class).to be String
125
- xml = Nokogiri::XML(result)
126
- expect(xml.errors.size).to eq 0
127
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
128
- expect(xml.xpath('//resource').length).to eq 3
129
- expect(xml.xpath('//resource/file').length).to eq 3
130
- expect(xml.xpath('//label').length).to eq 1
131
- expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
132
- end
133
- end
134
-
135
- context 'when using a single tif and jp2' do
136
- it 'generates valid content metadata with overriding file attributes and no exif data' do
137
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
138
- result = described_class.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)
139
- expect(result.class).to be String
140
- xml = Nokogiri::XML(result)
141
- expect(xml.errors.size).to eq 0
142
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
143
- expect(xml.xpath('//resource').length).to eq 2
144
- expect(xml.xpath('//resource/file').length).to eq 2
145
- expect(xml.xpath('//label').length).to eq 2
146
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
147
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
148
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
149
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
150
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
151
- expect(xml.xpath('//resource/file')[0].attributes['size']).to be_nil
152
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
153
- expect(xml.xpath('//resource/file')[0].attributes['role']).to be_nil
154
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
155
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
156
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
157
- expect(xml.xpath('//resource/file')[1].attributes['size']).to be_nil
158
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
159
- expect(xml.xpath('//resource/file')[1].attributes['role']).to be_nil
160
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
161
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
162
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
163
- end
164
- end
165
-
166
- context 'when using a single tif and jp2' do
167
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
168
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
169
- result = described_class.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)
170
- expect(result.class).to be String
171
- xml = Nokogiri::XML(result)
172
- expect(xml.errors.size).to eq 0
173
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
174
- expect(xml.xpath('//resource/file').length).to eq 2
175
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
176
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
177
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
178
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
179
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
180
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
181
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
182
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
183
- (0..1).each do |i|
184
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
185
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
186
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
187
- end
188
- end
189
- end
190
-
191
- context 'when using two tifs and two associated jp2s using bundle=filename' do
192
- it 'generates valid content metadata and no exif data' do
193
- 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)]
194
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
195
- expect(result.class).to be String
196
- xml = Nokogiri::XML(result)
197
- expect(xml.errors.size).to eq 0
198
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
199
- expect(xml.xpath('//resource').length).to eq 2
200
- expect(xml.xpath('//resource/file').length).to eq 4
201
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
202
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
203
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
204
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('test2.jp2')
205
- expect(xml.xpath('//label').length).to eq 2
206
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
207
- (0..1).each do |i|
208
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
209
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
210
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
211
- end
212
- end
213
- end
214
-
215
- context 'when using two tifs and two associated jp2s using bundle=dpg' do
216
- it 'generates valid content metadata 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.to_s
219
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
220
- expect(result.class).to be String
221
- expect(result.include?('<?xml')).to be false
222
- xml = Nokogiri::XML(result)
223
- expect(xml.errors.size).to eq 0
224
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
225
- expect(test_druid).to eq(TEST_DRUID)
226
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
227
- expect(xml.xpath('//resource').length).to eq 2
228
- expect(xml.xpath('//resource/file').length).to eq 4
229
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
230
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
231
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
232
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
233
- expect(xml.xpath('//label').length).to eq 2
234
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
235
- (0..1).each do |i|
236
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
237
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
238
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
239
- end
240
- end
241
- end
242
-
243
- context 'when using two tifs and two associated jp2s using bundle=default' do
244
- it 'generates valid content metadata and no exif data' do
245
- 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)]
246
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
247
- expect(result.class).to be String
248
- xml = Nokogiri::XML(result)
249
- expect(xml.errors.size).to eq 0
250
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
251
- expect(xml.xpath('//resource').length).to eq 4
252
- expect(xml.xpath('//resource/file').length).to eq 4
253
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('test.tif')
254
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('test.jp2')
255
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('test2.tif')
256
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('test2.jp2')
257
- expect(xml.xpath('//label').length).to eq 4
258
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
259
- (0..3).each do |i|
260
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
261
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
262
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
263
- end
264
- end
265
- end
266
-
267
- context 'when using two tifs and two associated jp2s using bundle=default' do
268
- it 'generates valid content metadata and no exif data, preserving full paths' do
269
- 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)]
270
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
271
- expect(result.class).to be String
272
- xml = Nokogiri::XML(result)
273
- expect(xml.errors.size).to eq 0
274
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
275
- expect(xml.xpath('//resource').length).to eq 4
276
- expect(xml.xpath('//resource/file').length).to eq 4
277
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
278
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
279
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE2)
280
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE2)
281
- expect(xml.xpath('//label').length).to eq 4
282
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
283
- (0..3).each do |i|
284
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
285
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
286
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
287
- end
288
- end
289
- end
290
-
291
- context 'when using bundle=prebundled' do
292
- it 'generates valid content metadata for images and associated text files and no exif data' do
293
- 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]]
294
- objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
295
- result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
296
- expect(result.class).to be String
297
- xml = Nokogiri::XML(result)
298
- expect(xml.errors.size).to eq 0
299
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
300
- expect(xml.xpath('//resource').length).to eq 3
301
- expect(xml.xpath('//resource/file').length).to eq 16
302
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
303
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
304
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
305
- expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
306
- expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
307
- expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
308
- expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
309
- expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
310
-
311
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
312
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
313
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
314
- expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
315
- expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
316
- expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
317
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 6
318
-
319
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
320
- expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
321
- expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
322
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 3
323
-
324
- expect(xml.xpath('//label').length).to eq 3
325
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
326
- (0..2).each do |i|
327
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
328
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
329
- end
330
- end
331
- end
332
-
333
- context 'when using a single svg with add_exif: true' do
334
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, auto_labels: false, add_file_attributes: true, objects: objects) }
335
-
336
- let(:objects) { [Assembly::ObjectFile.new(TEST_SVG_INPUT_FILE)] }
337
-
338
- it 'generates no imageData node' do
339
- xml = Nokogiri::XML(result)
340
- expect(xml.errors.size).to eq 0
341
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
342
- expect(xml.xpath('//resource/file').length).to eq 1
343
- expect(xml.xpath('//resource/file')[0]['mimetype']).to eq 'image/svg+xml'
344
- expect(xml.xpath('//resource/file')[0]['publish']).to eq('no')
345
- expect(xml.xpath('//resource/file')[0]['preserve']).to eq('yes')
346
- expect(xml.xpath('//resource/file')[0]['shelve']).to eq('no')
347
- expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 1
348
- expect(xml.xpath('//imageData')).not_to be_present
349
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
350
- end
351
- end
352
- end
353
-
354
- context 'when style=webarchive-seed' do
355
- context 'when using a jp2' do
356
- it 'generates valid content metadata with exif, adding file attributes' do
357
- objects = [Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
358
- result = described_class.create_content_metadata(style: :'webarchive-seed', druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
359
- expect(result.class).to be String
360
- xml = Nokogiri::XML(result)
361
- expect(xml.errors.size).to eq 0
362
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('webarchive-seed')
363
- expect(xml.xpath('//bookData').length).to eq 0
364
- expect(xml.xpath('//resource').length).to eq 1
365
- expect(xml.xpath('//resource/file').length).to eq 1
366
- expect(xml.xpath('//resource/file/checksum').length).to eq 2
367
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
368
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('4eb54050d374291ece622d45e84f014d')
369
- expect(xml.xpath('//label').length).to eq 1
370
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
371
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
372
- expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('306')
373
- expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/jp2')
374
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
375
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
376
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('yes')
377
- expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
378
- expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
379
- end
380
- end
381
- end
382
-
383
- context 'when style=map' do
384
- context 'when using a single tif and jp2' do
385
- it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
386
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
387
- result = described_class.create_content_metadata(style: :map,
388
- druid: TEST_DRUID,
389
- add_file_attributes: true,
390
- file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' },
391
- 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } },
392
- objects: objects)
393
- expect(result.class).to be String
394
- xml = Nokogiri::XML(result)
395
- expect(xml.errors.size).to eq 0
396
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
397
- expect(xml.xpath('//bookData').length).to eq 0
398
- expect(xml.xpath('//resource/file').length).to eq 2
399
- expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
400
- expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
401
- expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
402
- expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
403
- expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
404
- expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
405
- expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
406
- expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
407
- (0..1).each do |i|
408
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
409
- expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
410
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
411
- end
412
- end
413
- end
414
- end
415
-
416
- context 'when style=simple_book' do
417
- context 'when using two tifs, two associated jp2s, one combined pdf and one special tif using bundle=dpg' do
418
- it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
419
- 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)]
420
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
421
- expect(result.class).to be String
422
- expect(result.include?('<?xml')).to be false
423
- xml = Nokogiri::XML(result)
424
- expect(xml.errors.size).to eq 0
425
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
426
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
427
- expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('ltr')
428
- expect(xml.xpath('//resource').length).to eq 4
429
- expect(xml.xpath('//resource/file').length).to eq 6
430
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
431
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
432
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
433
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
434
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
435
- expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
436
- expect(xml.xpath('//label').length).to eq 4
437
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
438
- (0..1).each do |i|
439
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
440
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
441
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
442
- end
443
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
444
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
445
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
446
- expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
447
- expect(xml.xpath('//label')[3].text).to eq('Object 2')
448
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
449
- end
450
- end
451
-
452
- context "when item has a 'druid:' prefix and specified book order. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
453
- it 'generates valid content metadata with flattening folder structure' do
454
- objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
455
- Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
456
- Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
457
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
458
- test_druid = "druid:#{TEST_DRUID}"
459
- result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true, reading_order: 'rtl')
460
- expect(result.class).to be String
461
- expect(result.include?('<?xml')).to be true
462
- xml = Nokogiri::XML(result)
463
- expect(xml.errors.size).to eq 0
464
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
465
- expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
466
- expect(xml.xpath('//bookData')[0].attributes['readingOrder'].value).to eq('rtl')
467
- expect(test_druid).to eq("druid:#{TEST_DRUID}")
468
- expect(xml.xpath('//resource').length).to eq 3
469
- expect(xml.xpath('//resource/file').length).to be 7
470
-
471
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
472
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
473
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
474
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
475
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
476
- expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
477
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
478
- expect(xml.xpath('//label').length).to eq 3
479
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
480
- (0..1).each do |i|
481
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
482
- expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
483
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
484
- end
485
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
486
- expect(xml.xpath('//label')[2].text).to eq('Object 1')
487
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
488
- end
489
- end
490
-
491
- context 'throws an error with invalid reading order' do
492
- subject(:result) { described_class.create_content_metadata(druid: "druid:#{TEST_DRUID}", bundle: :dpg, objects: [], style: :simple_book, flatten_folder_structure: true, reading_order: 'bogus') }
493
-
494
- it 'generates valid content metadata with flattening folder structure' do
495
- expect { result }.to raise_error(Dry::Struct::Error)
496
- end
497
- end
498
-
499
- context 'when using two tifs' do
500
- it 'generates valid content metadata for two tifs of style=simple_book' do
501
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
502
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
503
- expect(result.class).to be String
504
- xml = Nokogiri::XML(result)
505
- expect(xml.errors.size).to eq 0
506
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
507
- expect(xml.xpath('//resource').length).to eq 2
508
- expect(xml.xpath('//resource/file').length).to eq 2
509
- expect(xml.xpath('//label').length).to eq 2
510
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
511
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
512
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
513
- (0..1).each do |i|
514
- expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
515
- expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
516
- expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
517
- expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
518
- expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
519
- end
520
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
521
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
522
- end
523
- end
524
- end
525
-
526
- context 'when style=book_with_pdf' do
527
- context 'when using two tiffs and a pdf' do
528
- let(:objects) do
529
- [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
530
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
531
- Assembly::ObjectFile.new(TEST_PDF_FILE)]
532
- end
533
- let(:style) { :book_with_pdf }
534
-
535
- before do
536
- allow(Deprecation).to receive(:warn)
537
- end
538
-
539
- it 'generates valid content metadata for two tifs' do
540
- expect(xml.errors.size).to eq 0
541
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
542
- expect(xml.xpath('//resource').length).to eq 3
543
- expect(xml.xpath('//resource/file').length).to eq 3
544
- expect(xml.xpath('//label').length).to eq 3
545
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
546
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
547
- expect(xml.xpath('//label')[2].text).to match(/Object 1/)
548
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
549
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
550
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
551
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
552
- end
553
- end
554
-
555
- context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg' do
556
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
557
-
558
- let(:objects) do
559
- [
560
- Assembly::ObjectFile.new(TEST_DPG_TIF),
561
- Assembly::ObjectFile.new(TEST_DPG_JP),
562
- Assembly::ObjectFile.new(TEST_DPG_PDF),
563
- Assembly::ObjectFile.new(TEST_DPG_TIF2),
564
- Assembly::ObjectFile.new(TEST_DPG_JP2),
565
- Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
566
- ]
567
- end
568
- let(:style) { :book_with_pdf }
569
-
570
- before do
571
- allow(Deprecation).to receive(:warn)
572
- end
573
-
574
- it 'generates valid content metadata' do
575
- expect(xml.errors.size).to eq 0
576
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
577
- expect(xml.xpath('//resource').length).to eq 3
578
- expect(xml.xpath('//resource/file').length).to eq 6
579
- expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
580
- expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
581
- expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
582
- expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
583
- expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
584
- expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
585
- expect(xml.xpath('//label').length).to eq 3
586
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
587
- expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
588
- expect(xml.xpath('//label')[0].text).to eq('Object 1')
589
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
590
- expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
591
- expect(xml.xpath('//label')[1].text).to eq('Page 1')
592
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
593
- expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
594
- expect(xml.xpath('//label')[2].text).to eq('Object 2')
595
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
596
- end
597
- end
598
- end
599
-
600
- context 'when style=file' do
601
- context 'when using two tifs and two associated jp2s' do
602
- it 'generates valid content metadata using specific content metadata paths' do
603
- 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)]
604
- objects[0].relative_path = 'input/test.tif'
605
- objects[1].relative_path = 'input/test.jp2'
606
- objects[2].relative_path = 'input/test2.tif'
607
- objects[3].relative_path = 'input/test2.jp2'
608
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
609
- expect(result.class).to be String
610
- xml = Nokogiri::XML(result)
611
- expect(xml.errors.size).to eq 0
612
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
613
- expect(xml.xpath('//bookData').length).to eq 0
614
- expect(xml.xpath('//resource').length).to eq 4
615
- expect(xml.xpath('//resource/file').length).to eq 4
616
- expect(xml.xpath('//label').length).to eq 4
617
- expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
618
- expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
619
- expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
620
- expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
621
- (0..3).each do |i|
622
- expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
623
- expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
624
- expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
625
- end
626
- end
627
- end
628
- end
629
-
630
- context 'when using style=book_as_image' do
631
- let(:objects) do
632
- [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
633
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
634
- end
635
-
636
- let(:style) { :book_as_image }
637
-
638
- before do
639
- allow(Deprecation).to receive(:warn)
640
- end
641
-
642
- it 'generates valid content metadata for two tifs' do
643
- expect(xml.errors.size).to eq 0
644
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
645
- expect(xml.xpath('//bookData').length).to eq 1
646
- expect(xml.xpath('//resource').length).to eq 2
647
- expect(xml.xpath('//resource/file').length).to eq 2
648
- expect(xml.xpath('//label').length).to eq 2
649
- expect(xml.xpath('//label')[0].text).to match(/Image 1/)
650
- expect(xml.xpath('//label')[1].text).to match(/Image 2/)
651
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
652
- (0..1).each do |i|
653
- file = xml.xpath('//resource/file')[i]
654
-
655
- expect(file.attributes['size']).to be_nil
656
- expect(file.attributes['mimetype']).to be_nil
657
- expect(file.attributes['publish']).to be_nil
658
- expect(file.attributes['preserve']).to be_nil
659
- expect(file.attributes['shelve']).to be_nil
660
- end
661
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
662
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
663
- end
664
- end
665
-
666
- context 'when using style=document' do
667
- let(:objects) do
668
- [Assembly::ObjectFile.new(TEST_PDF_FILE)]
669
- end
670
-
671
- let(:style) { :document }
672
-
673
- it 'generates valid content metadata' do
674
- expect(xml.errors.size).to eq 0
675
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('document')
676
- expect(xml.xpath('//bookData').length).to eq 0
677
- expect(xml.xpath('//resource').length).to eq 1
678
- expect(xml.xpath('//resource/file').length).to eq 1
679
- expect(xml.xpath('//label').length).to eq 1
680
- expect(xml.xpath('//label')[0].text).to match(/Document 1/)
681
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
682
- file = xml.xpath('//resource/file').first
683
- expect(file.attributes['size']).to be_nil
684
- expect(file.attributes['mimetype']).to be_nil
685
- expect(file.attributes['publish']).to be_nil
686
- expect(file.attributes['preserve']).to be_nil
687
- expect(file.attributes['shelve']).to be_nil
688
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('document')
689
- end
690
- end
691
-
692
- context 'when using user supplied checksums for two tifs and style=simple_book' do
693
- it 'generates valid content metadata with no exif' do
694
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
695
- obj1.provider_md5 = '123456789'
696
- obj1.provider_sha1 = 'abcdefgh'
697
- obj2 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)
698
- obj2.provider_md5 = 'qwerty'
699
- objects = [obj1, obj2]
700
- result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
701
- expect(result.class).to be String
702
- xml = Nokogiri::XML(result)
703
- expect(xml.errors.size).to eq 0
704
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
705
- expect(xml.xpath('//resource').length).to eq 2
706
- expect(xml.xpath('//resource/file').length).to eq 2
707
- expect(xml.xpath('//resource/file/checksum').length).to eq 3
708
- expect(xml.xpath('//label').length).to eq 2
709
- expect(xml.xpath('//label')[0].text).to match(/Page 1/)
710
- expect(xml.xpath('//label')[1].text).to match(/Page 2/)
711
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
712
- expect(xml.xpath('//resource/file/checksum')[0].text).to eq('abcdefgh')
713
- expect(xml.xpath('//resource/file/checksum')[1].text).to eq('123456789')
714
- expect(xml.xpath('//resource/file/checksum')[2].text).to eq('qwerty')
715
- (0..1).each do |i|
716
- expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
717
- expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
718
- expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
719
- expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
720
- expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
721
- end
722
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
723
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
724
- end
725
- end
726
-
727
- context 'when not all input files exist' do
728
- it 'does not generate valid content metadata' do
729
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
730
- junk_file = '/tmp/flim_flam_floom.jp2'
731
- expect(File.exist?(junk_file)).to be false
732
- objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(junk_file)]
733
- expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
734
- end
735
- end
736
-
737
- context 'when using a 3d object with one 3d type files and three other supporting files (where one supporting file is a non-viewable but downloadable 3d file)' do
738
- let(:objects) do
739
- [Assembly::ObjectFile.new(TEST_OBJ_FILE),
740
- Assembly::ObjectFile.new(TEST_PLY_FILE),
741
- Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
742
- Assembly::ObjectFile.new(TEST_PDF_FILE)]
743
- end
744
- let(:style) { :'3d' }
745
-
746
- it 'generates valid content metadata' do
747
- expect(xml.errors.size).to eq 0
748
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
749
- expect(xml.xpath('//bookData').length).to eq 0
750
- expect(xml.xpath('//resource').length).to eq 4
751
- expect(xml.xpath('//resource/file').length).to eq 4
752
- expect(xml.xpath('//label').length).to eq 4
753
- expect(xml.xpath('//label')[0].text).to match(/3d 1/)
754
- expect(xml.xpath('//label')[1].text).to match(/File 1/)
755
- expect(xml.xpath('//label')[2].text).to match(/File 2/)
756
- expect(xml.xpath('//label')[3].text).to match(/File 3/)
757
- expect(xml.xpath('//resource/file/imageData').length).to eq 0
758
- expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
759
- expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
760
- expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
761
- expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
762
- end
763
- end
764
-
765
- context 'when providing file attributes' do
766
- it 'generates role attributes for content metadata' do
767
- obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
768
- obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no', role: 'master-role' }
769
- objects = [obj1]
770
- result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
771
- expect(result.class).to be String
772
- xml = Nokogiri::XML(result)
773
- expect(xml.errors.size).to eq 0
774
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
775
- expect(xml.xpath('//resource').length).to eq 1
776
- expect(xml.xpath('//resource/file').length).to eq 1
777
- expect(xml.xpath('//resource/file').length).to eq 1
778
- expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
779
- end
780
- end
781
-
782
- context 'when no objects are passed in' do
783
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
784
-
785
- let(:objects) { [] }
786
-
787
- let(:style) { :file }
788
-
789
- it 'generates content metadata even when no objects are passed in' do
790
- expect(xml.errors.size).to eq 0
791
- expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
792
- expect(xml.xpath('//resource').length).to eq 0
793
- expect(xml.xpath('//resource/file').length).to eq 0
794
- end
795
- end
796
-
797
- context 'when an unknown style is passed in' do
798
- subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
799
-
800
- let(:objects) { [] }
801
-
802
- let(:style) { :borked }
803
-
804
- it 'generates an error message' do
805
- expect { result }.to raise_error 'Supplied style (borked) not valid'
806
- end
807
- end
808
- end
809
- end