cocina-models 0.67.1 → 0.68.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/README.md +5 -0
  4. data/lib/cocina/generator/generator.rb +1 -6
  5. data/lib/cocina/generator/vocab.rb +36 -39
  6. data/lib/cocina/models/access.rb +3 -3
  7. data/lib/cocina/models/admin_policy.rb +1 -1
  8. data/lib/cocina/models/{admin_policy_default_access.rb → admin_policy_access_template.rb} +4 -4
  9. data/lib/cocina/models/admin_policy_administrative.rb +1 -1
  10. data/lib/cocina/models/administrative.rb +0 -3
  11. data/lib/cocina/models/citation_only_access.rb +3 -3
  12. data/lib/cocina/models/collection.rb +5 -5
  13. data/lib/cocina/models/collection_access.rb +1 -1
  14. data/lib/cocina/models/controlled_digital_lending_access.rb +3 -3
  15. data/lib/cocina/models/dark_access.rb +3 -3
  16. data/lib/cocina/models/dro.rb +15 -15
  17. data/lib/cocina/models/dro_access.rb +4 -4
  18. data/lib/cocina/models/embargo.rb +3 -3
  19. data/lib/cocina/models/file.rb +1 -1
  20. data/lib/cocina/models/file_access.rb +3 -3
  21. data/lib/cocina/models/file_set.rb +16 -16
  22. data/lib/cocina/models/file_set_type.rb +72 -0
  23. data/lib/cocina/models/location_based_access.rb +3 -3
  24. data/lib/cocina/models/location_based_download_access.rb +3 -3
  25. data/lib/cocina/models/object_type.rb +96 -0
  26. data/lib/cocina/models/request_admin_policy.rb +1 -1
  27. data/lib/cocina/models/request_administrative.rb +14 -0
  28. data/lib/cocina/models/request_collection.rb +6 -6
  29. data/lib/cocina/models/request_dro.rb +16 -16
  30. data/lib/cocina/models/request_file.rb +1 -1
  31. data/lib/cocina/models/request_file_set.rb +16 -16
  32. data/lib/cocina/models/stanford_access.rb +3 -3
  33. data/lib/cocina/models/version.rb +1 -1
  34. data/lib/cocina/models/world_access.rb +3 -3
  35. data/lib/cocina/models.rb +14 -7
  36. data/openapi.yml +132 -124
  37. metadata +6 -4
  38. data/lib/cocina/models/vocab.rb +0 -162
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # This vocabulary defines the top level object type
6
+ class ObjectType
7
+ def self.three_dimensional
8
+ 'https://cocina.sul.stanford.edu/models/3d'
9
+ end
10
+
11
+ def self.admin_policy
12
+ 'https://cocina.sul.stanford.edu/models/admin_policy'
13
+ end
14
+
15
+ def self.agreement
16
+ 'https://cocina.sul.stanford.edu/models/agreement'
17
+ end
18
+
19
+ def self.book
20
+ 'https://cocina.sul.stanford.edu/models/book'
21
+ end
22
+
23
+ def self.collection
24
+ 'https://cocina.sul.stanford.edu/models/collection'
25
+ end
26
+
27
+ def self.curated_collection
28
+ 'https://cocina.sul.stanford.edu/models/curated-collection'
29
+ end
30
+
31
+ def self.document
32
+ 'https://cocina.sul.stanford.edu/models/document'
33
+ end
34
+
35
+ def self.exhibit
36
+ 'https://cocina.sul.stanford.edu/models/exhibit'
37
+ end
38
+
39
+ def self.file
40
+ 'https://cocina.sul.stanford.edu/models/file'
41
+ end
42
+
43
+ def self.geo
44
+ 'https://cocina.sul.stanford.edu/models/geo'
45
+ end
46
+
47
+ def self.image
48
+ 'https://cocina.sul.stanford.edu/models/image'
49
+ end
50
+
51
+ def self.manuscript
52
+ 'https://cocina.sul.stanford.edu/models/manuscript'
53
+ end
54
+
55
+ def self.map
56
+ 'https://cocina.sul.stanford.edu/models/map'
57
+ end
58
+
59
+ def self.media
60
+ 'https://cocina.sul.stanford.edu/models/media'
61
+ end
62
+
63
+ def self.object
64
+ 'https://cocina.sul.stanford.edu/models/object'
65
+ end
66
+
67
+ def self.page
68
+ 'https://cocina.sul.stanford.edu/models/page'
69
+ end
70
+
71
+ def self.photograph
72
+ 'https://cocina.sul.stanford.edu/models/photograph'
73
+ end
74
+
75
+ def self.series
76
+ 'https://cocina.sul.stanford.edu/models/series'
77
+ end
78
+
79
+ def self.track
80
+ 'https://cocina.sul.stanford.edu/models/track'
81
+ end
82
+
83
+ def self.user_collection
84
+ 'https://cocina.sul.stanford.edu/models/user-collection'
85
+ end
86
+
87
+ def self.webarchive_binary
88
+ 'https://cocina.sul.stanford.edu/models/webarchive-binary'
89
+ end
90
+
91
+ def self.webarchive_seed
92
+ 'https://cocina.sul.stanford.edu/models/webarchive-seed'
93
+ end
94
+ end
95
+ end
96
+ end
@@ -7,7 +7,7 @@ module Cocina
7
7
 
8
8
  include Checkable
9
9
 
10
- TYPES = ['http://cocina.sul.stanford.edu/models/admin_policy.jsonld'].freeze
10
+ TYPES = ['https://cocina.sul.stanford.edu/models/admin_policy'].freeze
11
11
 
12
12
  # The version of Cocina with which this object conforms.
13
13
  # example: 1.2.3
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ class RequestAdministrative < Struct
6
+ # example: druid:bc123df4567
7
+ attribute :hasAdminPolicy, Types::Strict::String
8
+ attribute :releaseTags, Types::Strict::Array.of(ReleaseTag).default([].freeze)
9
+ # Internal project this resource is a part of. This governs routing of messages about this object.
10
+ # example: Google Books
11
+ attribute :partOfProject, Types::Strict::String.meta(omittable: true)
12
+ end
13
+ end
14
+ end
@@ -7,11 +7,11 @@ module Cocina
7
7
 
8
8
  include Checkable
9
9
 
10
- TYPES = ['http://cocina.sul.stanford.edu/models/collection.jsonld',
11
- 'http://cocina.sul.stanford.edu/models/curated-collection.jsonld',
12
- 'http://cocina.sul.stanford.edu/models/user-collection.jsonld',
13
- 'http://cocina.sul.stanford.edu/models/exhibit.jsonld',
14
- 'http://cocina.sul.stanford.edu/models/series.jsonld'].freeze
10
+ TYPES = ['https://cocina.sul.stanford.edu/models/collection',
11
+ 'https://cocina.sul.stanford.edu/models/curated-collection',
12
+ 'https://cocina.sul.stanford.edu/models/user-collection',
13
+ 'https://cocina.sul.stanford.edu/models/exhibit',
14
+ 'https://cocina.sul.stanford.edu/models/series'].freeze
15
15
 
16
16
  # The version of Cocina with which this object conforms.
17
17
  # example: 1.2.3
@@ -20,7 +20,7 @@ module Cocina
20
20
  attribute :label, Types::Strict::String
21
21
  attribute :version, Types::Strict::Integer.default(1).enum(1)
22
22
  attribute(:access, CollectionAccess.default { CollectionAccess.new })
23
- attribute(:administrative, Administrative.default { Administrative.new })
23
+ attribute(:administrative, RequestAdministrative.default { RequestAdministrative.new })
24
24
  attribute :description, RequestDescription.optional.meta(omittable: true)
25
25
  attribute :identification, CollectionIdentification.optional.meta(omittable: true)
26
26
  end
@@ -7,21 +7,21 @@ module Cocina
7
7
 
8
8
  include Checkable
9
9
 
10
- TYPES = ['http://cocina.sul.stanford.edu/models/object.jsonld',
11
- 'http://cocina.sul.stanford.edu/models/3d.jsonld',
12
- 'http://cocina.sul.stanford.edu/models/agreement.jsonld',
13
- 'http://cocina.sul.stanford.edu/models/book.jsonld',
14
- 'http://cocina.sul.stanford.edu/models/document.jsonld',
15
- 'http://cocina.sul.stanford.edu/models/geo.jsonld',
16
- 'http://cocina.sul.stanford.edu/models/image.jsonld',
17
- 'http://cocina.sul.stanford.edu/models/page.jsonld',
18
- 'http://cocina.sul.stanford.edu/models/photograph.jsonld',
19
- 'http://cocina.sul.stanford.edu/models/manuscript.jsonld',
20
- 'http://cocina.sul.stanford.edu/models/map.jsonld',
21
- 'http://cocina.sul.stanford.edu/models/media.jsonld',
22
- 'http://cocina.sul.stanford.edu/models/track.jsonld',
23
- 'http://cocina.sul.stanford.edu/models/webarchive-binary.jsonld',
24
- 'http://cocina.sul.stanford.edu/models/webarchive-seed.jsonld'].freeze
10
+ TYPES = ['https://cocina.sul.stanford.edu/models/object',
11
+ 'https://cocina.sul.stanford.edu/models/3d',
12
+ 'https://cocina.sul.stanford.edu/models/agreement',
13
+ 'https://cocina.sul.stanford.edu/models/book',
14
+ 'https://cocina.sul.stanford.edu/models/document',
15
+ 'https://cocina.sul.stanford.edu/models/geo',
16
+ 'https://cocina.sul.stanford.edu/models/image',
17
+ 'https://cocina.sul.stanford.edu/models/page',
18
+ 'https://cocina.sul.stanford.edu/models/photograph',
19
+ 'https://cocina.sul.stanford.edu/models/manuscript',
20
+ 'https://cocina.sul.stanford.edu/models/map',
21
+ 'https://cocina.sul.stanford.edu/models/media',
22
+ 'https://cocina.sul.stanford.edu/models/track',
23
+ 'https://cocina.sul.stanford.edu/models/webarchive-binary',
24
+ 'https://cocina.sul.stanford.edu/models/webarchive-seed'].freeze
25
25
 
26
26
  # The version of Cocina with which this object conforms.
27
27
  # example: 1.2.3
@@ -30,7 +30,7 @@ module Cocina
30
30
  attribute :label, Types::Strict::String
31
31
  attribute :version, Types::Strict::Integer.default(1).enum(1)
32
32
  attribute :access, DROAccess.optional.meta(omittable: true)
33
- attribute(:administrative, Administrative.default { Administrative.new })
33
+ attribute(:administrative, RequestAdministrative.default { RequestAdministrative.new })
34
34
  attribute :description, RequestDescription.optional.meta(omittable: true)
35
35
  attribute(:identification, RequestIdentification.default { RequestIdentification.new })
36
36
  attribute :structural, RequestDROStructural.optional.meta(omittable: true)
@@ -5,7 +5,7 @@ module Cocina
5
5
  class RequestFile < Struct
6
6
  include Checkable
7
7
 
8
- TYPES = ['http://cocina.sul.stanford.edu/models/file.jsonld'].freeze
8
+ TYPES = ['https://cocina.sul.stanford.edu/models/file'].freeze
9
9
 
10
10
  attribute :type, Types::Strict::String.enum(*RequestFile::TYPES)
11
11
  attribute :label, Types::Strict::String
@@ -5,22 +5,22 @@ module Cocina
5
5
  class RequestFileSet < Struct
6
6
  include Checkable
7
7
 
8
- TYPES = ['http://cocina.sul.stanford.edu/models/resources/audio.jsonld',
9
- 'http://cocina.sul.stanford.edu/models/resources/attachment.jsonld',
10
- 'http://cocina.sul.stanford.edu/models/resources/document.jsonld',
11
- 'http://cocina.sul.stanford.edu/models/resources/file.jsonld',
12
- 'http://cocina.sul.stanford.edu/models/resources/image.jsonld',
13
- 'http://cocina.sul.stanford.edu/models/resources/main-augmented.jsonld',
14
- 'http://cocina.sul.stanford.edu/models/resources/main-original.jsonld',
15
- 'http://cocina.sul.stanford.edu/models/resources/media.jsonld',
16
- 'http://cocina.sul.stanford.edu/models/resources/object.jsonld',
17
- 'http://cocina.sul.stanford.edu/models/resources/page.jsonld',
18
- 'http://cocina.sul.stanford.edu/models/resources/permissions.jsonld',
19
- 'http://cocina.sul.stanford.edu/models/resources/preview.jsonld',
20
- 'http://cocina.sul.stanford.edu/models/resources/supplement.jsonld',
21
- 'http://cocina.sul.stanford.edu/models/resources/3d.jsonld',
22
- 'http://cocina.sul.stanford.edu/models/resources/thumb.jsonld',
23
- 'http://cocina.sul.stanford.edu/models/resources/video.jsonld'].freeze
8
+ TYPES = ['https://cocina.sul.stanford.edu/models/resources/audio',
9
+ 'https://cocina.sul.stanford.edu/models/resources/attachment',
10
+ 'https://cocina.sul.stanford.edu/models/resources/document',
11
+ 'https://cocina.sul.stanford.edu/models/resources/file',
12
+ 'https://cocina.sul.stanford.edu/models/resources/image',
13
+ 'https://cocina.sul.stanford.edu/models/resources/main-augmented',
14
+ 'https://cocina.sul.stanford.edu/models/resources/main-original',
15
+ 'https://cocina.sul.stanford.edu/models/resources/media',
16
+ 'https://cocina.sul.stanford.edu/models/resources/object',
17
+ 'https://cocina.sul.stanford.edu/models/resources/page',
18
+ 'https://cocina.sul.stanford.edu/models/resources/permissions',
19
+ 'https://cocina.sul.stanford.edu/models/resources/preview',
20
+ 'https://cocina.sul.stanford.edu/models/resources/supplement',
21
+ 'https://cocina.sul.stanford.edu/models/resources/3d',
22
+ 'https://cocina.sul.stanford.edu/models/resources/thumb',
23
+ 'https://cocina.sul.stanford.edu/models/resources/video'].freeze
24
24
 
25
25
  attribute :type, Types::Strict::String.enum(*RequestFileSet::TYPES)
26
26
  attribute :label, Types::Strict::String
@@ -4,11 +4,11 @@ module Cocina
4
4
  module Models
5
5
  class StanfordAccess < Struct
6
6
  # Access level.
7
- attribute :access, Types::Strict::String.enum('stanford')
7
+ attribute :view, Types::Strict::String.enum('stanford')
8
8
  # Download access level.
9
9
  attribute :download, Types::Strict::String.enum('stanford')
10
- # If access is "location-based", which location should have access.
11
- attribute :readLocation, Types::Strict::String.optional.enum('').meta(omittable: true)
10
+ # Not used for this access type, must be null.
11
+ attribute :location, Types::Strict::String.optional.enum('').meta(omittable: true)
12
12
  attribute :controlledDigitalLending, Types::Strict::Bool.enum(false).meta(omittable: true)
13
13
  end
14
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocina
4
4
  module Models
5
- VERSION = '0.67.1'
5
+ VERSION = '0.68.0'
6
6
  end
7
7
  end
@@ -4,11 +4,11 @@ module Cocina
4
4
  module Models
5
5
  class WorldAccess < Struct
6
6
  # Access level.
7
- attribute :access, Types::Strict::String.enum('world')
7
+ attribute :view, Types::Strict::String.enum('world')
8
8
  # Download access level.
9
9
  attribute :download, Types::Strict::String.enum('none', 'stanford', 'world')
10
- # If access is "location-based", which location should have access.
11
- attribute :readLocation, Types::Strict::String.optional.enum('').meta(omittable: true)
10
+ # Not used for this access type, must be null.
11
+ attribute :location, Types::Strict::String.optional.enum('').meta(omittable: true)
12
12
  attribute :controlledDigitalLending, Types::Strict::Bool.enum(false).meta(omittable: true)
13
13
  end
14
14
  end
data/lib/cocina/models.rb CHANGED
@@ -42,7 +42,7 @@ module Cocina
42
42
  # Raised when the type attribute is not valid.
43
43
  class UnknownTypeError < Error; end
44
44
 
45
- # Raised when an error occurs validating against openapi.
45
+ # Raised when the type attribute is missing or an error occurs validating against openapi.
46
46
  class ValidationError < Error; end
47
47
 
48
48
  # Base class for Cocina Structs
@@ -60,10 +60,10 @@ module Cocina
60
60
  # @param [boolean] validate
61
61
  # @return [DRO,Collection,AdminPolicy]
62
62
  # @raises [UnknownTypeError] if a valid type is not found in the data
63
- # @raises [KeyError] if a type field cannot be found in the data
63
+ # @raises [ValidationError] if a type field cannot be found in the data
64
64
  # @raises [ValidationError] if hash representation fails openapi validation
65
65
  def self.build(dyn, validate: true)
66
- clazz = case dyn.fetch('type')
66
+ clazz = case type_for(dyn)
67
67
  when *DRO::TYPES
68
68
  DRO
69
69
  when *Collection::TYPES
@@ -71,7 +71,7 @@ module Cocina
71
71
  when *AdminPolicy::TYPES
72
72
  AdminPolicy
73
73
  else
74
- raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
74
+ raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
75
75
  end
76
76
  clazz.new(dyn, false, validate)
77
77
  end
@@ -80,10 +80,10 @@ module Cocina
80
80
  # @param [boolean] validate
81
81
  # @return [RequestDRO,RequestCollection,RequestAdminPolicy]
82
82
  # @raises [UnknownTypeError] if a valid type is not found in the data
83
- # @raises [KeyError] if a type field cannot be found in the data
83
+ # @raises [ValidationError] if a type field cannot be found in the data
84
84
  # @raises [ValidationError] if hash representation fails openapi validation
85
85
  def self.build_request(dyn, validate: true)
86
- clazz = case dyn.fetch('type')
86
+ clazz = case type_for(dyn)
87
87
  when *DRO::TYPES
88
88
  RequestDRO
89
89
  when *Collection::TYPES
@@ -91,9 +91,16 @@ module Cocina
91
91
  when *AdminPolicy::TYPES
92
92
  RequestAdminPolicy
93
93
  else
94
- raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
94
+ raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
95
95
  end
96
96
  clazz.new(dyn, false, validate)
97
97
  end
98
+
99
+ def self.type_for(dyn)
100
+ dyn.with_indifferent_access.fetch('type')
101
+ rescue KeyError
102
+ raise ValidationError, 'Type field not found'
103
+ end
104
+ private_class_method :type_for
98
105
  end
99
106
  end