sul_orcid_client 0.4.1 → 0.6.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 +353 -13
- data/Gemfile +2 -2
- data/Gemfile.lock +138 -124
- data/README.md +1 -2
- data/Rakefile +3 -3
- data/lib/sul_orcid_client/cocina_support.rb +7 -21
- data/lib/sul_orcid_client/contributor_mapper.rb +73 -28
- data/lib/sul_orcid_client/version.rb +1 -1
- data/lib/sul_orcid_client/work_mapper.rb +66 -59
- data/lib/sul_orcid_client.rb +45 -33
- data/sul_orcid_client.gemspec +32 -28
- metadata +65 -20
- data/.rubocop/custom.yml +0 -85
- data/.standard.yml +0 -1
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sul_orcid_client (0.
|
5
|
-
activesupport (>= 4.2
|
4
|
+
sul_orcid_client (0.6.0)
|
5
|
+
activesupport (>= 4.2)
|
6
6
|
cocina-models (~> 0.90)
|
7
7
|
faraday
|
8
8
|
faraday-retry
|
@@ -12,24 +12,28 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (
|
15
|
+
activesupport (8.0.2)
|
16
16
|
base64
|
17
|
+
benchmark (>= 0.3)
|
17
18
|
bigdecimal
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
19
20
|
connection_pool (>= 2.2.5)
|
20
21
|
drb
|
21
22
|
i18n (>= 1.6, < 2)
|
23
|
+
logger (>= 1.4.2)
|
22
24
|
minitest (>= 5.1)
|
23
|
-
|
24
|
-
tzinfo (~> 2.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
securerandom (>= 0.3)
|
26
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
27
|
+
uri (>= 0.13.1)
|
28
|
+
addressable (2.8.7)
|
29
|
+
public_suffix (>= 2.0.2, < 7.0)
|
30
|
+
ast (2.4.3)
|
28
31
|
attr_extras (7.1.0)
|
29
|
-
base64 (0.
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
base64 (0.3.0)
|
33
|
+
benchmark (0.4.1)
|
34
|
+
bigdecimal (3.2.2)
|
35
|
+
byebug (12.0.0)
|
36
|
+
cocina-models (0.104.1)
|
33
37
|
activesupport
|
34
38
|
deprecation
|
35
39
|
dry-struct (~> 1.0)
|
@@ -39,175 +43,181 @@ GEM
|
|
39
43
|
i18n
|
40
44
|
jsonpath
|
41
45
|
nokogiri
|
42
|
-
openapi3_parser
|
43
46
|
openapi_parser (~> 1.0)
|
44
|
-
rss
|
45
47
|
super_diff
|
46
48
|
thor
|
47
49
|
zeitwerk (~> 2.1)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
concurrent-ruby (1.3.5)
|
51
|
+
connection_pool (2.5.3)
|
52
|
+
crack (1.0.0)
|
53
|
+
bigdecimal
|
52
54
|
rexml
|
53
55
|
deprecation (1.1.0)
|
54
56
|
activesupport
|
55
|
-
diff-lcs (1.
|
56
|
-
docile (1.4.
|
57
|
-
drb (2.2.
|
58
|
-
|
59
|
-
dry-core (1.0.1)
|
57
|
+
diff-lcs (1.6.2)
|
58
|
+
docile (1.4.1)
|
59
|
+
drb (2.2.3)
|
60
|
+
dry-core (1.1.0)
|
60
61
|
concurrent-ruby (~> 1.0)
|
62
|
+
logger
|
61
63
|
zeitwerk (~> 2.6)
|
62
|
-
dry-inflector (1.
|
63
|
-
dry-logic (1.
|
64
|
+
dry-inflector (1.2.0)
|
65
|
+
dry-logic (1.6.0)
|
66
|
+
bigdecimal
|
64
67
|
concurrent-ruby (~> 1.0)
|
65
|
-
dry-core (~> 1.
|
68
|
+
dry-core (~> 1.1)
|
66
69
|
zeitwerk (~> 2.6)
|
67
|
-
dry-struct (1.
|
68
|
-
dry-core (~> 1.
|
69
|
-
dry-types (
|
70
|
+
dry-struct (1.8.0)
|
71
|
+
dry-core (~> 1.1)
|
72
|
+
dry-types (~> 1.8, >= 1.8.2)
|
70
73
|
ice_nine (~> 0.11)
|
71
74
|
zeitwerk (~> 2.6)
|
72
|
-
dry-types (1.
|
75
|
+
dry-types (1.8.3)
|
76
|
+
bigdecimal (~> 3.0)
|
73
77
|
concurrent-ruby (~> 1.0)
|
74
78
|
dry-core (~> 1.0)
|
75
79
|
dry-inflector (~> 1.0)
|
76
80
|
dry-logic (~> 1.4)
|
77
81
|
zeitwerk (~> 2.6)
|
78
|
-
edtf (3.
|
79
|
-
activesupport (>= 3.0, <
|
82
|
+
edtf (3.2.0)
|
83
|
+
activesupport (>= 3.0, < 9.0)
|
80
84
|
equivalent-xml (0.6.0)
|
81
85
|
nokogiri (>= 1.4.3)
|
82
|
-
faraday (2.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
faraday-net_http (3.
|
87
|
-
|
86
|
+
faraday (2.13.1)
|
87
|
+
faraday-net_http (>= 2.0, < 3.5)
|
88
|
+
json
|
89
|
+
logger
|
90
|
+
faraday-net_http (3.4.1)
|
91
|
+
net-http (>= 0.5.0)
|
92
|
+
faraday-retry (2.3.2)
|
88
93
|
faraday (~> 2.0)
|
89
|
-
hashdiff (1.0
|
94
|
+
hashdiff (1.2.0)
|
90
95
|
hashie (5.0.0)
|
91
|
-
i18n (1.14.
|
96
|
+
i18n (1.14.7)
|
92
97
|
concurrent-ruby (~> 1.0)
|
93
98
|
ice_nine (0.11.2)
|
94
|
-
json (2.
|
99
|
+
json (2.12.2)
|
95
100
|
jsonpath (1.1.5)
|
96
101
|
multi_json
|
97
|
-
jwt (
|
98
|
-
|
102
|
+
jwt (3.1.2)
|
103
|
+
base64
|
104
|
+
language_server-protocol (3.17.0.5)
|
99
105
|
lint_roller (1.1.0)
|
100
|
-
|
106
|
+
logger (1.7.0)
|
107
|
+
minitest (5.25.5)
|
101
108
|
multi_json (1.15.0)
|
102
|
-
multi_xml (0.
|
103
|
-
|
104
|
-
|
109
|
+
multi_xml (0.7.2)
|
110
|
+
bigdecimal (~> 3.1)
|
111
|
+
net-http (0.6.0)
|
112
|
+
uri
|
113
|
+
nokogiri (1.18.8-arm64-darwin)
|
105
114
|
racc (~> 1.4)
|
106
|
-
nokogiri (1.
|
115
|
+
nokogiri (1.18.8-x86_64-darwin)
|
107
116
|
racc (~> 1.4)
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
nokogiri (1.18.8-x86_64-linux-gnu)
|
118
|
+
racc (~> 1.4)
|
119
|
+
oauth2 (2.0.12)
|
120
|
+
faraday (>= 0.17.3, < 4.0)
|
121
|
+
jwt (>= 1.0, < 4.0)
|
122
|
+
logger (~> 1.2)
|
111
123
|
multi_xml (~> 0.5)
|
112
124
|
rack (>= 1.2, < 4)
|
113
|
-
snaky_hash (~> 2.0)
|
114
|
-
version_gem (
|
115
|
-
openapi3_parser (0.9.2)
|
116
|
-
commonmarker (~> 0.17)
|
125
|
+
snaky_hash (~> 2.0, >= 2.0.3)
|
126
|
+
version_gem (>= 1.1.8, < 3)
|
117
127
|
openapi_parser (1.0.0)
|
118
|
-
optimist (3.1
|
119
|
-
parallel (1.
|
120
|
-
parser (3.
|
128
|
+
optimist (3.2.1)
|
129
|
+
parallel (1.27.0)
|
130
|
+
parser (3.3.8.0)
|
121
131
|
ast (~> 2.4.1)
|
122
132
|
racc
|
123
133
|
patience_diff (1.2.0)
|
124
134
|
optimist (~> 3.0)
|
125
|
-
|
126
|
-
|
127
|
-
|
135
|
+
prism (1.4.0)
|
136
|
+
public_suffix (6.0.2)
|
137
|
+
racc (1.8.1)
|
138
|
+
rack (3.1.16)
|
128
139
|
rainbow (3.1.1)
|
129
|
-
rake (13.
|
130
|
-
regexp_parser (2.
|
131
|
-
rexml (3.
|
132
|
-
rspec (3.
|
133
|
-
rspec-core (~> 3.
|
134
|
-
rspec-expectations (~> 3.
|
135
|
-
rspec-mocks (~> 3.
|
136
|
-
rspec-core (3.
|
137
|
-
rspec-support (~> 3.
|
138
|
-
rspec-expectations (3.
|
140
|
+
rake (13.3.0)
|
141
|
+
regexp_parser (2.10.0)
|
142
|
+
rexml (3.4.1)
|
143
|
+
rspec (3.13.1)
|
144
|
+
rspec-core (~> 3.13.0)
|
145
|
+
rspec-expectations (~> 3.13.0)
|
146
|
+
rspec-mocks (~> 3.13.0)
|
147
|
+
rspec-core (3.13.5)
|
148
|
+
rspec-support (~> 3.13.0)
|
149
|
+
rspec-expectations (3.13.5)
|
139
150
|
diff-lcs (>= 1.2.0, < 2.0)
|
140
|
-
rspec-support (~> 3.
|
141
|
-
rspec-mocks (3.
|
151
|
+
rspec-support (~> 3.13.0)
|
152
|
+
rspec-mocks (3.13.5)
|
142
153
|
diff-lcs (>= 1.2.0, < 2.0)
|
143
|
-
rspec-support (~> 3.
|
144
|
-
rspec-support (3.
|
145
|
-
|
146
|
-
rexml
|
147
|
-
rubocop (1.57.2)
|
154
|
+
rspec-support (~> 3.13.0)
|
155
|
+
rspec-support (3.13.4)
|
156
|
+
rubocop (1.77.0)
|
148
157
|
json (~> 2.3)
|
149
|
-
language_server-protocol (
|
158
|
+
language_server-protocol (~> 3.17.0.2)
|
159
|
+
lint_roller (~> 1.1.0)
|
150
160
|
parallel (~> 1.10)
|
151
|
-
parser (>= 3.
|
161
|
+
parser (>= 3.3.0.2)
|
152
162
|
rainbow (>= 2.2.2, < 4.0)
|
153
|
-
regexp_parser (>=
|
154
|
-
|
155
|
-
rubocop-ast (>= 1.28.1, < 2.0)
|
163
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
164
|
+
rubocop-ast (>= 1.45.1, < 2.0)
|
156
165
|
ruby-progressbar (~> 1.7)
|
157
|
-
unicode-display_width (>= 2.4.0, <
|
158
|
-
rubocop-ast (1.
|
159
|
-
parser (>= 3.
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
rubocop (~> 1.
|
164
|
-
rubocop-
|
165
|
-
|
166
|
-
rubocop
|
167
|
-
rubocop-
|
168
|
-
|
169
|
-
rubocop
|
170
|
-
rubocop-
|
166
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
167
|
+
rubocop-ast (1.45.1)
|
168
|
+
parser (>= 3.3.7.2)
|
169
|
+
prism (~> 1.4)
|
170
|
+
rubocop-capybara (2.22.1)
|
171
|
+
lint_roller (~> 1.1)
|
172
|
+
rubocop (~> 1.72, >= 1.72.1)
|
173
|
+
rubocop-factory_bot (2.27.1)
|
174
|
+
lint_roller (~> 1.1)
|
175
|
+
rubocop (~> 1.72, >= 1.72.1)
|
176
|
+
rubocop-performance (1.25.0)
|
177
|
+
lint_roller (~> 1.1)
|
178
|
+
rubocop (>= 1.75.0, < 2.0)
|
179
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
180
|
+
rubocop-rspec (3.6.0)
|
181
|
+
lint_roller (~> 1.1)
|
182
|
+
rubocop (~> 1.72, >= 1.72.1)
|
183
|
+
rubocop-rspec_rails (2.31.0)
|
184
|
+
lint_roller (~> 1.1)
|
185
|
+
rubocop (~> 1.72, >= 1.72.1)
|
186
|
+
rubocop-rspec (~> 3.5)
|
171
187
|
ruby-progressbar (1.13.0)
|
172
|
-
|
188
|
+
securerandom (0.4.1)
|
173
189
|
simplecov (0.22.0)
|
174
190
|
docile (~> 1.1)
|
175
191
|
simplecov-html (~> 0.11)
|
176
192
|
simplecov_json_formatter (~> 0.1)
|
177
|
-
simplecov-html (0.
|
193
|
+
simplecov-html (0.13.1)
|
178
194
|
simplecov_json_formatter (0.1.4)
|
179
|
-
snaky_hash (2.0.
|
180
|
-
hashie
|
181
|
-
version_gem (
|
182
|
-
|
183
|
-
language_server-protocol (~> 3.17.0.2)
|
184
|
-
lint_roller (~> 1.0)
|
185
|
-
rubocop (~> 1.57.2)
|
186
|
-
standard-custom (~> 1.0.0)
|
187
|
-
standard-performance (~> 1.2)
|
188
|
-
standard-custom (1.0.2)
|
189
|
-
lint_roller (~> 1.0)
|
190
|
-
rubocop (~> 1.50)
|
191
|
-
standard-performance (1.2.1)
|
192
|
-
lint_roller (~> 1.1)
|
193
|
-
rubocop-performance (~> 1.19.1)
|
194
|
-
super_diff (0.10.0)
|
195
|
+
snaky_hash (2.0.3)
|
196
|
+
hashie (>= 0.1.0, < 6)
|
197
|
+
version_gem (>= 1.1.8, < 3)
|
198
|
+
super_diff (0.16.0)
|
195
199
|
attr_extras (>= 6.2.4)
|
196
200
|
diff-lcs
|
197
201
|
patience_diff
|
198
|
-
thor (1.3.
|
202
|
+
thor (1.3.2)
|
199
203
|
tzinfo (2.0.6)
|
200
204
|
concurrent-ruby (~> 1.0)
|
201
|
-
unicode-display_width (
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
+
unicode-display_width (3.1.4)
|
206
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
207
|
+
unicode-emoji (4.0.4)
|
208
|
+
uri (1.0.3)
|
209
|
+
vcr (6.3.1)
|
210
|
+
base64
|
211
|
+
version_gem (1.1.8)
|
212
|
+
webmock (3.25.1)
|
205
213
|
addressable (>= 2.8.0)
|
206
214
|
crack (>= 0.3.2)
|
207
215
|
hashdiff (>= 0.4.0, < 2.0.0)
|
208
|
-
zeitwerk (2.
|
216
|
+
zeitwerk (2.7.3)
|
209
217
|
|
210
218
|
PLATFORMS
|
219
|
+
arm64-darwin-23
|
220
|
+
arm64-darwin-24
|
211
221
|
x86_64-darwin-19
|
212
222
|
x86_64-darwin-22
|
213
223
|
x86_64-linux
|
@@ -216,12 +226,16 @@ DEPENDENCIES
|
|
216
226
|
byebug
|
217
227
|
rake (~> 13.0)
|
218
228
|
rspec (~> 3.0)
|
229
|
+
rubocop
|
230
|
+
rubocop-capybara
|
231
|
+
rubocop-factory_bot
|
232
|
+
rubocop-performance
|
219
233
|
rubocop-rspec
|
234
|
+
rubocop-rspec_rails
|
220
235
|
simplecov
|
221
|
-
standard
|
222
236
|
sul_orcid_client!
|
223
237
|
vcr
|
224
238
|
webmock
|
225
239
|
|
226
240
|
BUNDLED WITH
|
227
|
-
2.
|
241
|
+
2.6.9
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
[](https://badge.fury.io/rb/sul_orcid_client)
|
2
2
|
[](https://dl.circleci.com/status-badge/redirect/gh/sul-dlss/orcid_client/tree/main)
|
3
|
-
[](https://codeclimate.com/github/sul-dlss/orcid_client/test_coverage)
|
3
|
+
[](https://codecov.io/github/sul-dlss/orcid_client)
|
5
4
|
|
6
5
|
# orcid_client
|
7
6
|
API client for accessing ORCID API and for mapping to ORCID works.
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
6
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
8
|
RuboCop::RakeTask.new
|
@@ -1,38 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class SulOrcidClient
|
2
4
|
# Helper methods for working with Orcid in Cocina
|
3
|
-
# NOTE: there is similar code in dor_indexing_app which fetches
|
4
|
-
# ORCIDs out of cocina. Consider consolidating at some point or keeping in sync.
|
5
|
-
# see https://github.com/sul-dlss/dor_indexing_app/blob/main/app/services/orcid_builder.rb
|
6
|
-
# and https://github.com/sul-dlss/dor_indexing_app/issues/1022
|
7
5
|
class CocinaSupport
|
8
|
-
# @param [Cocina::Models::Contributor] contributor to check
|
9
|
-
# @return [Boolean] true unless the contributor has a citation status of false
|
10
|
-
def self.cited?(contributor)
|
11
|
-
contributor.note.none? { |note| note.type == "citation status" && note.value == "false" }
|
12
|
-
end
|
13
|
-
|
14
6
|
# @param [Cocina::Models::Contributor] contributor to check
|
15
7
|
# @return [String, nil] orcid id including host if present
|
8
|
+
# rubocop:disable Metrics/AbcSize
|
16
9
|
def self.orcidid(contributor)
|
17
|
-
identifier = contributor.identifier.find { |
|
10
|
+
identifier = contributor.identifier.find { |check_identifier| check_identifier.type == 'ORCID' }
|
18
11
|
return unless identifier
|
19
12
|
|
20
13
|
# some records have the full ORCID URI in the data, just return it if so, e.g. druid:gf852zt8324
|
21
14
|
return identifier.uri if identifier.uri
|
22
|
-
return identifier.value if identifier.value.start_with?(
|
15
|
+
return identifier.value if identifier.value.start_with?('https://orcid.org/')
|
23
16
|
|
24
17
|
# some records have just the ORCIDID without the URL prefix, add it if so, e.g. druid:tp865ng1792
|
25
|
-
return URI.join(
|
18
|
+
return URI.join('https://orcid.org/', identifier.value).to_s if identifier.source.uri.blank?
|
26
19
|
|
27
20
|
URI.join(identifier.source.uri, identifier.value).to_s
|
28
21
|
end
|
29
|
-
|
30
|
-
# @param [Cocina::Models::Description] description containing contributors to check
|
31
|
-
# @return [Array<String>] orcid ids including host if present
|
32
|
-
# Note that non-cited contributors are excluded.
|
33
|
-
def self.cited_orcidids(description)
|
34
|
-
cited_contributors = description.contributor.select { |contributor| cited?(contributor) }
|
35
|
-
cited_contributors.map { |contributor| orcidid(contributor) }.compact
|
36
|
-
end
|
22
|
+
# rubocop:enable Metrics/AbcSize
|
37
23
|
end
|
38
24
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class SulOrcidClient
|
2
4
|
# Maps a Cocina Contributor to an Orcid Contributor.
|
3
|
-
|
4
5
|
class ContributorMapper
|
5
6
|
def self.map(contributor:)
|
6
|
-
new(contributor:
|
7
|
+
new(contributor:).map
|
7
8
|
end
|
8
9
|
|
9
10
|
# @param [Cocina::Models::Contributor] contributor to map
|
@@ -12,12 +13,10 @@ class SulOrcidClient
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def map
|
15
|
-
return unless CocinaSupport.cited?(contributor)
|
16
|
-
|
17
16
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
'credit-name': map_credit_name,
|
18
|
+
'contributor-orcid': map_orcid,
|
19
|
+
'contributor-attributes': map_attributes
|
21
20
|
}.compact
|
22
21
|
end
|
23
22
|
|
@@ -27,54 +26,100 @@ class SulOrcidClient
|
|
27
26
|
|
28
27
|
def map_credit_name
|
29
28
|
value = if contributor.name.first&.structuredValue.present?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
name_from_structured_value(contributor.name.first.structuredValue)
|
30
|
+
else
|
31
|
+
contributor.name.first&.value
|
32
|
+
end
|
34
33
|
|
35
34
|
return unless value
|
36
35
|
|
37
36
|
{
|
38
|
-
value:
|
37
|
+
value:
|
39
38
|
}
|
40
39
|
end
|
41
40
|
|
41
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
42
42
|
def name_from_structured_value(structured_value)
|
43
|
-
forename = structured_value.find { |name_part| name_part.type ==
|
44
|
-
surname = structured_value.find { |name_part| name_part.type ==
|
45
|
-
|
43
|
+
forename = structured_value.find { |name_part| name_part.type == 'forename' }&.value
|
44
|
+
surname = structured_value.find { |name_part| name_part.type == 'surname' }&.value
|
45
|
+
|
46
|
+
if forename.present? || surname.present?
|
47
|
+
[forename, surname].compact.join(' ')
|
48
|
+
else
|
49
|
+
# take first value for the Stanford University organization. Do not map the department/institute suborganization for now.
|
50
|
+
structured_value.first&.value
|
51
|
+
end
|
46
52
|
end
|
53
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
54
|
+
|
55
|
+
IDENTIFIER_TYPES = %w[ORCID ROR].freeze
|
47
56
|
|
48
57
|
def map_orcid
|
49
|
-
|
58
|
+
if contributor.name.first&.structuredValue.present?
|
59
|
+
# there could be an identifier in the structuredValue if it has a suborganization
|
60
|
+
if contributor.name.first.structuredValue.first&.identifier.present?
|
61
|
+
orcid_from_structured_value
|
62
|
+
else
|
63
|
+
orcid_from_contributor
|
64
|
+
end
|
65
|
+
else
|
66
|
+
orcid_from_contributor
|
67
|
+
end
|
68
|
+
end
|
50
69
|
|
51
|
-
|
70
|
+
def identifier_from_structured_value(structured_value)
|
71
|
+
structured_value.identifier.find { |identifier| IDENTIFIER_TYPES.include?(identifier.type) }
|
72
|
+
end
|
73
|
+
|
74
|
+
# the identifier in the structuredValue has the uri in a different properties than a top-level contributor.identifier
|
75
|
+
def map_orcid_from_structured_value(identifier)
|
76
|
+
{
|
77
|
+
uri: identifier.uri || identifier.value,
|
78
|
+
path: URI(identifier.uri).path.split('/').last,
|
79
|
+
host: identifier.type == 'ORCID' ? 'orcid.org' : 'ror.org'
|
80
|
+
}
|
81
|
+
end
|
52
82
|
|
83
|
+
def map_orcid_from_contributor(identifier)
|
53
84
|
{
|
54
85
|
uri: URI.join(identifier.source.uri, identifier.value).to_s,
|
55
86
|
path: identifier.value,
|
56
|
-
host:
|
87
|
+
host: identifier.type == 'ORCID' ? 'orcid.org' : 'ror.org'
|
57
88
|
}
|
58
89
|
end
|
59
90
|
|
91
|
+
# find and map an orcid from a contributor.identifier
|
92
|
+
def orcid_from_contributor
|
93
|
+
identifier = contributor.identifier.find { |check_identifier| IDENTIFIER_TYPES.include?(check_identifier.type) }
|
94
|
+
return unless identifier
|
95
|
+
|
96
|
+
map_orcid_from_contributor(identifier)
|
97
|
+
end
|
98
|
+
|
99
|
+
# find and map an orcid from a contributor.structuredValue.identifier
|
100
|
+
def orcid_from_structured_value
|
101
|
+
identifier = identifier_from_structured_value(contributor.name.first.structuredValue.first)
|
102
|
+
map_orcid_from_structured_value(identifier)
|
103
|
+
end
|
104
|
+
|
60
105
|
def map_attributes
|
61
106
|
{
|
62
|
-
|
107
|
+
'contributor-role': map_role
|
63
108
|
}.compact.presence
|
64
109
|
end
|
65
110
|
|
66
111
|
MARC_RELATOR_MAP = {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
112
|
+
'aut' => 'author',
|
113
|
+
'cmp' => 'author',
|
114
|
+
'ctb' => 'author',
|
115
|
+
'cre' => 'author',
|
116
|
+
'edt' => 'editor',
|
117
|
+
'rth' => 'principal-investigator'
|
118
|
+
}.freeze
|
74
119
|
|
75
120
|
def map_role
|
76
|
-
role = contributor.role.find do |
|
77
|
-
|
121
|
+
role = contributor.role.find do |check_role|
|
122
|
+
check_role.source&.code == 'marcrelator' && MARC_RELATOR_MAP.key?(check_role.code)
|
78
123
|
end
|
79
124
|
|
80
125
|
return unless role
|