Skip to content

Commit

Permalink
update for DataCite Schema 4, gh-68
Browse files Browse the repository at this point in the history
  • Loading branch information
stkenny committed Jan 11, 2025
1 parent e9874ce commit fc70289
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 88 deletions.
6 changes: 5 additions & 1 deletion app/controllers/metadata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def update_or_mint_doi

doi_metadata_fields = {}
@doi.metadata_fields.each do |field|
doi_metadata_fields[field] = @object.send(field.to_sym)
if field == "type"
doi_metadata_fields['resource_type'] = @object.send(field.to_sym)
else
doi_metadata_fields[field] = @object.send(field.to_sym)
end
end
@doi.update_metadata(doi_metadata_fields)
new_doi_if_required(@object, @doi, 'metadata updated')
Expand Down
1 change: 1 addition & 0 deletions app/models/datacite_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def set_metadata
metadata.creation_date = object.creation_date.to_a if object.creation_date.present?
metadata.published_date = object.published_date.to_a if object.published_date.present?
metadata.rights = object.rights.to_a if object.rights
metadata.resource_type = object.type.to_a
metadata.save

self.doi_metadata = metadata
Expand Down
61 changes: 58 additions & 3 deletions app/models/doi_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,53 @@ class DoiMetadata < ActiveRecord::Base
serialize :creator, coder: YAML
serialize :creation_date, coder: YAML
serialize :published_date, coder: YAML
serialize :resource_type, coder: YAML

RESOURCE_TYPE_GENERAL = %w(AudioVisual
Award
Book
BookChapter
Collection
ComputationalNotebook
ConferencePaper
ConferenceProceeding
DataPaper
Dataset
Dissertation
Event
Image
InteractiveResource
Instrument
Journal
JournalArticle
Model
OutputManagmentPlan
PeerReview
PhysicalObject
Preprint
Project
Report
Service
Software
Sound
Standard
StudyRegistration
Text
Worklow
Other
)

def metadata_fields
%w(title subject creator description creation_date published_date)
%w(title subject creator description creation_date published_date type)
end

def to_xml
resource_type = resource_type_general

builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
xml.resource('xmlns' => 'http://datacite.org/schema/kernel-3',
xml.resource('xmlns' => 'http://datacite.org/schema/kernel-4',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation'=>'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd') {
'xsi:schemaLocation'=>'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd') {
# mandatory entries
xml.identifier self.datacite_doi.doi, identifierType: 'DOI'
xml.creators {
Expand All @@ -32,6 +69,13 @@ def to_xml
}
xml.publisher DoiConfig.publisher
xml.publicationYear publication_year

if resource_type_general.is_a?(Array)
xml.resourceType(resource_type_general[1], resourceTypeGeneral: resource_type_general[0])
else
xml.resourceType '', resourceTypeGeneral: resource_type_general
end

}
end

Expand All @@ -41,4 +85,15 @@ def to_xml
def publication_year
Time.now.year
end

def resource_type_general
resource_type_matches = resource_type.map(&:camelcase).intersection(RESOURCE_TYPE_GENERAL)
return resource_type_matches.first unless resource_type_matches.empty?

downcased = resource_type.map(&:downcase)

return ["Other", "3D"] if downcased.include?("3d")
return "AudioVisual" if downcased.include?("movingimage") || downcased.include?("video")
return "Sound" if downcased.include?("audio")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddResourceTypeToDoiMetadata < ActiveRecord::Migration[7.1]
def change
add_column :doi_metadata, :resource_type, :text
end
end
Loading

0 comments on commit fc70289

Please sign in to comment.