-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to v4 DOI schema and REST/JSON API
- Loading branch information
Showing
7 changed files
with
88 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,71 @@ | ||
module IdentifiableByDoi | ||
def to_doi_xml | ||
xml = ::Builder::XmlMarkup.new | ||
xml.tag! 'resource', schema_definitions do | ||
xml.tag! 'creators' do | ||
xml.tag! 'creator' do | ||
xml.tag! 'creatorName', collector_name | ||
end | ||
end | ||
xml.tag! 'identifier', '10.4225/72/bcndhj78437hjk', identifierType: 'DOI' | ||
xml.tag! 'titles' do | ||
xml.tag! 'title', title | ||
end | ||
xml.tag! 'publisher', 'PARADISEC' | ||
# Items are the only type which contain the true publication date, so prefer that, but fall back to the date it was added to Nabu | ||
publicationYear = case | ||
when is_a?(Item) | ||
originated_on || created_at | ||
when is_a?(Essence) | ||
item.originated_on || created_at | ||
else | ||
created_at | ||
end.year | ||
|
||
xml.tag! 'publicationYear', publicationYear | ||
|
||
xml.tag! 'contributors' do | ||
xml.tag! 'contributor', contributorType: 'DataCollector' do | ||
xml.tag! 'contributorName', collector_name | ||
end | ||
|
||
if respond_to?(:university_name) && university_name.present? | ||
xml.tag! 'contributor', contributorType: 'DataCollector' do | ||
xml.tag! 'contributorName', university_name | ||
end | ||
end | ||
end | ||
|
||
# parent should exist for everything except Collection | ||
if parent.present? | ||
xml.tag! 'relatedIdentifiers' do | ||
xml.tag! 'relatedIdentifier', parent.doi, relatedIdentifierType: 'DOI', relationType: is_a?(Item) ? 'IsPartOf' : 'IsSourceOf' | ||
end | ||
end | ||
def to_doi_json(prefix) | ||
# NOTE: Items are the only type which contain the true publication date, so prefer that, but fall back to the date it was added to Nabu | ||
publication_date = if is_a?(Item) | ||
originated_on || created_at | ||
elsif is_a?(Essence) | ||
item.originated_on || created_at | ||
else | ||
created_at | ||
end | ||
|
||
parent = if is_a?(Item) | ||
collection | ||
elsif is_a?(Essence) | ||
item | ||
end | ||
|
||
resource_type_general = if is_a?(Item) | ||
'Dataset' | ||
elsif is_a?(Essence) | ||
essence_resource_type | ||
else | ||
'Collection' | ||
end | ||
|
||
contributors = [{ name: collector_name, contributorType: 'DataCollector' }] | ||
contributors.push({ name: university_name, contributorType: 'DataCollector' }) if respond_to?(:university_name) | ||
|
||
attributes = { | ||
event: 'publish', | ||
prefix:, | ||
creators: [{ name: collector_name }], | ||
titles: [{ title: }], | ||
publisher: 'PARADISEC', | ||
publicationYear: publication_date.year, | ||
contributors:, | ||
url: full_path, | ||
types: { | ||
resourceTypeGeneral: resource_type_general | ||
} | ||
} | ||
|
||
# NOTE: parent should exist for everything except Collection | ||
if parent | ||
attributes['relatedIdentifiers'] = [{ | ||
relatedIdentifier: parent.doi, | ||
relatedIdentifierType: 'DOI', | ||
relationType: is_a?(Item) ? 'IsPartOf' : 'IsSourceOf' | ||
}] | ||
end | ||
|
||
{ | ||
data: { | ||
type: 'dois', | ||
attributes: | ||
} | ||
}.to_json | ||
end | ||
|
||
private | ||
|
||
def schema_definitions | ||
{ | ||
'xmlns' => 'http://datacite.org/schema/kernel-3', | ||
'xsi:schemaLocation' => 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd', | ||
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', | ||
} | ||
def essence_resource_type | ||
case Essence.first.mimetype.split('/')[0] | ||
when 'audio' then 'Sound' | ||
when 'video' then 'Audiovisual' | ||
when 'image' then 'Image' | ||
when 'text' then 'Text' | ||
else 'Other' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters