assembly-objectfile 1.11.0 → 1.12.0
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.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +3 -5
- data/Gemfile +2 -0
- data/lib/assembly-objectfile/content_metadata/file.rb +1 -1
- data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +10 -10
- data/lib/assembly-objectfile/version.rb +1 -1
- data/spec/content_metadata_spec.rb +58 -40
- data/spec/spec_helper.rb +3 -2
- data/spec/test_data/input/test.svg +2 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e964d66148904c190829abd7d9c65d09459405f184a48a2350602d1f4c6b6a5f
|
4
|
+
data.tar.gz: 85fca1341b29f0c3f5b3858b419e0273754de1a47140b5ae36d2cbf2a77feea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2cf693279f7c43392f92b3dd8bf28df4baca673276c3c96208b420c6ec26415b37b9498149a0ee6fe8ff4606046768582107f1e71b66199f04463b8f5dec918
|
7
|
+
data.tar.gz: fcdc3f9041410416893e8ba1258c677a9eb0f6ede6eb833deb74f9dcb30e005d226d4486419a6fc2a1ae24b9e0ceda579e1acb7f189cf022af822fc32e275fa6
|
@@ -1,12 +1,10 @@
|
|
1
|
-
## Why was this change made?
|
1
|
+
## Why was this change made? 🤔
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
## How was this change tested?
|
5
|
+
## How was this change tested? 🤨
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
## Which documentation and/or configurations were updated?
|
7
|
+
⚡ ⚠ If this change has cross service impact, ***run [integration tests](https://github.com/sul-dlss/infrastructure-integration-test) that do accessioning*** and/or test in [stage|qa] environment, in addition to specs. ⚡
|
10
8
|
|
11
9
|
|
12
10
|
|
data/Gemfile
CHANGED
@@ -35,7 +35,7 @@ module Assembly
|
|
35
35
|
@style = style
|
36
36
|
end
|
37
37
|
|
38
|
-
delegate :sha1, :md5, :provider_md5, :provider_sha1, :mimetype, :filesize, :image?, to: :file
|
38
|
+
delegate :sha1, :md5, :provider_md5, :provider_sha1, :mimetype, :filesize, :image?, :valid_image?, to: :file
|
39
39
|
|
40
40
|
def file_id(common_path:, flatten_folder_structure:)
|
41
41
|
# set file id attribute, first check the relative_path parameter on the object, and if it is set, just use that
|
@@ -31,19 +31,19 @@ module Assembly
|
|
31
31
|
resource_label = fileset.label_from_file(default: default_label)
|
32
32
|
|
33
33
|
xml.label(resource_label) unless resource_label.empty?
|
34
|
-
fileset.files.each do |
|
35
|
-
xml_file_params = { id:
|
36
|
-
xml_file_params.merge!(
|
37
|
-
xml_file_params.merge!(mimetype:
|
34
|
+
fileset.files.each do |cm_file| # iterate over all the files in a resource
|
35
|
+
xml_file_params = { id: cm_file.file_id(common_path: common_path, flatten_folder_structure: config.flatten_folder_structure) }
|
36
|
+
xml_file_params.merge!(cm_file.file_attributes(config.file_attributes)) if config.add_file_attributes
|
37
|
+
xml_file_params.merge!(mimetype: cm_file.mimetype, size: cm_file.filesize) if config.add_exif
|
38
38
|
|
39
39
|
xml.file(xml_file_params) do
|
40
40
|
if config.add_exif # add exif info if the user requested it
|
41
|
-
xml.checksum(
|
42
|
-
xml.checksum(
|
43
|
-
xml.imageData(
|
44
|
-
elsif
|
45
|
-
xml.checksum(
|
46
|
-
xml.checksum(
|
41
|
+
xml.checksum(cm_file.sha1, type: 'sha1')
|
42
|
+
xml.checksum(cm_file.md5, type: 'md5')
|
43
|
+
xml.imageData(cm_file.image_data) if cm_file.valid_image? # add image data for an image
|
44
|
+
elsif cm_file.provider_md5 || cm_file.provider_sha1 # if we did not add exif info, see if there are user supplied checksums to add
|
45
|
+
xml.checksum(cm_file.provider_sha1, type: 'sha1') if cm_file.provider_sha1
|
46
|
+
xml.checksum(cm_file.provider_md5, type: 'md5') if cm_file.provider_md5
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -9,7 +9,7 @@ RSpec.describe Assembly::ContentMetadata do
|
|
9
9
|
let(:xml) { Nokogiri::XML(result) }
|
10
10
|
|
11
11
|
context 'when style=simple_image' do
|
12
|
-
context 'when using a single tif and jp2' do
|
12
|
+
context 'when using a single tif and jp2 with add_exif: true' do
|
13
13
|
it 'generates valid content metadata with exif, adding file attributes' do
|
14
14
|
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
15
15
|
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
@@ -44,46 +44,8 @@ RSpec.describe Assembly::ContentMetadata do
|
|
44
44
|
expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
|
45
45
|
expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
|
46
46
|
end
|
47
|
-
end
|
48
47
|
|
49
|
-
|
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
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'when using a single tif and jp2' do
|
86
|
-
it 'generates valid content metadata with exif, overriding file labels' do
|
48
|
+
it 'generates valid content metadata, overriding file labels' do
|
87
49
|
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
|
88
50
|
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
89
51
|
expect(result.class).to be String
|
@@ -119,6 +81,42 @@ RSpec.describe Assembly::ContentMetadata do
|
|
119
81
|
end
|
120
82
|
end
|
121
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
|
+
|
122
120
|
context 'when using a single tif and jp2' do
|
123
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
|
124
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: '')]
|
@@ -331,6 +329,26 @@ RSpec.describe Assembly::ContentMetadata do
|
|
331
329
|
end
|
332
330
|
end
|
333
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
|
334
352
|
end
|
335
353
|
|
336
354
|
context 'when style=webarchive-seed' do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'simplecov'
|
4
4
|
SimpleCov.start
|
5
5
|
|
6
|
-
|
7
|
-
require
|
6
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
|
7
|
+
require 'byebug'
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.order = 'random'
|
@@ -18,6 +18,7 @@ TEST_TIF_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.tif')
|
|
18
18
|
TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
|
19
19
|
TEST_JP2_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jp2')
|
20
20
|
TEST_JP2_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.jp2')
|
21
|
+
TEST_SVG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.svg')
|
21
22
|
TEST_JP2_OUTPUT_FILE = File.join(TEST_OUTPUT_DIR, 'test.jp2')
|
22
23
|
TEST_PDF_FILE = File.join(TEST_INPUT_DIR, 'test.pdf')
|
23
24
|
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="507.3" height="508.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="hidden"><defs><clipPath id="clip0"><rect x="2361" y="213" width="507" height="508"/></clipPath></defs><g clip-path="url(#clip0)" transform="translate(-2361 -213)"><path d="M2361 467C2361 326.72 2474.5 213 2614.5 213 2754.5 213 2868 326.72 2868 467 2868 607.28 2754.5 721 2614.5 721 2474.5 721 2361 607.28 2361 467Z" fill="#BF9000" fill-rule="evenodd"/></g></svg>
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assembly-objectfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
8
8
|
- Renzo Sanchez-Silva
|
9
9
|
- Monty Hindman
|
10
10
|
- Tony Calavano
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2022-
|
14
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- spec/test_data/input/test.jp2
|
266
266
|
- spec/test_data/input/test.json
|
267
267
|
- spec/test_data/input/test.pdf
|
268
|
+
- spec/test_data/input/test.svg
|
268
269
|
- spec/test_data/input/test.tif
|
269
270
|
- spec/test_data/input/test2.jp2
|
270
271
|
- spec/test_data/input/test2.tif
|
@@ -273,7 +274,7 @@ homepage: https://github.com/sul-dlss/assembly-objectfile
|
|
273
274
|
licenses:
|
274
275
|
- ALv2
|
275
276
|
metadata: {}
|
276
|
-
post_install_message:
|
277
|
+
post_install_message:
|
277
278
|
rdoc_options: []
|
278
279
|
require_paths:
|
279
280
|
- lib
|
@@ -291,8 +292,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
292
|
- !ruby/object:Gem::Version
|
292
293
|
version: '0'
|
293
294
|
requirements: []
|
294
|
-
rubygems_version: 3.
|
295
|
-
signing_key:
|
295
|
+
rubygems_version: 3.2.32
|
296
|
+
signing_key:
|
296
297
|
specification_version: 4
|
297
298
|
summary: Ruby immplementation of file services needed to prepare objects to be accessioned
|
298
299
|
in SULAIR digital library
|
@@ -332,6 +333,7 @@ test_files:
|
|
332
333
|
- spec/test_data/input/test.jp2
|
333
334
|
- spec/test_data/input/test.json
|
334
335
|
- spec/test_data/input/test.pdf
|
336
|
+
- spec/test_data/input/test.svg
|
335
337
|
- spec/test_data/input/test.tif
|
336
338
|
- spec/test_data/input/test2.jp2
|
337
339
|
- spec/test_data/input/test2.tif
|