Class: Datacite::Mapping::FromCocina::RelatedResource

Inherits:
Object
  • Object
show all
Defined in:
lib/datacite/mapping/from_cocina/related_resource.rb

Overview

Transform the Cocina::Models::Description relatedResource attributes to the DataCite relatedItem attributes

see https://support.datacite.org/reference/dois-2#put_dois-id

Constant Summary collapse

RELATION_TYPE_MAP =

rubocop:disable Metrics/ClassLength

{
  'supplement to' => 'IsSupplementTo',
  'supplemented by' => 'IsSupplementedBy',
  'referenced by' => 'IsReferencedBy',
  'references' => 'References',
  'derived from' => 'IsDerivedFrom',
  'source of' => 'IsSourceOf',
  'version of record' => 'IsVersionOf',
  'identical to' => 'IsIdenticalTo',
  'has version' => 'HasVersion',
  'preceded by' => 'Continues',
  'succeeded by' => 'IsContinuedBy',
  'part of' => 'IsPartOf',
  'has part' => 'HasPart'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(related_resource:) ⇒ RelatedResource

Returns a new instance of RelatedResource.



41
42
43
# File 'lib/datacite/mapping/from_cocina/related_resource.rb', line 41

def initialize(related_resource:)
  @related_resource = related_resource
end

Class Method Details

request to DataCite or nil if blank

see https://support.datacite.org/reference/dois-2#put_dois-id

Parameters:

  • related_resource (Cocina::Models::RelatedResource)

Returns:

  • (Hash)

    Hash of DataCite relatedIdentifier attributes, conforming to the expectations of HTTP PUT



37
38
39
# File 'lib/datacite/mapping/from_cocina/related_resource.rb', line 37

def self.related_identifier_attributes(...)
  new(...).related_identifier_attributes
end

request to DataCite or nil if blank

see https://support.datacite.org/reference/dois-2#put_dois-id

Parameters:

  • related_resource (Cocina::Models::RelatedResource)

Returns:

  • (Hash)

    Hash of DataCite relatedItem attributes, conforming to the expectations of HTTP PUT



29
30
31
# File 'lib/datacite/mapping/from_cocina/related_resource.rb', line 29

def self.related_item_attributes(...)
  new(...).related_item_attributes
end

Instance Method Details

request to DataCite or nil if blank or the identifier lacks a URI or Type

see https://support.datacite.org/reference/dois-2#put_dois-id

Returns:

  • (Hash, nil)

    Array of DataCite relatedIdentifier attributes, conforming to the expectations of HTTP PUT



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/datacite/mapping/from_cocina/related_resource.rb', line 76

def related_identifier_attributes
  return if related_identifier_blank?

  id, type = unpack_related_uri_and_type
  return unless id && type

  {
    resourceTypeGeneral: 'Other',
    relationType: relation_type,
    relatedIdentifier: id,
    relatedIdentifierType: type
  }
end

request to DataCite or nil if blank

see https://support.datacite.org/reference/dois-2#put_dois-id

Returns:

  • (Hash, nil)

    Array of DataCite relatedItem attributes, conforming to the expectations of HTTP PUT



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/datacite/mapping/from_cocina/related_resource.rb', line 48

def related_item_attributes # rubocop:disable Metrics/MethodLength
  return if related_resource_blank?

  titles = related_item_title ? [title: related_item_title] : []
  id, type = unpack_related_uri_and_type

  if id && type
    {
      relatedItemType: 'Other',
      titles: titles,
      relationType: relation_type,
      relatedItemIdentifier: {
        relatedItemIdentifier: id,
        relatedItemIdentifierType: type
      }
    }
  else
    {
      relatedItemType: 'Other',
      titles: titles,
      relationType: relation_type
    }
  end
end