assembly-objectfile 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +20 -23
- data/assembly-objectfile.gemspec +1 -0
- data/lib/assembly-objectfile.rb +0 -20
- data/lib/assembly-objectfile/content_metadata.rb +5 -9
- data/lib/assembly-objectfile/content_metadata/config.rb +1 -1
- data/lib/assembly-objectfile/content_metadata/file.rb +21 -1
- data/lib/assembly-objectfile/content_metadata/file_set.rb +4 -0
- data/lib/assembly-objectfile/version.rb +1 -1
- data/spec/content_metadata_spec.rb +689 -568
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab94538c86ddec92361ad8be34b75f30d5c5c2991ddbb25e3375593e6c079b94
|
4
|
+
data.tar.gz: b03077ed3ae19b4c77615ce407e600b8cacdaa190cded54e98edc5461d360af8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e77fd23ee31f26f9d9cd4502b760670381e5e97ade348274e52f9b70e318b4d8dd54bd45fe7529535a8912f60c822dfb616f71306f8381f6923bffa37c631993
|
7
|
+
data.tar.gz: 8d92581381a3464cc0cfb44bf0e7dabd3222edf70acf477c293d79c7b1791ca5c626bf2458d1faebe05a1ef5f4606d53e1a7a1266ff18e68257dbfe1f66ddfcd
|
data/.rubocop.yml
CHANGED
@@ -13,3 +13,28 @@ RSpec/MessageSpies:
|
|
13
13
|
|
14
14
|
RSpec/NestedGroups:
|
15
15
|
Max: 4 # default: 3
|
16
|
+
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- spec/**/*_spec.rb
|
20
|
+
|
21
|
+
Layout/SpaceAroundMethodCallOperator:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Lint/RaiseException:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Lint/StructNewOverride:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Style/ExponentialNotation:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Style/HashEachMethods:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Style/HashTransformKeys:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Style/HashTransformValues:
|
40
|
+
Enabled: true
|
data/.rubocop_todo.yml
CHANGED
@@ -1,36 +1,33 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2020-04-23 10:59:56 -0500 using RuboCop version 0.82.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 1
|
10
|
-
Lint/AmbiguousBlockAssociation:
|
11
|
-
Exclude:
|
12
|
-
- 'spec/content_metadata_spec.rb'
|
13
|
-
|
14
9
|
# Offense count: 1
|
15
10
|
Lint/UselessAssignment:
|
16
11
|
Exclude:
|
17
12
|
- 'config/boot.rb'
|
18
13
|
|
19
14
|
# Offense count: 3
|
15
|
+
# Configuration parameters: IgnoredMethods.
|
20
16
|
Metrics/AbcSize:
|
21
17
|
Max: 51
|
22
18
|
|
23
|
-
# Offense count:
|
19
|
+
# Offense count: 2
|
24
20
|
# Configuration parameters: CountComments, ExcludedMethods.
|
25
21
|
# ExcludedMethods: refine
|
26
22
|
Metrics/BlockLength:
|
27
|
-
Max:
|
23
|
+
Max: 27
|
28
24
|
|
29
|
-
# Offense count:
|
25
|
+
# Offense count: 2
|
26
|
+
# Configuration parameters: IgnoredMethods.
|
30
27
|
Metrics/CyclomaticComplexity:
|
31
28
|
Max: 14
|
32
29
|
|
33
|
-
# Offense count:
|
30
|
+
# Offense count: 4
|
34
31
|
# Configuration parameters: CountComments, ExcludedMethods.
|
35
32
|
Metrics/MethodLength:
|
36
33
|
Max: 30
|
@@ -46,6 +43,7 @@ Metrics/ParameterLists:
|
|
46
43
|
Max: 11
|
47
44
|
|
48
45
|
# Offense count: 2
|
46
|
+
# Configuration parameters: IgnoredMethods.
|
49
47
|
Metrics/PerceivedComplexity:
|
50
48
|
Max: 12
|
51
49
|
|
@@ -57,10 +55,10 @@ Naming/FileName:
|
|
57
55
|
- 'lib/assembly-objectfile.rb'
|
58
56
|
|
59
57
|
# Offense count: 1
|
60
|
-
# Configuration parameters: NamePrefix,
|
58
|
+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
|
61
59
|
# NamePrefix: is_, has_, have_
|
62
|
-
#
|
63
|
-
#
|
60
|
+
# ForbiddenPrefixes: is_, has_, have_
|
61
|
+
# AllowedMethods: is_a?
|
64
62
|
# MethodDefinitionMacros: define_method, define_singleton_method
|
65
63
|
Naming/PredicateName:
|
66
64
|
Exclude:
|
@@ -80,7 +78,7 @@ RSpec/FilePath:
|
|
80
78
|
- 'spec/content_metadata_spec.rb'
|
81
79
|
- 'spec/object_file_spec.rb'
|
82
80
|
|
83
|
-
# Offense count:
|
81
|
+
# Offense count: 71
|
84
82
|
# Configuration parameters: AssignmentOnly.
|
85
83
|
RSpec/InstanceVariable:
|
86
84
|
Exclude:
|
@@ -101,20 +99,19 @@ RSpec/RepeatedExample:
|
|
101
99
|
Exclude:
|
102
100
|
- 'spec/object_file_spec.rb'
|
103
101
|
|
102
|
+
# Offense count: 8
|
103
|
+
RSpec/RepeatedExampleGroupDescription:
|
104
|
+
Exclude:
|
105
|
+
- 'spec/content_metadata_spec.rb'
|
106
|
+
|
104
107
|
# Offense count: 2
|
105
108
|
Style/CommentedKeyword:
|
106
109
|
Exclude:
|
107
110
|
- 'lib/assembly-objectfile/content_metadata.rb'
|
108
111
|
|
109
|
-
# Offense count:
|
110
|
-
# Configuration parameters: MinBodyLength.
|
111
|
-
Style/GuardClause:
|
112
|
-
Exclude:
|
113
|
-
- 'lib/assembly-objectfile/object_file.rb'
|
114
|
-
|
115
|
-
# Offense count: 346
|
112
|
+
# Offense count: 409
|
116
113
|
# Cop supports --auto-correct.
|
117
114
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
118
115
|
# URISchemes: http, https
|
119
|
-
|
120
|
-
Max:
|
116
|
+
Layout/LineLength:
|
117
|
+
Max: 284
|
data/assembly-objectfile.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
23
|
s.add_dependency 'activesupport', '>= 5.2.0'
|
24
|
+
s.add_dependency 'deprecation'
|
24
25
|
s.add_dependency 'dry-struct', '~> 1.0'
|
25
26
|
s.add_dependency 'dry-types', '~> 1.1'
|
26
27
|
s.add_dependency 'mime-types', '> 3'
|
data/lib/assembly-objectfile.rb
CHANGED
@@ -14,26 +14,6 @@ module Assembly
|
|
14
14
|
# by the file command, then a check will be made to see if exif data exists...if so, the mimetype returned by the exif data will be used
|
15
15
|
# if no exif data exists, then the mimetype returned by the unix file command will be used
|
16
16
|
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml'].freeze
|
17
|
-
|
18
|
-
# default publish/preserve/shelve attributes used in content metadata
|
19
|
-
# if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below
|
20
|
-
FILE_ATTRIBUTES = {
|
21
|
-
'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
22
|
-
'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
23
|
-
'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
24
|
-
'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
25
|
-
'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
26
|
-
'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
27
|
-
'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
28
|
-
'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
29
|
-
'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
30
|
-
'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
31
|
-
'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
32
|
-
'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
33
|
-
'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
|
34
|
-
'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
35
|
-
'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
|
36
|
-
}.freeze
|
37
17
|
end
|
38
18
|
|
39
19
|
require 'assembly-objectfile/content_metadata'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'nokogiri'
|
4
|
+
require 'deprecation'
|
4
5
|
require 'active_support'
|
5
6
|
require 'assembly-objectfile/content_metadata/file'
|
6
7
|
require 'assembly-objectfile/content_metadata/file_set'
|
@@ -13,6 +14,7 @@ module Assembly
|
|
13
14
|
# these are used when :bundle=>:dpg only
|
14
15
|
|
15
16
|
DEPRECATED_STYLES = %i[book_with_pdf book_as_image].freeze
|
17
|
+
VALID_STYLES = %i[simple_image simple_book file map document 3d].freeze
|
16
18
|
|
17
19
|
# This class generates content metadata for image files
|
18
20
|
class ContentMetadata
|
@@ -60,7 +62,6 @@ module Assembly
|
|
60
62
|
common_path = find_common_path(objects) unless preserve_common_paths # find common paths to all files provided if needed
|
61
63
|
|
62
64
|
filesets = FileSetBuilder.build(bundle: bundle, objects: objects, style: style)
|
63
|
-
|
64
65
|
config = Config.new(auto_labels: auto_labels,
|
65
66
|
flatten_folder_structure: flatten_folder_structure,
|
66
67
|
add_file_attributes: add_file_attributes,
|
@@ -98,21 +99,16 @@ module Assembly
|
|
98
99
|
private_class_method :find_common_path
|
99
100
|
|
100
101
|
def self.object_level_type(style)
|
101
|
-
|
102
|
+
Deprecation.warn(self, "the style #{style} is now deprecated and should not be used. This will be removed in assembly-objectfile 2.0") if DEPRECATED_STYLES.include? style
|
103
|
+
raise "Supplied style (#{style}) not valid" unless (VALID_STYLES + DEPRECATED_STYLES).include? style
|
102
104
|
|
103
105
|
case style
|
104
106
|
when :simple_image
|
105
107
|
'image'
|
106
|
-
when :file
|
107
|
-
'file'
|
108
108
|
when :simple_book, :book_with_pdf, :book_as_image
|
109
109
|
'book'
|
110
|
-
when :map
|
111
|
-
'map'
|
112
|
-
when :'3d'
|
113
|
-
'3d'
|
114
110
|
else
|
115
|
-
|
111
|
+
style.to_s
|
116
112
|
end
|
117
113
|
end
|
118
114
|
end # class
|
@@ -12,7 +12,7 @@ module Assembly
|
|
12
12
|
|
13
13
|
# Represents a configuration for generating the content metadata
|
14
14
|
class Config < Dry::Struct
|
15
|
-
STYLES = %w[image file book map 3d].freeze
|
15
|
+
STYLES = %w[image file book map 3d document].freeze
|
16
16
|
attribute :auto_labels, Types::Strict::Bool.default(true)
|
17
17
|
attribute :flatten_folder_structure, Types::Strict::Bool.default(false)
|
18
18
|
attribute :add_file_attributes, Types::Strict::Bool.default(false)
|
@@ -6,6 +6,26 @@ module Assembly
|
|
6
6
|
class ContentMetadata
|
7
7
|
# Represents a single File
|
8
8
|
class File
|
9
|
+
# default publish/preserve/shelve attributes used in content metadata
|
10
|
+
# if no mimetype specific attributes are specified for a given file, define some defaults, and override for specific mimetypes below
|
11
|
+
ATTRIBUTES_FOR_TYPE = {
|
12
|
+
'default' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
13
|
+
'image/tif' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
14
|
+
'image/tiff' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
15
|
+
'image/jp2' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
16
|
+
'image/jpeg' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
17
|
+
'audio/wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
18
|
+
'audio/x-wav' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
19
|
+
'audio/mp3' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
20
|
+
'audio/mpeg' => { preserve: 'no', shelve: 'yes', publish: 'yes' },
|
21
|
+
'application/pdf' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
22
|
+
'plain/text' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
23
|
+
'text/plain' => { preserve: 'yes', shelve: 'yes', publish: 'yes' },
|
24
|
+
'image/png' => { preserve: 'yes', shelve: 'yes', publish: 'no' },
|
25
|
+
'application/zip' => { preserve: 'yes', shelve: 'no', publish: 'no' },
|
26
|
+
'application/json' => { preserve: 'yes', shelve: 'yes', publish: 'yes' }
|
27
|
+
}.freeze
|
28
|
+
|
9
29
|
# @param [Symbol] bundle
|
10
30
|
# @param [Assembly::ObjectFile] file
|
11
31
|
# @param style
|
@@ -28,7 +48,7 @@ module Assembly
|
|
28
48
|
end
|
29
49
|
|
30
50
|
def file_attributes(provided_file_attributes)
|
31
|
-
file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] ||
|
51
|
+
file.file_attributes || provided_file_attributes[mimetype] || provided_file_attributes['default'] || ATTRIBUTES_FOR_TYPE[mimetype] || ATTRIBUTES_FOR_TYPE['default']
|
32
52
|
end
|
33
53
|
|
34
54
|
def image_data
|
@@ -39,6 +39,7 @@ module Assembly
|
|
39
39
|
resource_files.collect { |obj| ContentMetadata.special_dpg_folder?(obj.dpg_folder) }.include?(true)
|
40
40
|
end
|
41
41
|
|
42
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
42
43
|
def resource_type_descriptions
|
43
44
|
# grab all of the file types within a resource into an array so we can decide what the resource type should be
|
44
45
|
resource_file_types = resource_files.collect(&:object_type)
|
@@ -57,6 +58,8 @@ module Assembly
|
|
57
58
|
resource_has_non_images ? 'object' : 'page'
|
58
59
|
when :map
|
59
60
|
'image'
|
61
|
+
when :document
|
62
|
+
'document'
|
60
63
|
when :'3d'
|
61
64
|
resource_extensions = resource_files.collect(&:ext)
|
62
65
|
if (resource_extensions & VALID_THREE_DIMENSION_EXTENTIONS).empty? # if this resource contains no known 3D file extensions, the resource type is file
|
@@ -66,6 +69,7 @@ module Assembly
|
|
66
69
|
end
|
67
70
|
end
|
68
71
|
end
|
72
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
@@ -2,610 +2,731 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Assembly::ContentMetadata do
|
6
|
-
|
7
|
-
|
8
|
-
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
9
|
-
expect(result.class).to be String
|
10
|
-
xml = Nokogiri::XML(result)
|
11
|
-
expect(xml.errors.size).to be 0
|
12
|
-
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
13
|
-
expect(xml.xpath('//resource').length).to be 2
|
14
|
-
expect(xml.xpath('//resource/file').length).to be 2
|
15
|
-
expect(xml.xpath('//resource/file/checksum').length).to be 4
|
16
|
-
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
|
17
|
-
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
|
18
|
-
expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
|
19
|
-
expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
|
20
|
-
expect(xml.xpath('//label').length).to be 2
|
21
|
-
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
22
|
-
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
23
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
24
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
25
|
-
expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
|
26
|
-
expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
|
27
|
-
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
28
|
-
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
|
29
|
-
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
30
|
-
expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
|
31
|
-
expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
|
32
|
-
expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
|
33
|
-
expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
|
34
|
-
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
35
|
-
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
|
36
|
-
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
37
|
-
expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
|
38
|
-
expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
|
39
|
-
end
|
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) }
|
40
8
|
|
41
|
-
|
42
|
-
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
43
|
-
obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
|
44
|
-
obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
|
45
|
-
obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
|
46
|
-
obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
|
47
|
-
objects = [obj1, obj2, obj3]
|
48
|
-
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
|
49
|
-
expect(result.class).to be String
|
50
|
-
xml = Nokogiri::XML(result)
|
51
|
-
expect(xml.errors.size).to be 0
|
52
|
-
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
53
|
-
expect(xml.xpath('//resource').length).to be 3
|
54
|
-
expect(xml.xpath('//resource/file').length).to be 3
|
55
|
-
expect(xml.xpath('//resource/file/checksum').length).to be 0
|
56
|
-
expect(xml.xpath('//resource/file/imageData').length).to be 0
|
57
|
-
expect(xml.xpath('//label').length).to be 3
|
58
|
-
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
59
|
-
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
60
|
-
expect(xml.xpath('//label')[2].text).to match(/Image 3/)
|
61
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
62
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
63
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
|
64
|
-
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
|
65
|
-
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
|
66
|
-
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
|
67
|
-
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
|
68
|
-
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
|
69
|
-
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
|
70
|
-
expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
|
71
|
-
expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
|
72
|
-
expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
|
73
|
-
end
|
9
|
+
let(:xml) { Nokogiri::XML(result) }
|
74
10
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
11
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
12
|
+
it 'generates valid content metadata with exif, adding file attributes' do
|
13
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
14
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
15
|
+
expect(result.class).to be String
|
16
|
+
xml = Nokogiri::XML(result)
|
17
|
+
expect(xml.errors.size).to eq 0
|
18
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
19
|
+
expect(xml.xpath('//resource').length).to eq 2
|
20
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
21
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 4
|
22
|
+
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
|
23
|
+
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
|
24
|
+
expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
|
25
|
+
expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
|
26
|
+
expect(xml.xpath('//label').length).to eq 2
|
27
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
28
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
29
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
30
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
31
|
+
expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
|
32
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
|
33
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
34
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
|
35
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
36
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
|
37
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
|
38
|
+
expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
|
39
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
|
40
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
41
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
|
42
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
43
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
|
44
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
|
45
|
+
end
|
46
|
+
end
|
109
47
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
48
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
49
|
+
it 'generates valid content metadata with no exif adding specific file attributes for 2 objects, and defaults for 1 object' do
|
50
|
+
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
51
|
+
obj2 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)
|
52
|
+
obj3 = Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE2)
|
53
|
+
obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no' }
|
54
|
+
obj2.file_attributes = { publish: 'yes', preserve: 'yes', shelve: 'yes' }
|
55
|
+
objects = [obj1, obj2, obj3]
|
56
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
|
57
|
+
expect(result.class).to be String
|
58
|
+
xml = Nokogiri::XML(result)
|
59
|
+
expect(xml.errors.size).to eq 0
|
60
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
61
|
+
expect(xml.xpath('//resource').length).to eq 3
|
62
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
63
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 0
|
64
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
65
|
+
expect(xml.xpath('//label').length).to eq 3
|
66
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
67
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
68
|
+
expect(xml.xpath('//label')[2].text).to match(/Image 3/)
|
69
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
70
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
71
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('image')
|
72
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no') # specificially set in object
|
73
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no') # specificially set in object
|
74
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no') # specificially set in object
|
75
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes') # specificially set in object
|
76
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes') # specificially set in object
|
77
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes') # specificially set in object
|
78
|
+
expect(xml.xpath('//resource/file')[2].attributes['publish'].value).to eq('yes') # defaults by mimetype
|
79
|
+
expect(xml.xpath('//resource/file')[2].attributes['preserve'].value).to eq('no') # defaults by mimetype
|
80
|
+
expect(xml.xpath('//resource/file')[2].attributes['shelve'].value).to eq('yes') # defaults by mimetype
|
81
|
+
end
|
82
|
+
end
|
122
83
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
84
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
85
|
+
it 'generates valid content metadata with exif, overriding file labels' do
|
86
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE, label: 'Sample tif label!'), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE, label: 'Sample jp2 label!')]
|
87
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: true, add_file_attributes: true, objects: objects)
|
88
|
+
expect(result.class).to be String
|
89
|
+
xml = Nokogiri::XML(result)
|
90
|
+
expect(xml.errors.size).to eq 0
|
91
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
92
|
+
expect(xml.xpath('//resource').length).to eq 2
|
93
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
94
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 4
|
95
|
+
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
|
96
|
+
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('a2400500acf21e43f5440d93be894101')
|
97
|
+
expect(xml.xpath('//resource/file/checksum')[2].text).to eq('b965b5787e0100ec2d43733144120feab327e88c')
|
98
|
+
expect(xml.xpath('//resource/file/checksum')[3].text).to eq('4eb54050d374291ece622d45e84f014d')
|
99
|
+
expect(xml.xpath('//label').length).to eq 2
|
100
|
+
expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
|
101
|
+
expect(xml.xpath('//label')[1].text).to match(/Sample jp2 label!/)
|
102
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
103
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
104
|
+
expect(xml.xpath('//resource/file')[0].attributes['size'].value).to eq('63542')
|
105
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype'].value).to eq('image/tiff')
|
106
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
107
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('yes')
|
108
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
109
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['width'].value).to eq('100')
|
110
|
+
expect(xml.xpath('//resource/file/imageData')[0].attributes['height'].value).to eq('100')
|
111
|
+
expect(xml.xpath('//resource/file')[1].attributes['size'].value).to eq('306')
|
112
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype'].value).to eq('image/jp2')
|
113
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
114
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('no')
|
115
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
116
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['width'].value).to eq('100')
|
117
|
+
expect(xml.xpath('//resource/file/imageData')[1].attributes['height'].value).to eq('100')
|
118
|
+
end
|
119
|
+
end
|
151
120
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
166
|
-
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
167
|
-
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
168
|
-
(0..1).each do |i|
|
169
|
-
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to be 1
|
170
|
-
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
171
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
121
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
122
|
+
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
|
123
|
+
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: '')]
|
124
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, auto_labels: false, add_file_attributes: true, objects: objects)
|
125
|
+
expect(result.class).to be String
|
126
|
+
xml = Nokogiri::XML(result)
|
127
|
+
expect(xml.errors.size).to eq 0
|
128
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
129
|
+
expect(xml.xpath('//resource').length).to eq 3
|
130
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
131
|
+
expect(xml.xpath('//label').length).to eq 1
|
132
|
+
expect(xml.xpath('//label')[0].text).to match(/Sample tif label!/)
|
133
|
+
end
|
172
134
|
end
|
173
|
-
end
|
174
135
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
136
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
137
|
+
it 'generates valid content metadata with overriding file attributes and no exif data' do
|
138
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
139
|
+
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)
|
140
|
+
expect(result.class).to be String
|
141
|
+
xml = Nokogiri::XML(result)
|
142
|
+
expect(xml.errors.size).to eq 0
|
143
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
144
|
+
expect(xml.xpath('//resource').length).to eq 2
|
145
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
146
|
+
expect(xml.xpath('//label').length).to eq 2
|
147
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
148
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
149
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
150
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
151
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
152
|
+
expect(xml.xpath('//resource/file')[0].attributes['size']).to be_nil
|
153
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
154
|
+
expect(xml.xpath('//resource/file')[0].attributes['role']).to be_nil
|
155
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('no')
|
156
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
157
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
158
|
+
expect(xml.xpath('//resource/file')[1].attributes['size']).to be_nil
|
159
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
160
|
+
expect(xml.xpath('//resource/file')[1].attributes['role']).to be_nil
|
161
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
162
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
163
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
164
|
+
end
|
195
165
|
end
|
196
|
-
end
|
197
166
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
167
|
+
context 'when using a single tif and jp2 of style=simple_image' do
|
168
|
+
it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
|
169
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
170
|
+
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)
|
171
|
+
expect(result.class).to be String
|
172
|
+
xml = Nokogiri::XML(result)
|
173
|
+
expect(xml.errors.size).to eq 0
|
174
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
175
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
176
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
177
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
178
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
179
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
180
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
181
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
182
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
183
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
184
|
+
(0..1).each do |i|
|
185
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
186
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
187
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
188
|
+
end
|
189
|
+
end
|
217
190
|
end
|
218
|
-
end
|
219
191
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
192
|
+
context 'when using a single tif and jp2 of style=map' do
|
193
|
+
it 'generates valid content metadata with overriding file attributes, including a default value, and no exif data' do
|
194
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_JP2_INPUT_FILE)]
|
195
|
+
result = described_class.create_content_metadata(style: :map, druid: TEST_DRUID, add_file_attributes: true, file_attributes: { 'default' => { publish: 'yes', preserve: 'no', shelve: 'no' }, 'image/jp2' => { publish: 'yes', preserve: 'yes', shelve: 'yes' } }, objects: objects)
|
196
|
+
expect(result.class).to be String
|
197
|
+
xml = Nokogiri::XML(result)
|
198
|
+
expect(xml.errors.size).to eq 0
|
199
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('map')
|
200
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
201
|
+
expect(xml.xpath('//resource/file')[0].attributes['mimetype']).to be_nil
|
202
|
+
expect(xml.xpath('//resource/file')[0].attributes['publish'].value).to eq('yes')
|
203
|
+
expect(xml.xpath('//resource/file')[0].attributes['preserve'].value).to eq('no')
|
204
|
+
expect(xml.xpath('//resource/file')[0].attributes['shelve'].value).to eq('no')
|
205
|
+
expect(xml.xpath('//resource/file')[1].attributes['mimetype']).to be_nil
|
206
|
+
expect(xml.xpath('//resource/file')[1].attributes['publish'].value).to eq('yes')
|
207
|
+
expect(xml.xpath('//resource/file')[1].attributes['preserve'].value).to eq('yes')
|
208
|
+
expect(xml.xpath('//resource/file')[1].attributes['shelve'].value).to eq('yes')
|
209
|
+
(0..1).each do |i|
|
210
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
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
|
214
|
+
end
|
243
215
|
end
|
244
|
-
end
|
245
216
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
217
|
+
context 'when using two tifs and two associated jp2s of style=simple_image using bundle=filename' do
|
218
|
+
it 'generates valid content metadata and no exif data' do
|
219
|
+
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)]
|
220
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :filename, objects: objects)
|
221
|
+
expect(result.class).to be String
|
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(xml.xpath('//resource').length).to eq 2
|
226
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
227
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('test.tif')
|
228
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('test.jp2')
|
229
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('test2.tif')
|
230
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('test2.jp2')
|
231
|
+
expect(xml.xpath('//label').length).to eq 2
|
232
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
233
|
+
(0..1).each do |i|
|
234
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 2
|
235
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
236
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
237
|
+
end
|
238
|
+
end
|
269
239
|
end
|
270
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to be 1
|
271
|
-
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
272
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
273
|
-
expect(xml.xpath("//resource[@sequence='4']/file").length).to be 1
|
274
|
-
expect(xml.xpath('//label')[3].text).to eq('Object 2')
|
275
|
-
expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('object')
|
276
|
-
end
|
277
240
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
241
|
+
context 'when using two tifs and two associated jp2s of style=simple_image using bundle=dpg' do
|
242
|
+
it 'generates valid content metadata and no exif data and no root xml node' do
|
243
|
+
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)]
|
244
|
+
test_druid = TEST_DRUID.to_s
|
245
|
+
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, include_root_xml: false)
|
246
|
+
expect(result.class).to be String
|
247
|
+
expect(result.include?('<?xml')).to be false
|
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(test_druid).to eq(TEST_DRUID)
|
252
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
|
253
|
+
expect(xml.xpath('//resource').length).to eq 2
|
254
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
255
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
|
256
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_001.jp2')
|
257
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_002.tif')
|
258
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('05/oo000oo0001_05_002.jp2')
|
259
|
+
expect(xml.xpath('//label').length).to eq 2
|
260
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
261
|
+
(0..1).each do |i|
|
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')
|
265
|
+
end
|
266
|
+
end
|
305
267
|
end
|
306
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to be 1
|
307
|
-
expect(xml.xpath('//label')[2].text).to eq('Object 1')
|
308
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
309
|
-
end
|
310
268
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
269
|
+
context 'when using two tifs, two associated jp2s, one combined pdf and one special tif of style=simple_book using bundle=dpg' do
|
270
|
+
it 'generates valid content metadata and no exif data and no root xml node, flattening folder structure' do
|
271
|
+
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)]
|
272
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, bundle: :dpg, objects: objects, include_root_xml: false, flatten_folder_structure: true)
|
273
|
+
expect(result.class).to be String
|
274
|
+
expect(result.include?('<?xml')).to be false
|
275
|
+
xml = Nokogiri::XML(result)
|
276
|
+
expect(xml.errors.size).to eq 0
|
277
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
278
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(TEST_DRUID.to_s)
|
279
|
+
expect(xml.xpath('//resource').length).to eq 4
|
280
|
+
expect(xml.xpath('//resource/file').length).to eq 6
|
281
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
|
282
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
|
283
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
|
284
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
|
285
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_31_001.pdf')
|
286
|
+
expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq('oo000oo0001_50_001.tif')
|
287
|
+
expect(xml.xpath('//label').length).to eq 4
|
288
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
289
|
+
(0..1).each do |i|
|
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')
|
293
|
+
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
|
+
end
|
301
|
+
end
|
338
302
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
303
|
+
context "when item has a 'druid:' prefix. Using two tifs, two associated jp2s, two associated pdfs and one lingering PDF of style=simple_book using bundle=dpg" do
|
304
|
+
it 'generates valid content metadata with flattening folder structure' do
|
305
|
+
objects = [Assembly::ObjectFile.new(TEST_DPG_TIF), Assembly::ObjectFile.new(TEST_DPG_JP),
|
306
|
+
Assembly::ObjectFile.new(TEST_DPG_PDF), Assembly::ObjectFile.new(TEST_DPG_TIF2),
|
307
|
+
Assembly::ObjectFile.new(TEST_DPG_JP2), Assembly::ObjectFile.new(TEST_DPG_PDF2),
|
308
|
+
Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)]
|
309
|
+
test_druid = "druid:#{TEST_DRUID}"
|
310
|
+
result = described_class.create_content_metadata(druid: test_druid, bundle: :dpg, objects: objects, style: :simple_book, flatten_folder_structure: true)
|
311
|
+
expect(result.class).to be String
|
312
|
+
expect(result.include?('<?xml')).to be true
|
313
|
+
xml = Nokogiri::XML(result)
|
314
|
+
expect(xml.errors.size).to eq 0
|
315
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
316
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['objectId'].value).to eq(test_druid)
|
317
|
+
expect(test_druid).to eq("druid:#{TEST_DRUID}")
|
318
|
+
expect(xml.xpath('//resource').length).to eq 3
|
319
|
+
expect(xml.xpath('//resource/file').length).to be 7
|
320
|
+
|
321
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_001.tif')
|
322
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_001.jp2')
|
323
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_001.pdf')
|
324
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq('oo000oo0001_00_002.tif')
|
325
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[1].attributes['id'].value).to eq('oo000oo0001_05_002.jp2')
|
326
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('oo000oo0001_15_002.pdf')
|
327
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('oo000oo0001_book.pdf')
|
328
|
+
expect(xml.xpath('//label').length).to eq 3
|
329
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
330
|
+
(0..1).each do |i|
|
331
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 3
|
332
|
+
expect(xml.xpath('//label')[i].text).to eq("Page #{i + 1}")
|
333
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('page')
|
334
|
+
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
|
+
end
|
358
339
|
end
|
359
|
-
end
|
360
340
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
341
|
+
context 'when using two tifs, two associated jp2s, two associated pdfs and one lingering PDF of style=book_with_pdf using bundle=dpg' do
|
342
|
+
subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :dpg, style: style, objects: objects) }
|
343
|
+
|
344
|
+
let(:objects) do
|
345
|
+
[
|
346
|
+
Assembly::ObjectFile.new(TEST_DPG_TIF),
|
347
|
+
Assembly::ObjectFile.new(TEST_DPG_JP),
|
348
|
+
Assembly::ObjectFile.new(TEST_DPG_PDF),
|
349
|
+
Assembly::ObjectFile.new(TEST_DPG_TIF2),
|
350
|
+
Assembly::ObjectFile.new(TEST_DPG_JP2),
|
351
|
+
Assembly::ObjectFile.new(TEST_DPG_SPECIAL_PDF1)
|
352
|
+
]
|
353
|
+
end
|
354
|
+
let(:style) { :book_with_pdf }
|
355
|
+
|
356
|
+
before do
|
357
|
+
allow(Deprecation).to receive(:warn)
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'generates valid content metadata' do
|
361
|
+
expect(xml.errors.size).to eq 0
|
362
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
363
|
+
expect(xml.xpath('//resource').length).to eq 3
|
364
|
+
expect(xml.xpath('//resource/file').length).to eq 6
|
365
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq('00/oo000oo0001_00_001.tif')
|
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')
|
382
|
+
end
|
380
383
|
end
|
381
|
-
end
|
382
384
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
385
|
+
context 'when using two tifs and two associated jp2s of style=simple_image using bundle=default' do
|
386
|
+
it 'generates valid content metadata and no exif data' do
|
387
|
+
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)]
|
388
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects)
|
389
|
+
expect(result.class).to be String
|
390
|
+
xml = Nokogiri::XML(result)
|
391
|
+
expect(xml.errors.size).to eq 0
|
392
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
393
|
+
expect(xml.xpath('//resource').length).to eq 4
|
394
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
395
|
+
expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('test.tif')
|
396
|
+
expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('test.jp2')
|
397
|
+
expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('test2.tif')
|
398
|
+
expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('test2.jp2')
|
399
|
+
expect(xml.xpath('//label').length).to eq 4
|
400
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
401
|
+
(0..3).each do |i|
|
402
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
403
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
404
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
405
|
+
end
|
406
|
+
end
|
405
407
|
end
|
406
|
-
end
|
407
408
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
409
|
+
context 'when using two tifs and two associated jp2s of style=simple_image using bundle=default' do
|
410
|
+
it 'generates valid content metadata and no exif data, preserving full paths' do
|
411
|
+
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)]
|
412
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, bundle: :default, objects: objects, preserve_common_paths: true)
|
413
|
+
expect(result.class).to be String
|
414
|
+
xml = Nokogiri::XML(result)
|
415
|
+
expect(xml.errors.size).to eq 0
|
416
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
417
|
+
expect(xml.xpath('//resource').length).to eq 4
|
418
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
419
|
+
expect(xml.xpath("//resource[@sequence='1']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE)
|
420
|
+
expect(xml.xpath("//resource[@sequence='2']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE)
|
421
|
+
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq(TEST_TIF_INPUT_FILE2)
|
422
|
+
expect(xml.xpath("//resource[@sequence='4']/file")[0].attributes['id'].value).to eq(TEST_JP2_INPUT_FILE2)
|
423
|
+
expect(xml.xpath('//label').length).to eq 4
|
424
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
425
|
+
(0..3).each do |i|
|
426
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
427
|
+
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
428
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
429
|
+
end
|
430
|
+
end
|
427
431
|
end
|
428
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
429
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
430
|
-
end
|
431
432
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
433
|
+
context 'when using two tifs and two associated jp2s of style=file' do
|
434
|
+
it 'generates valid content metadata using specific content metadata paths' do
|
435
|
+
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)]
|
436
|
+
objects[0].relative_path = 'input/test.tif'
|
437
|
+
objects[1].relative_path = 'input/test.jp2'
|
438
|
+
objects[2].relative_path = 'input/test2.tif'
|
439
|
+
objects[3].relative_path = 'input/test2.jp2'
|
440
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :file, objects: objects)
|
441
|
+
expect(result.class).to be String
|
442
|
+
xml = Nokogiri::XML(result)
|
443
|
+
expect(xml.errors.size).to eq 0
|
444
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
|
445
|
+
expect(xml.xpath('//resource').length).to eq 4
|
446
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
447
|
+
expect(xml.xpath('//label').length).to eq 4
|
448
|
+
expect(xml.xpath('//resource/file')[0].attributes['id'].value).to eq('input/test.tif')
|
449
|
+
expect(xml.xpath('//resource/file')[1].attributes['id'].value).to eq('input/test.jp2')
|
450
|
+
expect(xml.xpath('//resource/file')[2].attributes['id'].value).to eq('input/test2.tif')
|
451
|
+
expect(xml.xpath('//resource/file')[3].attributes['id'].value).to eq('input/test2.jp2')
|
452
|
+
(0..3).each do |i|
|
453
|
+
expect(xml.xpath("//resource[@sequence='#{i + 1}']/file").length).to eq 1
|
454
|
+
expect(xml.xpath('//label')[i].text).to eq("File #{i + 1}")
|
455
|
+
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('file')
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
450
459
|
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
460
|
+
context 'when using two tifs of style=simple_book' do
|
461
|
+
it 'generates valid content metadata for two tifs of style=simple_book' do
|
462
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
463
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
|
464
|
+
expect(result.class).to be String
|
465
|
+
xml = Nokogiri::XML(result)
|
466
|
+
expect(xml.errors.size).to eq 0
|
467
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
468
|
+
expect(xml.xpath('//resource').length).to eq 2
|
469
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
470
|
+
expect(xml.xpath('//label').length).to eq 2
|
471
|
+
expect(xml.xpath('//label')[0].text).to match(/Page 1/)
|
472
|
+
expect(xml.xpath('//label')[1].text).to match(/Page 2/)
|
473
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
474
|
+
(0..1).each do |i|
|
475
|
+
expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
|
476
|
+
expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
|
477
|
+
expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
|
478
|
+
expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
|
479
|
+
expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
|
480
|
+
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
|
+
end
|
470
484
|
end
|
471
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
472
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
473
|
-
end
|
474
485
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be nil
|
502
|
-
expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be nil
|
486
|
+
context 'when using style=book_with_pdf' do
|
487
|
+
let(:objects) do
|
488
|
+
[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
|
489
|
+
Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2),
|
490
|
+
Assembly::ObjectFile.new(TEST_PDF_FILE)]
|
491
|
+
end
|
492
|
+
let(:style) { :book_with_pdf }
|
493
|
+
|
494
|
+
before do
|
495
|
+
allow(Deprecation).to receive(:warn)
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'generates valid content metadata for two tifs' do
|
499
|
+
expect(xml.errors.size).to eq 0
|
500
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
501
|
+
expect(xml.xpath('//resource').length).to eq 3
|
502
|
+
expect(xml.xpath('//resource/file').length).to eq 3
|
503
|
+
expect(xml.xpath('//label').length).to eq 3
|
504
|
+
expect(xml.xpath('//label')[0].text).to match(/Page 1/)
|
505
|
+
expect(xml.xpath('//label')[1].text).to match(/Page 2/)
|
506
|
+
expect(xml.xpath('//label')[2].text).to match(/Object 1/)
|
507
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
508
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
509
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
510
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('object')
|
511
|
+
end
|
503
512
|
end
|
504
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
505
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
506
|
-
end
|
507
513
|
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
|
514
|
-
end
|
514
|
+
context 'when using style=book_as_image' do
|
515
|
+
let(:objects) do
|
516
|
+
[Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
|
517
|
+
Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)]
|
518
|
+
end
|
515
519
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
expect(xml.errors.size).to be 0
|
522
|
-
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
|
523
|
-
expect(xml.xpath('//resource').length).to be 4
|
524
|
-
expect(xml.xpath('//resource/file').length).to be 4
|
525
|
-
expect(xml.xpath('//label').length).to be 4
|
526
|
-
expect(xml.xpath('//label')[0].text).to match(/3d 1/)
|
527
|
-
expect(xml.xpath('//label')[1].text).to match(/File 1/)
|
528
|
-
expect(xml.xpath('//label')[2].text).to match(/File 2/)
|
529
|
-
expect(xml.xpath('//label')[3].text).to match(/File 3/)
|
530
|
-
expect(xml.xpath('//resource/file/imageData').length).to be 0
|
531
|
-
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
|
532
|
-
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
|
533
|
-
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
|
534
|
-
expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
|
535
|
-
end
|
520
|
+
let(:style) { :book_as_image }
|
521
|
+
|
522
|
+
before do
|
523
|
+
allow(Deprecation).to receive(:warn)
|
524
|
+
end
|
536
525
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[2].attributes['id'].value).to eq('res2_image2.tif')
|
559
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[3].attributes['id'].value).to eq('res2_image2.jp2')
|
560
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[4].attributes['id'].value).to eq('res2_teifile.txt')
|
561
|
-
expect(xml.xpath("//resource[@sequence='2']/file")[5].attributes['id'].value).to eq('res2_textfile.txt')
|
562
|
-
expect(xml.xpath("//resource[@sequence='2']/file").length).to be 6
|
563
|
-
|
564
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[0].attributes['id'].value).to eq('res3_image1.tif')
|
565
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[1].attributes['id'].value).to eq('res3_image1.jp2')
|
566
|
-
expect(xml.xpath("//resource[@sequence='3']/file")[2].attributes['id'].value).to eq('res3_teifile.txt')
|
567
|
-
expect(xml.xpath("//resource[@sequence='3']/file").length).to be 3
|
568
|
-
|
569
|
-
expect(xml.xpath('//label').length).to be 3
|
570
|
-
expect(xml.xpath('//resource/file/imageData').length).to be 0
|
571
|
-
(0..2).each do |i|
|
572
|
-
expect(xml.xpath('//label')[i].text).to eq("Image #{i + 1}")
|
573
|
-
expect(xml.xpath('//resource')[i].attributes['type'].value).to eq('image')
|
526
|
+
it 'generates valid content metadata for two tifs' do
|
527
|
+
expect(xml.errors.size).to eq 0
|
528
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
529
|
+
expect(xml.xpath('//resource').length).to eq 2
|
530
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
531
|
+
expect(xml.xpath('//label').length).to eq 2
|
532
|
+
expect(xml.xpath('//label')[0].text).to match(/Image 1/)
|
533
|
+
expect(xml.xpath('//label')[1].text).to match(/Image 2/)
|
534
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
535
|
+
(0..1).each do |i|
|
536
|
+
file = xml.xpath('//resource/file')[i]
|
537
|
+
|
538
|
+
expect(file.attributes['size']).to be_nil
|
539
|
+
expect(file.attributes['mimetype']).to be_nil
|
540
|
+
expect(file.attributes['publish']).to be_nil
|
541
|
+
expect(file.attributes['preserve']).to be_nil
|
542
|
+
expect(file.attributes['shelve']).to be_nil
|
543
|
+
end
|
544
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('image')
|
545
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('image')
|
546
|
+
end
|
574
547
|
end
|
575
|
-
end
|
576
548
|
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
|
582
|
-
expect(result.class).to be String
|
583
|
-
xml = Nokogiri::XML(result)
|
584
|
-
expect(xml.errors.size).to be 0
|
585
|
-
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
586
|
-
expect(xml.xpath('//resource').length).to be 1
|
587
|
-
expect(xml.xpath('//resource/file').length).to be 1
|
588
|
-
expect(xml.xpath('//resource/file').length).to be 1
|
589
|
-
expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
|
590
|
-
end
|
549
|
+
context 'when using style=document' do
|
550
|
+
let(:objects) do
|
551
|
+
[Assembly::ObjectFile.new(TEST_PDF_FILE)]
|
552
|
+
end
|
591
553
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
554
|
+
let(:style) { :document }
|
555
|
+
|
556
|
+
it 'generates valid content metadata' do
|
557
|
+
expect(xml.errors.size).to eq 0
|
558
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('document')
|
559
|
+
expect(xml.xpath('//resource').length).to eq 1
|
560
|
+
expect(xml.xpath('//resource/file').length).to eq 1
|
561
|
+
expect(xml.xpath('//label').length).to eq 1
|
562
|
+
expect(xml.xpath('//label')[0].text).to match(/Document 1/)
|
563
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
564
|
+
file = xml.xpath('//resource/file').first
|
565
|
+
expect(file.attributes['size']).to be_nil
|
566
|
+
expect(file.attributes['mimetype']).to be_nil
|
567
|
+
expect(file.attributes['publish']).to be_nil
|
568
|
+
expect(file.attributes['preserve']).to be_nil
|
569
|
+
expect(file.attributes['shelve']).to be_nil
|
570
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('document')
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context 'when using user supplied checksums for two tifs and style=simple_book' do
|
575
|
+
it 'generates valid content metadata with no exif' do
|
576
|
+
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
577
|
+
obj1.provider_md5 = '123456789'
|
578
|
+
obj1.provider_sha1 = 'abcdefgh'
|
579
|
+
obj2 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE2)
|
580
|
+
obj2.provider_md5 = 'qwerty'
|
581
|
+
objects = [obj1, obj2]
|
582
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, style: :simple_book, objects: objects)
|
583
|
+
expect(result.class).to be String
|
584
|
+
xml = Nokogiri::XML(result)
|
585
|
+
expect(xml.errors.size).to eq 0
|
586
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('book')
|
587
|
+
expect(xml.xpath('//resource').length).to eq 2
|
588
|
+
expect(xml.xpath('//resource/file').length).to eq 2
|
589
|
+
expect(xml.xpath('//resource/file/checksum').length).to eq 3
|
590
|
+
expect(xml.xpath('//label').length).to eq 2
|
591
|
+
expect(xml.xpath('//label')[0].text).to match(/Page 1/)
|
592
|
+
expect(xml.xpath('//label')[1].text).to match(/Page 2/)
|
593
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
594
|
+
expect(xml.xpath('//resource/file/checksum')[0].text).to eq('abcdefgh')
|
595
|
+
expect(xml.xpath('//resource/file/checksum')[1].text).to eq('123456789')
|
596
|
+
expect(xml.xpath('//resource/file/checksum')[2].text).to eq('qwerty')
|
597
|
+
(0..1).each do |i|
|
598
|
+
expect(xml.xpath('//resource/file')[i].attributes['size']).to be_nil
|
599
|
+
expect(xml.xpath('//resource/file')[i].attributes['mimetype']).to be_nil
|
600
|
+
expect(xml.xpath('//resource/file')[i].attributes['publish']).to be_nil
|
601
|
+
expect(xml.xpath('//resource/file')[i].attributes['preserve']).to be_nil
|
602
|
+
expect(xml.xpath('//resource/file')[i].attributes['shelve']).to be_nil
|
603
|
+
end
|
604
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('page')
|
605
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('page')
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
context 'when not all input files exist' do
|
610
|
+
it 'does not generate valid content metadata' do
|
611
|
+
expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
|
612
|
+
junk_file = '/tmp/flim_flam_floom.jp2'
|
613
|
+
expect(File.exist?(junk_file)).to be false
|
614
|
+
objects = [Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE), Assembly::ObjectFile.new(junk_file)]
|
615
|
+
expect { described_class.create_content_metadata(druid: TEST_DRUID, objects: objects) }.to raise_error(RuntimeError, "File '#{junk_file}' not found")
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
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
|
620
|
+
let(:objects) do
|
621
|
+
[Assembly::ObjectFile.new(TEST_OBJ_FILE),
|
622
|
+
Assembly::ObjectFile.new(TEST_PLY_FILE),
|
623
|
+
Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE),
|
624
|
+
Assembly::ObjectFile.new(TEST_PDF_FILE)]
|
625
|
+
end
|
626
|
+
let(:style) { :'3d' }
|
627
|
+
|
628
|
+
it 'generates valid content metadata' do
|
629
|
+
expect(xml.errors.size).to eq 0
|
630
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('3d')
|
631
|
+
expect(xml.xpath('//resource').length).to eq 4
|
632
|
+
expect(xml.xpath('//resource/file').length).to eq 4
|
633
|
+
expect(xml.xpath('//label').length).to eq 4
|
634
|
+
expect(xml.xpath('//label')[0].text).to match(/3d 1/)
|
635
|
+
expect(xml.xpath('//label')[1].text).to match(/File 1/)
|
636
|
+
expect(xml.xpath('//label')[2].text).to match(/File 2/)
|
637
|
+
expect(xml.xpath('//label')[3].text).to match(/File 3/)
|
638
|
+
expect(xml.xpath('//resource/file/imageData').length).to eq 0
|
639
|
+
expect(xml.xpath('//resource')[0].attributes['type'].value).to eq('3d')
|
640
|
+
expect(xml.xpath('//resource')[1].attributes['type'].value).to eq('file')
|
641
|
+
expect(xml.xpath('//resource')[2].attributes['type'].value).to eq('file')
|
642
|
+
expect(xml.xpath('//resource')[3].attributes['type'].value).to eq('file')
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
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
|
602
665
|
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|
+
context 'when providing file attributes' do
|
689
|
+
it 'generates role attributes for content metadata' do
|
690
|
+
obj1 = Assembly::ObjectFile.new(TEST_TIF_INPUT_FILE)
|
691
|
+
obj1.file_attributes = { publish: 'no', preserve: 'no', shelve: 'no', role: 'master-role' }
|
692
|
+
objects = [obj1]
|
693
|
+
result = described_class.create_content_metadata(druid: TEST_DRUID, add_exif: false, add_file_attributes: true, objects: objects)
|
694
|
+
expect(result.class).to be String
|
695
|
+
xml = Nokogiri::XML(result)
|
696
|
+
expect(xml.errors.size).to eq 0
|
697
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('image')
|
698
|
+
expect(xml.xpath('//resource').length).to eq 1
|
699
|
+
expect(xml.xpath('//resource/file').length).to eq 1
|
700
|
+
expect(xml.xpath('//resource/file').length).to eq 1
|
701
|
+
expect(xml.xpath('//resource/file')[0].attributes['role'].value).to eq('master-role')
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
context 'when no objects are passed in' do
|
706
|
+
subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
|
707
|
+
|
708
|
+
let(:objects) { [] }
|
709
|
+
|
710
|
+
let(:style) { :file }
|
711
|
+
|
712
|
+
it 'generates content metadata even when no objects are passed in' do
|
713
|
+
expect(xml.errors.size).to eq 0
|
714
|
+
expect(xml.xpath('//contentMetadata')[0].attributes['type'].value).to eq('file')
|
715
|
+
expect(xml.xpath('//resource').length).to eq 0
|
716
|
+
expect(xml.xpath('//resource/file').length).to eq 0
|
717
|
+
end
|
718
|
+
end
|
719
|
+
|
720
|
+
context 'when an unknown style is passed in' do
|
721
|
+
subject(:result) { described_class.create_content_metadata(druid: TEST_DRUID, bundle: :prebundled, style: style, objects: objects) }
|
722
|
+
|
723
|
+
let(:objects) { [] }
|
724
|
+
|
725
|
+
let(:style) { :borked }
|
726
|
+
|
727
|
+
it 'generates an error message' do
|
728
|
+
expect { result }.to raise_error 'Supplied style (borked) not valid'
|
729
|
+
end
|
730
|
+
end
|
610
731
|
end
|
611
732
|
end
|