assembly-objectfile 1.10.0 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +8 -1
- data/.rubocop.yml +98 -1
- data/.rubocop_todo.yml +62 -17
- data/README.md +1 -1
- data/assembly-objectfile.gemspec +3 -1
- data/config/boot.rb +2 -2
- data/lib/assembly-objectfile.rb +1 -1
- data/lib/assembly-objectfile/content_metadata.rb +7 -8
- data/lib/assembly-objectfile/content_metadata/config.rb +1 -1
- data/lib/assembly-objectfile/content_metadata/file.rb +1 -1
- data/lib/assembly-objectfile/content_metadata/file_set.rb +2 -4
- data/lib/assembly-objectfile/object_file.rb +3 -3
- data/lib/assembly-objectfile/object_fileable.rb +7 -6
- data/lib/assembly-objectfile/version.rb +1 -1
- data/spec/content_metadata_spec.rb +534 -491
- data/spec/spec_helper.rb +1 -1
- metadata +12 -12
@@ -8,506 +8,591 @@ RSpec.describe Assembly::ContentMetadata do
|
|
8
8
|
|
9
9
|
let(:xml) { Nokogiri::XML(result) }
|
10
10
|
|
11
|
-
context 'when
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
11
|
+
context 'when style is simple_image' do
|
12
|
+
context 'when using a single tif and jp2' 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
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
49
|
+
context 'when using a single tif and jp2' do
|
50
|
+
it 'generates valid content metadata with no exif adding specific file attributes for 2 objects, and defaults for 1 object' do
|
51
|
+
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
52
|
+
obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
|
53
|
+
obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
|
54
|
+
obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
|
55
|
+
obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
|
56
|
+
objects = [obj1, obj2, obj3]
|
57
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
|
58
|
+
expect(result.class).to be String
|
59
|
+
xml = Nokogiri::XML(result)
|
60
|
+
expect(xml.errors.size).to eq 0
|
61
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
62
|
+
expect(xml.xpath('//resource').length).to eq 3
|
63
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
64
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 0
|
65
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
66
|
+
expect(xml.xpath('//label').length).to eq 3
|
67
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
68
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
69
|
+
expect(xml.xpath('//label')[2].text).to match(/Image 3/)
|
70
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
71
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
72
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
|
73
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
|
74
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
|
75
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
|
76
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
|
77
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
|
78
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
|
79
|
+
expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
|
80
|
+
expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
|
81
|
+
expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
|
82
|
+
end
|
81
83
|
end
|
82
|
-
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
85
|
+
context 'when using a single tif and jp2' do
|
86
|
+
it 'generates valid content metadata with exif, overriding file labels' do
|
87
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
|
88
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
89
|
+
expect(result.class).to be String
|
90
|
+
xml = Nokogiri::XML(result)
|
91
|
+
expect(xml.errors.size).to eq 0
|
92
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
93
|
+
expect(xml.xpath('//resource').length).to eq 2
|
94
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
95
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 4
|
96
|
+
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
|
97
|
+
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
|
98
|
+
expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
|
99
|
+
expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
|
100
|
+
expect(xml.xpath('//label').length).to eq 2
|
101
|
+
expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
|
102
|
+
expect(xml.xpath('//label')[1].text).to match(/Sample jp2 label!/)
|
103
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
104
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
105
|
+
expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
|
106
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
|
107
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
108
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
|
109
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
110
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
|
111
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
|
112
|
+
expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
|
113
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
|
114
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
115
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
|
116
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
117
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
|
118
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
|
119
|
+
end
|
118
120
|
end
|
119
|
-
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
122
|
+
context 'when using a single tif and jp2' do
|
123
|
+
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
|
124
|
+
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: '')]
|
125
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, auto_labels: false, add_file_attributes: true, objects: objects)
|
126
|
+
expect(result.class).to be String
|
127
|
+
xml = Nokogiri::XML(result)
|
128
|
+
expect(xml.errors.size).to eq 0
|
129
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
130
|
+
expect(xml.xpath('//resource').length).to eq 3
|
131
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
132
|
+
expect(xml.xpath('//label').length).to eq 1
|
133
|
+
expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
|
134
|
+
end
|
133
135
|
end
|
134
|
-
end
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
137
|
+
context 'when using a single tif and jp2' do
|
138
|
+
it 'generates valid content metadata with overriding file attributes and no exif data' do
|
139
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
140
|
+
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)
|
141
|
+
expect(result.class).to be String
|
142
|
+
xml = Nokogiri::XML(result)
|
143
|
+
expect(xml.errors.size).to eq 0
|
144
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
145
|
+
expect(xml.xpath('//resource').length).to eq 2
|
146
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
147
|
+
expect(xml.xpath('//label').length).to eq 2
|
148
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
149
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
150
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
151
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
152
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
153
|
+
expect(xml.xpath('//resource/file')[0].attributes['size']).to be_nil
|
154
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
155
|
+
expect(xml.xpath('//resource/file')[0].attributes['role']).to be_nil
|
156
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
157
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
158
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
159
|
+
expect(xml.xpath('//resource/file')[1].attributes['size']).to be_nil
|
160
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
161
|
+
expect(xml.xpath('//resource/file')[1].attributes['role']).to be_nil
|
162
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
163
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
164
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
165
|
+
end
|
164
166
|
end
|
165
|
-
end
|
166
167
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
168
|
+
context 'when using a single tif and jp2' do
|
169
|
+
it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
|
170
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
171
|
+
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)
|
172
|
+
expect(result.class).to be String
|
173
|
+
xml = Nokogiri::XML(result)
|
174
|
+
expect(xml.errors.size).to eq 0
|
175
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
176
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
177
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
178
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
179
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
180
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
181
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
182
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
183
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
184
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
185
|
+
(0..1).each do |i|
|
186
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
187
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
188
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
189
|
+
end
|
188
190
|
end
|
189
191
|
end
|
190
|
-
end
|
191
192
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
193
|
+
context 'when using two tifs and two associated jp2s using bundle=filename' do
|
194
|
+
it 'generates valid content metadata 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 = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
|
197
|
+
expect(result.class).to be String
|
198
|
+
xml = Nokogiri::XML(result)
|
199
|
+
expect(xml.errors.size).to eq 0
|
200
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
201
|
+
expect(xml.xpath('//resource').length).to eq 2
|
202
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
203
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
|
204
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
|
205
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
|
206
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('test2.jp2')
|
207
|
+
expect(xml.xpath('//label').length).to eq 2
|
208
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
209
|
+
(0..1).each do |i|
|
210
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
211
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
212
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
213
|
+
end
|
213
214
|
end
|
214
215
|
end
|
215
|
-
end
|
216
216
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
expect(xml.xpath("//resource[@sequence='
|
235
|
-
expect(xml.xpath('//label')
|
236
|
-
expect(xml.xpath('//resource')
|
217
|
+
context 'when using two tifs and two associated jp2s using bundle=dpg' do
|
218
|
+
it 'generates valid content metadata and no exif data and no root xml node' do
|
219
|
+
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)]
|
220
|
+
test_druid = TEST_DRUID.to_s
|
221
|
+
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
|
222
|
+
expect(result.class).to be String
|
223
|
+
expect(result.include?('<?xml')).to be false
|
224
|
+
xml = Nokogiri::XML(result)
|
225
|
+
expect(xml.errors.size).to eq 0
|
226
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
227
|
+
expect(test_druid).to eq(TEST_DRUID)
|
228
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
|
229
|
+
expect(xml.xpath('//resource').length).to eq 2
|
230
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
231
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
|
232
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
|
233
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
|
234
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
|
235
|
+
expect(xml.xpath('//label').length).to eq 2
|
236
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
237
|
+
(0..1).each do |i|
|
238
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
239
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
240
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
241
|
+
end
|
237
242
|
end
|
238
243
|
end
|
239
|
-
end
|
240
244
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
263
|
-
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
264
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
245
|
+
context 'when using two tifs and two associated jp2s using bundle=default' do
|
246
|
+
it 'generates valid content metadata and no exif data' do
|
247
|
+
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)]
|
248
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
|
249
|
+
expect(result.class).to be String
|
250
|
+
xml = Nokogiri::XML(result)
|
251
|
+
expect(xml.errors.size).to eq 0
|
252
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
253
|
+
expect(xml.xpath('//resource').length).to eq 4
|
254
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
255
|
+
expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('test.tif')
|
256
|
+
expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('test.jp2')
|
257
|
+
expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('test2.tif')
|
258
|
+
expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('test2.jp2')
|
259
|
+
expect(xml.xpath('//label').length).to eq 4
|
260
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
261
|
+
(0..3).each do |i|
|
262
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
263
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
264
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
265
|
+
end
|
265
266
|
end
|
266
267
|
end
|
267
|
-
end
|
268
268
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
291
|
-
expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
|
292
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
269
|
+
context 'when using two tifs and two associated jp2s using bundle=default' do
|
270
|
+
it 'generates valid content metadata and no exif data, preserving full paths' do
|
271
|
+
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)]
|
272
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
|
273
|
+
expect(result.class).to be String
|
274
|
+
xml = Nokogiri::XML(result)
|
275
|
+
expect(xml.errors.size).to eq 0
|
276
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
277
|
+
expect(xml.xpath('//resource').length).to eq 4
|
278
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
279
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
|
280
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
|
281
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE2)
|
282
|
+
expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE2)
|
283
|
+
expect(xml.xpath('//label').length).to eq 4
|
284
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
285
|
+
(0..3).each do |i|
|
286
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
287
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
288
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
289
|
+
end
|
293
290
|
end
|
294
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
295
|
-
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
296
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
297
|
-
expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
|
298
|
-
expect(xml.xpath('//label')[3].text).to eq('Object 2')
|
299
|
-
expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
|
300
291
|
end
|
301
|
-
end
|
302
292
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
expect(xml.xpath("//resource[@sequence='
|
332
|
-
expect(xml.xpath(
|
333
|
-
expect(xml.xpath(
|
293
|
+
context 'when using bundle=prebundled' do
|
294
|
+
it 'generates valid content metadata for images and associated text files and no exif data' do
|
295
|
+
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]]
|
296
|
+
objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
|
297
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
|
298
|
+
expect(result.class).to be String
|
299
|
+
xml = Nokogiri::XML(result)
|
300
|
+
expect(xml.errors.size).to eq 0
|
301
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
302
|
+
expect(xml.xpath('//resource').length).to eq 3
|
303
|
+
expect(xml.xpath('//resource/file').length).to eq 16
|
304
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
|
305
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
|
306
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
|
307
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
|
308
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
|
309
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
|
310
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
|
311
|
+
expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
|
312
|
+
|
313
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
|
314
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
|
315
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
|
316
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
|
317
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
|
318
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
|
319
|
+
expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 6
|
320
|
+
|
321
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
|
322
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
|
323
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
|
324
|
+
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 3
|
325
|
+
|
326
|
+
expect(xml.xpath('//label').length).to eq 3
|
327
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
328
|
+
(0..2).each do |i|
|
329
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
330
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
331
|
+
end
|
334
332
|
end
|
335
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
336
|
-
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
337
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
338
333
|
end
|
339
334
|
end
|
340
335
|
|
341
|
-
context 'when
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
|
367
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
|
368
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
|
369
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
|
370
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
|
371
|
-
expect(xml.xpath('//label').length).to eq 3
|
372
|
-
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
373
|
-
expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
|
374
|
-
expect(xml.xpath('//label')[0].text).to eq('Object 1')
|
375
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
|
376
|
-
expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
|
377
|
-
expect(xml.xpath('//label')[1].text).to eq('Page 1')
|
378
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
379
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
380
|
-
expect(xml.xpath('//label')[2].text).to eq('Object 2')
|
381
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
336
|
+
context 'when style is webarchive-seed' do
|
337
|
+
context 'when using a jp2' do
|
338
|
+
it 'generates valid content metadata with exif, adding file attributes' do
|
339
|
+
objects = [Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
340
|
+
result = described_class.create_content_metadata(style: :'webarchive-seed', druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
341
|
+
expect(result.class).to be String
|
342
|
+
xml = Nokogiri::XML(result)
|
343
|
+
expect(xml.errors.size).to eq 0
|
344
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('webarchive-seed')
|
345
|
+
expect(xml.xpath('//resource').length).to eq 1
|
346
|
+
expect(xml.xpath('//resource/file').length).to eq 1
|
347
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 2
|
348
|
+
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
|
349
|
+
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('4eb54050d374291ece622d45e84f014d')
|
350
|
+
expect(xml.xpath('//label').length).to eq 1
|
351
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
352
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
353
|
+
expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('306')
|
354
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/jp2')
|
355
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
356
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
357
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('yes')
|
358
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
|
359
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
|
360
|
+
end
|
382
361
|
end
|
383
362
|
end
|
384
363
|
|
385
|
-
context 'when
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
expect(xml.xpath(
|
403
|
-
expect(xml.xpath('//
|
404
|
-
expect(xml.xpath('//resource')[
|
364
|
+
context 'when style=map' do
|
365
|
+
context 'when using a single tif and jp2' do
|
366
|
+
it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
|
367
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
368
|
+
result = described_class.create_content_metadata(style: :map,
|
369
|
+
druid: TEST_DRUID,
|
370
|
+
add_file_attributes: true,
|
371
|
+
file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' },
|
372
|
+
'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } },
|
373
|
+
objects: objects)
|
374
|
+
expect(result.class).to be String
|
375
|
+
xml = Nokogiri::XML(result)
|
376
|
+
expect(xml.errors.size).to eq 0
|
377
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
|
378
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
379
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
380
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
381
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
382
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
383
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
384
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
385
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
386
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
387
|
+
(0..1).each do |i|
|
388
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
389
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
390
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
391
|
+
end
|
405
392
|
end
|
406
393
|
end
|
407
394
|
end
|
408
395
|
|
409
|
-
context 'when
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
expect(xml.xpath("//resource[@sequence='
|
427
|
-
expect(xml.xpath(
|
428
|
-
expect(xml.xpath('//
|
396
|
+
context 'when style=simple_book' do
|
397
|
+
context 'when using two tifs, two associated jp2s, one combined pdf and one special tif using bundle=dpg' do
|
398
|
+
it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
|
399
|
+
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)]
|
400
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
|
401
|
+
expect(result.class).to be String
|
402
|
+
expect(result.include?('<?xml')).to be false
|
403
|
+
xml = Nokogiri::XML(result)
|
404
|
+
expect(xml.errors.size).to eq 0
|
405
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
406
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
|
407
|
+
expect(xml.xpath('//resource').length).to eq 4
|
408
|
+
expect(xml.xpath('//resource/file').length).to eq 6
|
409
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
|
410
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
|
411
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
|
412
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
|
413
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
|
414
|
+
expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
|
415
|
+
expect(xml.xpath('//label').length).to eq 4
|
416
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
417
|
+
(0..1).each do |i|
|
418
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
419
|
+
expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
|
420
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
421
|
+
end
|
422
|
+
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
423
|
+
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
424
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
425
|
+
expect(xml.xpath("//resource[@sequence='4']/file").length).to eq 1
|
426
|
+
expect(xml.xpath('//label')[3].text).to eq('Object 2')
|
427
|
+
expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
|
429
428
|
end
|
430
429
|
end
|
431
|
-
end
|
432
430
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
expect(xml.xpath("//resource[@sequence='
|
454
|
-
expect(xml.xpath(
|
455
|
-
expect(xml.xpath(
|
431
|
+
context "when item has a 'druid:' prefix. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg" do
|
432
|
+
it 'generates valid content metadata with flattening folder structure' do
|
433
|
+
objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
|
434
|
+
Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
|
435
|
+
Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
|
436
|
+
Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
|
437
|
+
test_druid = "druid:#{TEST_DRUID}"
|
438
|
+
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
|
439
|
+
expect(result.class).to be String
|
440
|
+
expect(result.include?('<?xml')).to be true
|
441
|
+
xml = Nokogiri::XML(result)
|
442
|
+
expect(xml.errors.size).to eq 0
|
443
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
444
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
|
445
|
+
expect(test_druid).to eq("druid:#{TEST_DRUID}")
|
446
|
+
expect(xml.xpath('//resource').length).to eq 3
|
447
|
+
expect(xml.xpath('//resource/file').length).to be 7
|
448
|
+
|
449
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
|
450
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
|
451
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
|
452
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
|
453
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
|
454
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
|
455
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
|
456
|
+
expect(xml.xpath('//label').length).to eq 3
|
457
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
458
|
+
(0..1).each do |i|
|
459
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
|
460
|
+
expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
|
461
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
462
|
+
end
|
463
|
+
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
464
|
+
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
465
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
456
466
|
end
|
457
467
|
end
|
458
|
-
end
|
459
468
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
469
|
+
context 'when using two tifs' do
|
470
|
+
it 'generates valid content metadata for two tifs of style=simple_book' do
|
471
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
472
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
|
473
|
+
expect(result.class).to be String
|
474
|
+
xml = Nokogiri::XML(result)
|
475
|
+
expect(xml.errors.size).to eq 0
|
476
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
477
|
+
expect(xml.xpath('//resource').length).to eq 2
|
478
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
479
|
+
expect(xml.xpath('//label').length).to eq 2
|
480
|
+
expect(xml.xpath('//label')[0].text).to match(/Page 1/)
|
481
|
+
expect(xml.xpath('//label')[1].text).to match(/Page 2/)
|
482
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
483
|
+
(0..1).each do |i|
|
484
|
+
expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
|
485
|
+
expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
|
486
|
+
expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
|
487
|
+
expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
|
488
|
+
expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
|
489
|
+
end
|
490
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
491
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
480
492
|
end
|
481
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
482
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
483
493
|
end
|
484
494
|
end
|
485
495
|
|
486
496
|
context 'when using style=book_with_pdf' do
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
497
|
+
context 'when using two tiffs and a pdf' do
|
498
|
+
let(:objects) do
|
499
|
+
[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
|
500
|
+
Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
|
501
|
+
Assembly::ObjectFile.new(TEST_PDF_FILE)]
|
502
|
+
end
|
503
|
+
let(:style) { :book_with_pdf }
|
504
|
+
|
505
|
+
before do
|
506
|
+
allow(Deprecation).to receive(:warn)
|
507
|
+
end
|
508
|
+
|
509
|
+
it 'generates valid content metadata for two tifs' do
|
510
|
+
expect(xml.errors.size).to eq 0
|
511
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
512
|
+
expect(xml.xpath('//resource').length).to eq 3
|
513
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
514
|
+
expect(xml.xpath('//label').length).to eq 3
|
515
|
+
expect(xml.xpath('//label')[0].text).to match(/Page 1/)
|
516
|
+
expect(xml.xpath('//label')[1].text).to match(/Page 2/)
|
517
|
+
expect(xml.xpath('//label')[2].text).to match(/Object 1/)
|
518
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
519
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
520
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
521
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
522
|
+
end
|
491
523
|
end
|
492
|
-
let(:style) { :book_with_pdf }
|
493
524
|
|
494
|
-
|
495
|
-
|
525
|
+
context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF using bundle=dpg' do
|
526
|
+
subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
|
527
|
+
|
528
|
+
let(:objects) do
|
529
|
+
[
|
530
|
+
Assembly::ObjectFile.new(TEST_DPG_TIF),
|
531
|
+
Assembly::ObjectFile.new(TEST_DPG_JP),
|
532
|
+
Assembly::ObjectFile.new(TEST_DPG_PDF),
|
533
|
+
Assembly::ObjectFile.new(TEST_DPG_TIF2),
|
534
|
+
Assembly::ObjectFile.new(TEST_DPG_JP2),
|
535
|
+
Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
|
536
|
+
]
|
537
|
+
end
|
538
|
+
let(:style) { :book_with_pdf }
|
539
|
+
|
540
|
+
before do
|
541
|
+
allow(Deprecation).to receive(:warn)
|
542
|
+
end
|
543
|
+
|
544
|
+
it 'generates valid content metadata' do
|
545
|
+
expect(xml.errors.size).to eq 0
|
546
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
547
|
+
expect(xml.xpath('//resource').length).to eq 3
|
548
|
+
expect(xml.xpath('//resource/file').length).to eq 6
|
549
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
|
550
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
|
551
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('15/oo000oo0001_15_001.pdf')
|
552
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
|
553
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
|
554
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
|
555
|
+
expect(xml.xpath('//label').length).to eq 3
|
556
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
557
|
+
expect(xml.xpath("//resource[@sequence='1']/file").length).to eq 3
|
558
|
+
expect(xml.xpath('//label')[0].text).to eq('Object 1')
|
559
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('object')
|
560
|
+
expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 2
|
561
|
+
expect(xml.xpath('//label')[1].text).to eq('Page 1')
|
562
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
563
|
+
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 1
|
564
|
+
expect(xml.xpath('//label')[2].text).to eq('Object 2')
|
565
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
566
|
+
end
|
496
567
|
end
|
568
|
+
end
|
497
569
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
570
|
+
context 'when style=file' do
|
571
|
+
context 'when using two tifs and two associated jp2s' do
|
572
|
+
it 'generates valid content metadata using specific content metadata paths' do
|
573
|
+
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)]
|
574
|
+
objects[0].relative_path = 'input/test.tif'
|
575
|
+
objects[1].relative_path = 'input/test.jp2'
|
576
|
+
objects[2].relative_path = 'input/test2.tif'
|
577
|
+
objects[3].relative_path = 'input/test2.jp2'
|
578
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
|
579
|
+
expect(result.class).to be String
|
580
|
+
xml = Nokogiri::XML(result)
|
581
|
+
expect(xml.errors.size).to eq 0
|
582
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
|
583
|
+
expect(xml.xpath('//resource').length).to eq 4
|
584
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
585
|
+
expect(xml.xpath('//label').length).to eq 4
|
586
|
+
expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
|
587
|
+
expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
|
588
|
+
expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
|
589
|
+
expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
|
590
|
+
(0..3).each do |i|
|
591
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
592
|
+
expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
|
593
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
|
594
|
+
end
|
595
|
+
end
|
511
596
|
end
|
512
597
|
end
|
513
598
|
|
@@ -643,48 +728,6 @@ RSpec.describe Assembly::ContentMetadata do
|
|
643
728
|
end
|
644
729
|
end
|
645
730
|
|
646
|
-
context 'when style=simple_image using bundle=prebundled' do
|
647
|
-
it 'generates valid content metadata for images and associated text files and no exif data' do
|
648
|
-
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]]
|
649
|
-
objects = files.collect { |resource| resource.collect { |file| Assembly::ObjectFile.new(file) } }
|
650
|
-
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: :simple_image, objects: objects)
|
651
|
-
expect(result.class).to be String
|
652
|
-
xml = Nokogiri::XML(result)
|
653
|
-
expect(xml.errors.size).to eq 0
|
654
|
-
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
655
|
-
expect(xml.xpath('//resource').length).to eq 3
|
656
|
-
expect(xml.xpath('//resource/file').length).to eq 16
|
657
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('res1_image1.tif')
|
658
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('res1_image1.jp2')
|
659
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('res1_image2.tif')
|
660
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[3].attributes['id'].value).to eq('res1_image2.jp2')
|
661
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[4].attributes['id'].value).to eq('res1_teifile.txt')
|
662
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[5].attributes['id'].value).to eq('res1_textfile.txt')
|
663
|
-
expect(xml.xpath("//resource[@sequence='1']/file")[6].attributes['id'].value).to eq('res1_transcript.pdf')
|
664
|
-
expect(xml.xpath("//resource[@sequence='1']/file").length).to be 7
|
665
|
-
|
666
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('res2_image1.tif')
|
667
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('res2_image1.jp2')
|
668
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
|
669
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
|
670
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
|
671
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
|
672
|
-
expect(xml.xpath("//resource[@sequence='2']/file").length).to eq 6
|
673
|
-
|
674
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
|
675
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
|
676
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
|
677
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to eq 3
|
678
|
-
|
679
|
-
expect(xml.xpath('//label').length).to eq 3
|
680
|
-
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
681
|
-
(0..2).each do |i|
|
682
|
-
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
683
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
684
|
-
end
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
731
|
context 'when providing file attributes' do
|
689
732
|
it 'generates role attributes for content metadata' do
|
690
733
|
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|