datacite 0.6.0 → 0.8.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +31 -9
- data/Gemfile +11 -10
- data/Gemfile.lock +136 -35
- data/README.md +20 -0
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/datacite.gemspec +19 -17
- data/lib/datacite/autogenerate_doi_request_body.rb +1 -1
- data/lib/datacite/client.rb +6 -6
- data/lib/datacite/mapping/from_cocina/alternate_identifiers.rb +30 -0
- data/lib/datacite/mapping/from_cocina/attributes.rb +74 -0
- data/lib/datacite/mapping/from_cocina/contributor_attributes.rb +209 -0
- data/lib/datacite/mapping/from_cocina/date.rb +198 -0
- data/lib/datacite/mapping/from_cocina/descriptions.rb +41 -0
- data/lib/datacite/mapping/from_cocina/identifiers.rb +28 -0
- data/lib/datacite/mapping/from_cocina/related_resource.rb +168 -0
- data/lib/datacite/mapping/from_cocina/rights_list.rb +36 -0
- data/lib/datacite/mapping/from_cocina/subject.rb +68 -0
- data/lib/datacite/mapping/from_cocina/titles.rb +32 -0
- data/lib/datacite/mapping/from_cocina/types.rb +81 -0
- data/lib/datacite/register_doi_request_body.rb +1 -1
- data/lib/datacite/response.rb +1 -1
- data/lib/datacite/schema/datacite-v4.6.json +643 -0
- data/lib/datacite/validators/attributes_validator.rb +43 -0
- data/lib/datacite/validators/cocina_validator.rb +26 -0
- data/lib/datacite/version.rb +1 -1
- data/lib/datacite.rb +1 -1
- metadata +46 -7
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Datacite
|
|
4
|
+
module Mapping
|
|
5
|
+
module FromCocina
|
|
6
|
+
# Transform the Cocina::Models::Description subjects attributes to the DataCite subjects attributes
|
|
7
|
+
# see https://support.datacite.org/reference/dois-2#put_dois-id
|
|
8
|
+
class Subject
|
|
9
|
+
# @param [Cocina::Models::Description] description
|
|
10
|
+
# @return [NilClass,Array<Hash>] list of DataCite subjects attributes, conforming to the expectations of
|
|
11
|
+
# HTTP PUT request to DataCite
|
|
12
|
+
def self.build(...)
|
|
13
|
+
new(...).call
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(description:)
|
|
17
|
+
@description = description
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [NilClass,Array<Hash>] list of DataCite subjects attributes, conforming to the expectations of
|
|
21
|
+
# HTTP PUT request to DataCite
|
|
22
|
+
def call
|
|
23
|
+
return if description&.subject.blank?
|
|
24
|
+
|
|
25
|
+
results = description.subject.map do |cocina_subject|
|
|
26
|
+
subject(cocina_subject)
|
|
27
|
+
end
|
|
28
|
+
results.compact.presence
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :description
|
|
34
|
+
|
|
35
|
+
def subject(cocina_subject)
|
|
36
|
+
return if cocina_subject.blank?
|
|
37
|
+
|
|
38
|
+
if fast?(cocina_subject)
|
|
39
|
+
fast_subject(cocina_subject)
|
|
40
|
+
else
|
|
41
|
+
non_fast_subject(cocina_subject)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def fast_subject(cocina_subject)
|
|
46
|
+
{
|
|
47
|
+
subjectScheme: 'fast',
|
|
48
|
+
schemeUri: 'http://id.worldcat.org/fast/'
|
|
49
|
+
|
|
50
|
+
}.tap do |attribs|
|
|
51
|
+
attribs[:subject] = cocina_subject.value if cocina_subject.value.present?
|
|
52
|
+
attribs[:valueUri] = cocina_subject.uri if cocina_subject.uri.present?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def non_fast_subject(cocina_subject)
|
|
57
|
+
return if cocina_subject.value.blank?
|
|
58
|
+
|
|
59
|
+
{ subject: cocina_subject.value }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def fast?(cocina_subject)
|
|
63
|
+
cocina_subject&.source&.code == 'fast'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Datacite
|
|
4
|
+
module Mapping
|
|
5
|
+
module FromCocina
|
|
6
|
+
# Transform the Cocina::Models::Description title attributes to attributes for one DataCite title
|
|
7
|
+
# see https://support.datacite.org/reference/dois-2#put_dois-id
|
|
8
|
+
class Titles
|
|
9
|
+
# @param [Cocina::Models::Description] description
|
|
10
|
+
# @return [Array<Hash>] list of titles for DataCite, conforming to the expectations of HTTP PUT request
|
|
11
|
+
# to DataCite
|
|
12
|
+
def self.build(...)
|
|
13
|
+
new(...).call
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(description:)
|
|
17
|
+
@description = description
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [Array<Hash>] list of titles for DataCite, conforming to the expectations of HTTP PUT request
|
|
21
|
+
# to DataCite
|
|
22
|
+
def call
|
|
23
|
+
[{ title: description.title.first.value }]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :description
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Datacite
|
|
4
|
+
module Mapping
|
|
5
|
+
module FromCocina
|
|
6
|
+
# Transform the Cocina::Models::Description form attributes to the DataCite types attributes
|
|
7
|
+
# see https://support.datacite.org/reference/dois-2#put_dois-id
|
|
8
|
+
class Types
|
|
9
|
+
# @param [Cocina::Models::Description] description
|
|
10
|
+
# @return [NilClass, Hash] the DataCite types attributes, conforming to the expectations of HTTP PUT request
|
|
11
|
+
# to DataCite
|
|
12
|
+
def self.build(...)
|
|
13
|
+
new(...).call
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(description:)
|
|
17
|
+
@description = description
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [NilClass, Hash] the DataCite types attributes, conforming to the expectations of HTTP PUT request
|
|
21
|
+
# to DataCite
|
|
22
|
+
def call
|
|
23
|
+
return unless resource_type_general || resource_type
|
|
24
|
+
|
|
25
|
+
{
|
|
26
|
+
resourceTypeGeneral: resource_type_general,
|
|
27
|
+
resourceType: resource_type || ''
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :description
|
|
34
|
+
|
|
35
|
+
# @return String DataCite resourceTypeGeneral value
|
|
36
|
+
def resource_type_general
|
|
37
|
+
@resource_type_general ||= Array(description.form).find do |cocina_form|
|
|
38
|
+
datacite_resource_types_form?(cocina_form)
|
|
39
|
+
end&.value
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @return [String] DataCite resourceType value
|
|
43
|
+
def resource_type
|
|
44
|
+
@resource_type ||= begin
|
|
45
|
+
self_deposit_form = Array(description.form).find { |cocina_form| self_deposit_form?(cocina_form) }
|
|
46
|
+
|
|
47
|
+
subtypes = self_deposit_subtypes(self_deposit_form)
|
|
48
|
+
if subtypes.blank?
|
|
49
|
+
self_deposit_type(self_deposit_form)
|
|
50
|
+
else
|
|
51
|
+
subtypes.select { |subtype| subtype if subtype != resource_type_general }.join('; ')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# call with cocina form element for Stanford self deposit resource types
|
|
57
|
+
# @return String the value from the structuredValue when the type is 'type' for the cocina form element
|
|
58
|
+
def self_deposit_type(cocina_self_deposit_form)
|
|
59
|
+
cocina_self_deposit_form&.structuredValue&.each do |struct_val|
|
|
60
|
+
return struct_val.value if struct_val.type == 'type'
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self_deposit_subtypes(cocina_self_deposit_form)
|
|
65
|
+
cocina_self_deposit_form&.structuredValue&.filter_map do |struct_val|
|
|
66
|
+
struct_val.value if struct_val.type == 'subtype'
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self_deposit_form?(cocina_form)
|
|
71
|
+
cocina_form.type == 'resource type' &&
|
|
72
|
+
cocina_form.source&.value == 'Stanford self-deposit resource types'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def datacite_resource_types_form?(cocina_form)
|
|
76
|
+
cocina_form.source&.value == 'DataCite resource types'
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|