commonmeta-ruby 3.4.3 → 3.4.5
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/Gemfile.lock +1 -1
- data/lib/commonmeta/crossref_utils.rb +21 -18
- data/lib/commonmeta/readers/json_feed_reader.rb +34 -5
- data/lib/commonmeta/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_related_identifiers_and_funding.yml +580 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed_item_metadata/ghost_post_with_related_identifiers_and_link_to_peer-reviewed_article.yml +4911 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_feed_item_from_rogue_scholar_with_relations_and_funding.yml +580 -0
- data/spec/readers/json_feed_reader_spec.rb +52 -1
- data/spec/writers/crossref_xml_writer_spec.rb +36 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ed18313eb13c333097da69b4990dde7d57862f16c898ca085ed70a7025496c
|
4
|
+
data.tar.gz: a798ca9f507d5070a9e6b86e5f55dd47378c054c080b076229dbb6c02dbcb1ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee34121b325b7b802ee4f67feaaf3d98393548a879a3b831d3d5950dde7e1a9510daf4d021fc195817ee7ea97004c62aa3cf0b32392d230c5dbbea7096fe0d0
|
7
|
+
data.tar.gz: 8eb084064dbbd0d2a6cd2c88de46d667813c298786ceb5c83b8dacd90ff33e1d8a6508d27f6f92526457386171b8c2d3ba6330b9d0e55bb5c8fab96cce0e1690
|
data/Gemfile.lock
CHANGED
@@ -62,6 +62,7 @@ module Commonmeta
|
|
62
62
|
insert_crossref_abstract(xml)
|
63
63
|
insert_crossref_issn(xml)
|
64
64
|
insert_item_number(xml)
|
65
|
+
insert_funding_references(xml)
|
65
66
|
insert_crossref_access_indicators(xml)
|
66
67
|
insert_crossref_relations(xml)
|
67
68
|
insert_doi_data(xml)
|
@@ -81,6 +82,7 @@ module Commonmeta
|
|
81
82
|
insert_institution(xml)
|
82
83
|
insert_item_number(xml)
|
83
84
|
insert_crossref_abstract(xml)
|
85
|
+
insert_funding_references(xml)
|
84
86
|
insert_crossref_access_indicators(xml)
|
85
87
|
insert_crossref_relations(xml)
|
86
88
|
insert_doi_data(xml)
|
@@ -99,7 +101,7 @@ module Commonmeta
|
|
99
101
|
Array.wrap(creators).each_with_index do |creator, index|
|
100
102
|
if creator["type"] == "Organization" && creator["name"].present?
|
101
103
|
xml.organization(creator["name"], "contributor_role" => "author",
|
102
|
-
|
104
|
+
"sequence" => index.zero? ? "first" : "additional")
|
103
105
|
elsif creator["givenName"].present? || creator["familyName"].present?
|
104
106
|
xml.person_name("contributor_role" => "author",
|
105
107
|
"sequence" => index.zero? ? "first" : "additional") do
|
@@ -128,7 +130,7 @@ module Commonmeta
|
|
128
130
|
xml.affiliations do
|
129
131
|
xml.institution do
|
130
132
|
xml.institution_name(creator.dig("affiliation", 0, "name")) if creator.dig("affiliation", 0, "name").present?
|
131
|
-
xml.institution_id(creator.dig("affiliation", 0, "id"),
|
133
|
+
xml.institution_id(creator.dig("affiliation", 0, "id"), "type" => "ror") if creator.dig("affiliation", 0, "id").present?
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
@@ -138,7 +140,7 @@ module Commonmeta
|
|
138
140
|
xml.affiliations do
|
139
141
|
xml.institution do
|
140
142
|
xml.institution_name(creator.dig("affiliation", 0, "name")) if creator.dig("affiliation", 0, "name").present?
|
141
|
-
xml.institution_id(creator.dig("affiliation", 0, "id"),
|
143
|
+
xml.institution_id(creator.dig("affiliation", 0, "id"), "type" => "ror") if creator.dig("affiliation", 0, "id").present?
|
142
144
|
end
|
143
145
|
end
|
144
146
|
end
|
@@ -218,7 +220,7 @@ module Commonmeta
|
|
218
220
|
end
|
219
221
|
end
|
220
222
|
end
|
221
|
-
|
223
|
+
|
222
224
|
# def insert_dates(xml)
|
223
225
|
# return xml unless Array.wrap(dates).present?
|
224
226
|
|
@@ -230,20 +232,21 @@ module Commonmeta
|
|
230
232
|
# end
|
231
233
|
# end
|
232
234
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
235
|
+
def insert_funding_references(xml)
|
236
|
+
return xml if funding_references.blank?
|
237
|
+
|
238
|
+
xml.program("xmlns" => "http://www.crossref.org/fundref.xsd",
|
239
|
+
"name" => "fundref") do
|
240
|
+
funding_references.each do |funding_reference|
|
241
|
+
xml.assertion("name" => "fundgroup") do
|
242
|
+
xml.assertion(funding_reference["funderName"], "name" => "funder_name") do
|
243
|
+
xml.assertion(funding_reference["funderIdentifier"], "name" => "funder_identifier")
|
244
|
+
end
|
245
|
+
xml.assertion(funding_reference["awardNumber"], "name" => "award_number")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
247
250
|
|
248
251
|
def insert_crossref_subjects(xml)
|
249
252
|
return xml unless subjects.present?
|
@@ -62,6 +62,7 @@ module Commonmeta
|
|
62
62
|
sum
|
63
63
|
end
|
64
64
|
references = get_references(meta)
|
65
|
+
funding_references = get_funding_references(meta)
|
65
66
|
related_identifiers = get_related_identifiers(meta)
|
66
67
|
alternate_identifiers = [{ "alternateIdentifier" => meta["id"], "alternateIdentifierType" => "UUID" }]
|
67
68
|
|
@@ -78,6 +79,7 @@ module Commonmeta
|
|
78
79
|
"license" => license,
|
79
80
|
"subjects" => subjects.presence,
|
80
81
|
"references" => references.presence,
|
82
|
+
"funding_references" => funding_references.presence,
|
81
83
|
"related_identifiers" => related_identifiers.presence,
|
82
84
|
"alternate_identifiers" => alternate_identifiers,
|
83
85
|
"state" => state }.compact.merge(read_options)
|
@@ -89,10 +91,10 @@ module Commonmeta
|
|
89
91
|
begin
|
90
92
|
if reference["doi"] && validate_doi(reference["doi"])
|
91
93
|
response = HTTP.follow
|
92
|
-
|
93
|
-
|
94
|
+
.headers(:accept => "application/vnd.citationstyles.csl+json")
|
95
|
+
.get(reference["doi"])
|
94
96
|
csl = JSON.parse(response.body.to_s)
|
95
|
-
sum << reference.merge("title" => csl[
|
97
|
+
sum << reference.merge("title" => csl["title"], "publicationYear" => csl.dig("issued", "date-parts", 0, 0).to_s) if [200, 301, 302].include? response.status
|
96
98
|
elsif reference["url"] && validate_url(reference["url"]) == "URL"
|
97
99
|
sum << reference if [200, 301, 302].include? HTTP.head(reference["url"]).status
|
98
100
|
end
|
@@ -106,10 +108,11 @@ module Commonmeta
|
|
106
108
|
end
|
107
109
|
|
108
110
|
def get_related_identifiers(meta)
|
109
|
-
# check that relationships resolve
|
111
|
+
# check that relationships resolve and has a supported type
|
112
|
+
supported_types = %w[IsIdenticalTo IsPreprintOf IsTranslationOf]
|
110
113
|
Array.wrap(meta["relationships"]).reduce([]) do |sum, relationship|
|
111
114
|
begin
|
112
|
-
if [200, 301, 302].include?
|
115
|
+
if supported_types.include?(relationship["type"]) && [200, 301, 302].include?(HTTP.head(relationship["url"]).status)
|
113
116
|
sum << { "id" => relationship["url"], "type" => relationship["type"] }
|
114
117
|
end
|
115
118
|
rescue => error
|
@@ -121,6 +124,32 @@ module Commonmeta
|
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
127
|
+
def get_funding_references(meta)
|
128
|
+
# check that relationships resolve and have type "HasAward"
|
129
|
+
Array.wrap(meta["relationships"]).reduce([]) do |sum, relationship|
|
130
|
+
begin
|
131
|
+
# funder is European Commission
|
132
|
+
if validate_prefix(relationship["url"]) == "10.3030" || URI.parse(relationship["url"]).host == "cordis.europa.eu"
|
133
|
+
relationship["funderIdentifier"] = "http://doi.org/10.13039/501100000780"
|
134
|
+
relationship["funderName"] = "European Commission"
|
135
|
+
relationship["awardNumber"] = relationship["url"].split("/").last
|
136
|
+
end
|
137
|
+
if relationship["type"] == "HasAward" && relationship["funderName"]
|
138
|
+
sum << {
|
139
|
+
"funderIdentifier" => relationship["funderIdentifier"],
|
140
|
+
"funderName" => relationship["funderName"],
|
141
|
+
"awardNumber" => relationship["awardNumber"],
|
142
|
+
}
|
143
|
+
end
|
144
|
+
rescue => error
|
145
|
+
# puts "Error: #{error.message}"
|
146
|
+
# puts "Error: #{reference}"
|
147
|
+
end
|
148
|
+
|
149
|
+
sum
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
124
153
|
def get_json_feed_unregistered
|
125
154
|
# get JSON Feed items not registered as DOIs
|
126
155
|
|
data/lib/commonmeta/version.rb
CHANGED