Module: Cocina::Models

Defined in:
lib/cocina/models.rb,
lib/cocina/models/doi.rb,
lib/cocina/models/dro.rb,
lib/cocina/models/file.rb,
lib/cocina/models/purl.rb,
lib/cocina/models/druid.rb,
lib/cocina/models/event.rb,
lib/cocina/models/title.rb,
lib/cocina/models/utils.rb,
lib/cocina/models/access.rb,
lib/cocina/models/source.rb,
lib/cocina/models/barcode.rb,
lib/cocina/models/embargo.rb,
lib/cocina/models/license.rb,
lib/cocina/models/version.rb,
lib/cocina/models/dro_lite.rb,
lib/cocina/models/file_set.rb,
lib/cocina/models/file_use.rb,
lib/cocina/models/language.rb,
lib/cocina/models/sequence.rb,
lib/cocina/models/standard.rb,
lib/cocina/models/checkable.rb,
lib/cocina/models/copyright.rb,
lib/cocina/models/source_id.rb,
lib/cocina/models/applies_to.rb,
lib/cocina/models/collection.rb,
lib/cocina/models/dro_access.rb,
lib/cocina/models/geographic.rb,
lib/cocina/models/vocabulary.rb,
lib/cocina/models/access_role.rb,
lib/cocina/models/contributor.rb,
lib/cocina/models/dark_access.rb,
lib/cocina/models/description.rb,
lib/cocina/models/doi_pattern.rb,
lib/cocina/models/file_access.rb,
lib/cocina/models/object_type.rb,
lib/cocina/models/request_dro.rb,
lib/cocina/models/validatable.rb,
lib/cocina/models/admin_policy.rb,
lib/cocina/models/catalog_link.rb,
lib/cocina/models/language_tag.rb,
lib/cocina/models/mapping/purl.rb,
lib/cocina/models/presentation.rb,
lib/cocina/models/request_file.rb,
lib/cocina/models/world_access.rb,
lib/cocina/models/file_set_type.rb,
lib/cocina/models/administrative.rb,
lib/cocina/models/catkey_barcode.rb,
lib/cocina/models/cocina_version.rb,
lib/cocina/models/doi_exceptions.rb,
lib/cocina/models/dro_structural.rb,
lib/cocina/models/identification.rb,
lib/cocina/models/message_digest.rb,
lib/cocina/models/collection_lite.rb,
lib/cocina/models/object_metadata.rb,
lib/cocina/models/stanford_access.rb,
lib/cocina/models/business_barcode.rb,
lib/cocina/models/related_resource.rb,
lib/cocina/models/request_file_set.rb,
lib/cocina/models/standard_barcode.rb,
lib/cocina/models/admin_policy_lite.rb,
lib/cocina/models/collection_access.rb,
lib/cocina/models/descriptive_value.rb,
lib/cocina/models/dro_with_metadata.rb,
lib/cocina/models/access_role_member.rb,
lib/cocina/models/folio_catalog_link.rb,
lib/cocina/models/request_collection.rb,
lib/cocina/models/file_administrative.rb,
lib/cocina/models/file_set_structural.rb,
lib/cocina/models/mapping/escape_html.rb,
lib/cocina/models/request_description.rb,
lib/cocina/models/citation_only_access.rb,
lib/cocina/models/lane_medical_barcode.rb,
lib/cocina/models/mapping/to_mods/form.rb,
lib/cocina/models/mapping/to_mods/note.rb,
lib/cocina/models/request_admin_policy.rb,
lib/cocina/models/validators/validator.rb,
lib/cocina/models/location_based_access.rb,
lib/cocina/models/mapping/to_mods/event.rb,
lib/cocina/models/mapping/to_mods/title.rb,
lib/cocina/models/symphony_catalog_link.rb,
lib/cocina/models/builders/title_builder.rb,
lib/cocina/models/mapping/error_notifier.rb,
lib/cocina/models/mapping/from_mods/form.rb,
lib/cocina/models/mapping/from_mods/note.rb,
lib/cocina/models/mapping/from_mods/purl.rb,
lib/cocina/models/mapping/to_mods/access.rb,
lib/cocina/models/request_administrative.rb,
lib/cocina/models/request_dro_structural.rb,
lib/cocina/models/request_identification.rb,
lib/cocina/models/descriptive_basic_value.rb,
lib/cocina/models/mapping/from_mods/event.rb,
lib/cocina/models/mapping/from_mods/title.rb,
lib/cocina/models/mapping/to_mods/subject.rb,
lib/cocina/models/collection_with_metadata.rb,
lib/cocina/models/mapping/from_mods/access.rb,
lib/cocina/models/mapping/normalizers/base.rb,
lib/cocina/models/mapping/to_mods/language.rb,
lib/cocina/models/collection_identification.rb,
lib/cocina/models/descriptive_grouped_value.rb,
lib/cocina/models/mapping/from_mods/primary.rb,
lib/cocina/models/mapping/from_mods/subject.rb,
lib/cocina/models/validators/dark_validator.rb,
lib/cocina/models/validators/purl_validator.rb,
lib/cocina/models/admin_policy_with_metadata.rb,
lib/cocina/models/descriptive_admin_metadata.rb,
lib/cocina/models/descriptive_parallel_event.rb,
lib/cocina/models/descriptive_parallel_value.rb,
lib/cocina/models/descriptive_value_language.rb,
lib/cocina/models/mapping/from_mods/language.rb,
lib/cocina/models/mapping/to_mods/geographic.rb,
lib/cocina/models/mapping/to_mods/identifier.rb,
lib/cocina/models/admin_policy_administrative.rb,
lib/cocina/models/created_in_folio_identifier.rb,
lib/cocina/models/descriptive_access_metadata.rb,
lib/cocina/models/mapping/from_mods/authority.rb,
lib/cocina/models/mapping/from_mods/value_uri.rb,
lib/cocina/models/mapping/to_mods/contributor.rb,
lib/cocina/models/mapping/to_mods/description.rb,
lib/cocina/models/mapping/to_mods/mods_writer.rb,
lib/cocina/models/mapping/to_mods/name_writer.rb,
lib/cocina/models/mapping/to_mods/part_writer.rb,
lib/cocina/models/mapping/to_mods/role_writer.rb,
lib/cocina/models/request_file_set_structural.rb,
lib/cocina/models/validators/w3cdtf_validator.rb,
lib/cocina/models/admin_policy_access_template.rb,
lib/cocina/models/descriptive_structured_value.rb,
lib/cocina/models/mapping/from_mods/geographic.rb,
lib/cocina/models/mapping/from_mods/identifier.rb,
lib/cocina/models/mapping/to_mods/id_generator.rb,
lib/cocina/models/mapping/from_mods/contributor.rb,
lib/cocina/models/mapping/from_mods/description.rb,
lib/cocina/models/validators/open_api_validator.rb,
lib/cocina/models/location_based_download_access.rb,
lib/cocina/models/mapping/from_mods/name_builder.rb,
lib/cocina/models/mapping/from_mods/part_builder.rb,
lib/cocina/models/mapping/to_mods/admin_metadata.rb,
lib/cocina/models/use_and_reproduction_statement.rb,
lib/cocina/models/validators/date_time_validator.rb,
lib/cocina/models/descriptive_geographic_metadata.rb,
lib/cocina/models/mapping/from_mods/alt_rep_group.rb,
lib/cocina/models/mapping/from_mods/language_term.rb,
lib/cocina/models/mapping/from_mods/title_builder.rb,
lib/cocina/models/descriptive_parallel_contributor.rb,
lib/cocina/models/mapping/from_mods/admin_metadata.rb,
lib/cocina/models/mapping/to_mods/name_title_group.rb,
lib/cocina/models/mapping/to_mods/related_resource.rb,
lib/cocina/models/migrated_from_voyager_identifier.rb,
lib/cocina/models/builders/name_title_group_builder.rb,
lib/cocina/models/controlled_digital_lending_access.rb,
lib/cocina/models/mapping/from_mods/identifier_type.rb,
lib/cocina/models/mapping/from_mods/language_script.rb,
lib/cocina/models/migrated_from_symphony_identifier.rb,
lib/cocina/models/validators/language_tag_validator.rb,
lib/cocina/models/mapping/from_mods/related_resource.rb,
lib/cocina/models/validators/catalog_links_validator.rb,
lib/cocina/models/builders/rights_description_builder.rb,
lib/cocina/models/mapping/normalizers/mods_normalizer.rb,
lib/cocina/models/mapping/from_mods/identifier_builder.rb,
lib/cocina/models/validators/associated_name_validator.rb,
lib/cocina/models/mapping/from_mods/description_builder.rb,
lib/cocina/models/validators/description_types_validator.rb,
lib/cocina/models/validators/reserved_filename_validator.rb,
lib/cocina/models/builders/dro_rights_description_builder.rb,
lib/cocina/models/validators/description_values_validator.rb,
lib/cocina/models/mapping/from_mods/title_builder_strategy.rb,
lib/cocina/models/mapping/normalizers/mods/name_normalizer.rb,
lib/cocina/models/mapping/from_mods/subject_authority_codes.rb,
lib/cocina/models/mapping/normalizers/mods/title_normalizer.rb,
lib/cocina/models/mapping/normalizers/mods/subject_normalizer.rb,
lib/cocina/models/mapping/from_mods/hydrus_default_title_builder.rb,
lib/cocina/models/mapping/normalizers/mods/origin_info_normalizer.rb,
lib/cocina/models/mapping/normalizers/mods/geo_extension_normalizer.rb

Overview

Provides Ruby objects for the repository and serializing them to/from JSON.

Defined Under Namespace

Modules: Builders, Checkable, Mapping, Types, Utils, Validatable, Validators Classes: Access, AccessRole, AccessRoleMember, AdminPolicy, AdminPolicyAccessTemplate, AdminPolicyAdministrative, AdminPolicyLite, AdminPolicyWithMetadata, Administrative, AppliesTo, CitationOnlyAccess, Collection, CollectionAccess, CollectionIdentification, CollectionLite, CollectionWithMetadata, Contributor, ControlledDigitalLendingAccess, DRO, DROAccess, DROLite, DROStructural, DROWithMetadata, DarkAccess, Description, DescriptiveAccessMetadata, DescriptiveAdminMetadata, DescriptiveBasicValue, DescriptiveGeographicMetadata, DescriptiveGroupedValue, DescriptiveParallelContributor, DescriptiveParallelEvent, DescriptiveParallelValue, DescriptiveStructuredValue, DescriptiveValue, DescriptiveValueLanguage, Embargo, Error, Event, File, FileAccess, FileAdministrative, FileSet, FileSetStructural, FileSetType, FolioCatalogLink, Geographic, Identification, Language, LocationBasedAccess, LocationBasedDownloadAccess, MessageDigest, ObjectMetadata, ObjectType, Presentation, RelatedResource, RequestAdminPolicy, RequestAdministrative, RequestCollection, RequestDRO, RequestDROStructural, RequestDescription, RequestFile, RequestFileSet, RequestFileSetStructural, RequestIdentification, Sequence, Source, Standard, StanfordAccess, Struct, SymphonyCatalogLink, Title, UnknownTypeError, ValidationError, Vocabulary, WorldAccess

Constant Summary collapse

METADATA_KEYS =

rubocop:enable Naming/MethodName

%i[created modified lock].freeze
DOI =
DoiPattern | DoiExceptions
Purl =
Types::String.constrained(format: %r{^https://})
Druid =
Types::String.constrained(format: /^druid:[b-df-hjkmnp-tv-z]{2}[0-9]{3}[b-df-hjkmnp-tv-z]{2}[0-9]{4}$/)
Barcode =
BusinessBarcode | LaneMedicalBarcode | CatkeyBarcode | StandardBarcode
License =
Types::String.enum('https://www.gnu.org/licenses/agpl.txt', 'https://www.apache.org/licenses/LICENSE-2.0', 'https://opensource.org/licenses/BSD-2-Clause', 'https://opensource.org/licenses/BSD-3-Clause', 'https://creativecommons.org/licenses/by/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode', 'https://creativecommons.org/licenses/by-nd/4.0/legalcode', 'https://creativecommons.org/licenses/by-sa/4.0/legalcode', 'https://creativecommons.org/publicdomain/zero/1.0/legalcode', 'https://opensource.org/licenses/cddl1', 'https://www.eclipse.org/legal/epl-2.0', 'https://www.gnu.org/licenses/gpl-3.0-standalone.html', 'https://www.isc.org/downloads/software-support-policy/isc-license/', 'https://www.gnu.org/licenses/lgpl-3.0-standalone.html', 'https://opensource.org/licenses/MIT', 'https://www.mozilla.org/MPL/2.0/', 'https://opendatacommons.org/licenses/by/1-0/', 'http://opendatacommons.org/licenses/odbl/1.0/', 'https://opendatacommons.org/licenses/odbl/1-0/', 'https://creativecommons.org/publicdomain/mark/1.0/', 'https://opendatacommons.org/licenses/pddl/1-0/', 'https://creativecommons.org/licenses/by/3.0/legalcode', 'https://creativecommons.org/licenses/by-sa/3.0/legalcode', 'https://creativecommons.org/licenses/by-nd/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', 'https://cocina.sul.stanford.edu/licenses/none')
VERSION =
'0.99.0'
FileUse =
Types::String
Types::String
SourceId =
Types::String.constrained(format: /^.+:.+$/)
DoiPattern =
Types::String.constrained(format: %r{^10\.(25740|80343)/[b-df-hjkmnp-tv-z]{2}[0-9]{3}[b-df-hjkmnp-tv-z]{2}[0-9]{4}$})
FolioCatalogLink | SymphonyCatalogLink
LanguageTag =
Types::String
CatkeyBarcode =
Types::String.constrained(format: /^[0-9]+-[0-9]+$/)
CocinaVersion =
Types::String.constrained(format: /^\d+\.\d+\.\d+$/)
DoiExceptions =
Types::String.constrained(format: %r{^10\.(25740/([vV][aA]90-[cC][tT]15|[sS][yY][xX][aA]-[mM]256|12[qQ][fF]-5243|65[jJ]8-6114)|25936/629[tT]-[bB][xX]79)$})
BusinessBarcode =
Types::String.constrained(format: /^2050[0-9]{7}$/)
StandardBarcode =
Types::String.constrained(format: /^36105[0-9]{9}$/)
LaneMedicalBarcode =
Types::String.constrained(format: /^245[0-9]{8}$/)
CreatedInFolioIdentifier =
Types::String.constrained(format: /^in\d+$/)
UseAndReproductionStatement =
Types::String
MigratedFromVoyagerIdentifier =
Types::String.constrained(format: /^L\d+$/)
MigratedFromSymphonyIdentifier =
Types::String.constrained(format: /^a\d+$/)

Class Method Summary collapse

Class Method Details

.build(dyn, validate: true) ⇒ DRO, ...

Parameters:

  • dyn (Hash)

    a ruby hash representation of the JSON serialization of a collection or DRO

  • validate (boolean) (defaults to: true)

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cocina/models.rb', line 83

def self.build(dyn, validate: true)
  clazz = case type_for(dyn)
          when *DRO::TYPES
            has_metadata?(dyn) ? DROWithMetadata : DRO
          when *Collection::TYPES
            has_metadata?(dyn) ? CollectionWithMetadata : Collection
          when *AdminPolicy::TYPES
            has_metadata?(dyn) ? AdminPolicyWithMetadata : AdminPolicy
          else
            raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
          end
  clazz.new(dyn, false, validate)
end

.build_lite(dyn) ⇒ DROLite, ...

Build “lite” versions of DROs, Collections, and AdminPolicies. Lite versions do not require attributes that are required in the normal versions. For example, “description” is required for a DRO, but optional for a DROLite. Lite versions also are not validated / validatable. Lite versions are useful for instantiating partially populated cocina objects similar to an ActiveRecord instantiated using .select (See guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields)

Parameters:

  • dyn (Hash)

    a ruby hash representation of the JSON serialization of a Collection, DRO, or AdminPolicy

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cocina/models.rb', line 127

def self.build_lite(dyn)
  clazz = case type_for(dyn)
          when *DRO::TYPES
            DROLite
          when *Collection::TYPES
            CollectionLite
          when *AdminPolicy::TYPES
            AdminPolicyLite
          else
            raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
          end
  # dyn for lite may contain extra keys
  clazz.new(dyn.with_indifferent_access.slice(*clazz.attribute_names))
end

.build_request(dyn, validate: true) ⇒ RequestDRO, ...

Parameters:

  • dyn (Hash)

    a ruby hash representation of the JSON serialization of a request for a Collection or DRO

  • validate (boolean) (defaults to: true)

Returns:



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cocina/models.rb', line 103

def self.build_request(dyn, validate: true)
  clazz = case type_for(dyn)
          when *DRO::TYPES
            RequestDRO
          when *Collection::TYPES
            RequestCollection
          when *AdminPolicy::TYPES
            RequestAdminPolicy
          else
            raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
          end
  clazz.new(dyn, false, validate)
end

.druid_regexObject



192
193
194
195
196
197
# File 'lib/cocina/models.rb', line 192

def self.druid_regex
  @druid_regex ||= begin
    str = Openapi3Parser.load_file('openapi.yml').components.schemas['Druid'].pattern
    Regexp.new(str)
  end
end

.Vocabulary(uri) ⇒ Class

Alias for ‘Cocina::Models::Vocabulary.create`.

rubocop:disable Naming/MethodName

Returns:

  • (Class)


70
71
72
# File 'lib/cocina/models.rb', line 70

def self.Vocabulary(uri)
  Vocabulary.create(uri)
end

.with_metadata(cocina_object, lock, created: nil, modified: nil) ⇒ DROWithMetadata, ...

Adds metadata to a DRO, Collection, AdminPolicy or updates for a DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata

Parameters:

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/cocina/models.rb', line 157

def self.(cocina_object, lock, created: nil, modified: nil)
  props = cocina_object.to_h
  props[:created] = created.iso8601 if created
  props[:modified] = modified.iso8601 if modified
  props[:lock] = lock

  clazz = case cocina_object.type
          when *DRO::TYPES
            DROWithMetadata
          when *Collection::TYPES
            CollectionWithMetadata
          else
            AdminPolicyWithMetadata
          end
  clazz.new(props, false, false)
end

.without_metadata(cocina_object) ⇒ DRO, ...

Coerces DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata to DRO, Collection, AdminPolicy



145
146
147
# File 'lib/cocina/models.rb', line 145

def self.(cocina_object)
  build(cocina_object.to_h.except(*METADATA_KEYS), validate: false)
end