Skip to content

Commit

Permalink
Return Cocina Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 10, 2019
1 parent addfa95 commit 98f8aa3
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions app/services/cocina/mapper.rb
Expand Up @@ -3,6 +3,9 @@
module Cocina
# Maps Dor::Items to Cocina objects
class Mapper
# Raised when called on something other than an item or collection
class UnsupportedObjectType < StandardError; end

def self.build(item)
new(item).build
end
Expand All @@ -12,22 +15,35 @@ def initialize(item)
end

def build
props = {
klass = cocina_klass
props = klass == Cocina::Models::DRO ? dro_props : collection_props
klass.new(props)
end

def dro_props
{
externalIdentifier: item.pid,
type: type,
type: 'http://sdr.sul.stanford.edu/models/sdr3-object.jsonld',
label: item.label,
version: item.current_version.to_i # TODO: remove to_i after upgrading cocina-models to 0.5.0
}

# Collections don't have embargoMetadata
if type == 'object' && item.embargoMetadata.release_date
props[:access] = {
embargoReleaseDate: item.embargoMetadata.release_date.iso8601
}
version: item.current_version,
administrative: build_administrative
}.tap do |props|
if item.embargoMetadata.release_date
props[:access] = {
embargoReleaseDate: item.embargoMetadata.release_date.iso8601
}
end
end
end

props[:administrative] = build_administrative
Cocina::Models::DRO.new(props)
def collection_props
{
externalIdentifier: item.pid,
type: 'http://sdr.sul.stanford.edu/models/sdr3-collection.jsonld',
label: item.label,
version: item.current_version,
administrative: build_administrative
}
end

private
Expand All @@ -53,16 +69,14 @@ def build_release_tags
end

# @todo This should have more speicific type such as found in identityMetadata.objectType
def type
def cocina_klass
case item
when Dor::Item
'object'
Cocina::Models::DRO
when Dor::Collection
'collection'
when Dor::AdminPolicyObject
'admin_policy'
Cocina::Models::Collection
else
raise "Unknown type for #{item.class}"
raise UnsupportedObjectType, "Unknown type for #{item.class}"
end
end
end
Expand Down

0 comments on commit 98f8aa3

Please sign in to comment.