lib/cocina/models/dro.rb in cocina-models-0.16.0 vs lib/cocina/models/dro.rb in cocina-models-0.17.0

- old
+ new

@@ -1,9 +1,7 @@ # frozen_string_literal: true -require 'json' - module Cocina module Models # A digital repository object. See http://sul-dlss.github.io/cocina-models/maps/DRO.json class DRO < Dry::Struct include Checkable @@ -50,11 +48,23 @@ params[:hasAdminPolicy] = dyn['hasAdminPolicy'] Administrative.new(params) end end + # Identification sub-schema for the DRO class Identification < Dry::Struct + attribute :sourceId, Types::Strict::String.meta(omittable: true) + attribute :catalogLinks, Types::Strict::Array.of(CatalogLink).meta(omittable: true) + def self.from_dynamic(dyn) + params = {} + params[:sourceId] = dyn['sourceId'] if dyn['sourceId'] + if dyn['catalogLinks'] + params[:catalogLinks] = dyn['catalogLinks'] + .map { |link| CatalogLink.from_dynamic(link) } + end + params + end end # Structural sub-schema for the DRO class Structural < Dry::Struct attribute :contains, Types::Strict::Array.of(FileSet).meta(omittable: true) @@ -78,23 +88,26 @@ # but I think it's actually required for every DRO attribute :description, Description.optional.default(nil) attribute(:identification, Identification.default { Identification.new }) attribute(:structural, Structural.default { Structural.new }) + # rubocop:disable Metrics/AbcSize def self.from_dynamic(dyn) params = { externalIdentifier: dyn['externalIdentifier'], type: dyn['type'], label: dyn['label'], version: dyn['version'] } params[:access] = Access.from_dynamic(dyn['access']) if dyn['access'] params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative'] - params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural'] params[:description] = Description.from_dynamic(dyn.fetch('description')) + params[:identification] = Identification.from_dynamic(dyn['identification']) if dyn['identification'] + params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural'] DRO.new(params) end + # rubocop:enable Metrics/AbcSize def self.from_json(json) from_dynamic(JSON.parse(json)) end