Skip to content

Commit ce9c351

Browse files
Copilotfbacall
andcommitted
Update serializers, views, bioschemas and ingestors for new Author model
Co-authored-by: fbacall <503373+fbacall@users.noreply.github.com>
1 parent 3998e76 commit ce9c351

7 files changed

Lines changed: 45 additions & 8 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class AuthorSerializer < ApplicationSerializer
2+
attributes :id, :first_name, :last_name, :orcid, :full_name
3+
end

app/serializers/material_serializer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class MaterialSerializer < ApplicationSerializer
55

66
:doi, :licence, :version, :status,
77

8-
:contact, :contributors, :authors,
8+
:contact, :contributors,
99

1010
:difficulty_level, :target_audience, :prerequisites, :syllabus, :learning_objectives, :subsets,
1111

@@ -18,4 +18,5 @@ class MaterialSerializer < ApplicationSerializer
1818
has_many :nodes
1919
has_many :collections
2020
has_many :events
21+
has_many :authors
2122
end

app/views/common/_extra_metadata.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<%= display_attribute(resource, :sponsors) { |values| values.join(', ') } %>
6060
<% end %>
6161

62-
<%= display_attribute(resource, :authors) { |values| values.join(', ') } if resource.respond_to?(:authors) %>
62+
<%= display_attribute(resource, :authors) { |values| values.map(&:full_name).join(', ') } if resource.respond_to?(:authors) %>
6363
<%= display_attribute(resource, :contributors) { |values| values.join(', ') } if resource.respond_to?(:contributors) %>
6464
<%= display_attribute(resource, :remote_created_date) if resource.respond_to?(:remote_created_date) %>
6565
<%= display_attribute(resource, :remote_updated_date) if resource.respond_to?(:remote_updated_date) %>

app/views/materials/show.json.jbuilder

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ json.extract! @material, :id, :title, :url, :description,
66

77
:doi, :licence, :version, :status,
88

9-
:contact, :contributors, :authors,
9+
:contact, :contributors,
1010

1111
:difficulty_level, :target_audience, :prerequisites, :syllabus, :learning_objectives, :subsets,
1212

@@ -21,6 +21,8 @@ json.nodes @material.associated_nodes.collect { |x| { name: x[:name], node_id: x
2121
json.collections @material.collections.collect { |x| { title: x[:title], id: x[:id] } }
2222
json.events @material.events.collect { |x| { title: x[:title], id: x[:id] } }
2323

24+
json.authors @material.authors.collect { |a| { id: a.id, first_name: a.first_name, last_name: a.last_name, orcid: a.orcid, full_name: a.full_name } }
25+
2426
json.external_resources do
2527
@material.external_resources.each do |external_resource|
2628
json.partial! 'common/external_resource', external_resource: external_resource

lib/bioschemas/learning_resource_generator.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ def self.bioschemas_profile
1515
property :version, :version
1616
property :description, :description
1717
property :keywords, :keywords
18-
property :author, -> (material) { material.authors.map { |p| person(p) } }
18+
property :author, -> (material) {
19+
material.authors.map { |a|
20+
author_hash = { "@type" => "Person", "name" => a.full_name }
21+
author_hash["@id"] = "https://orcid.org/#{a.orcid}" if a.orcid.present?
22+
author_hash
23+
}
24+
}
1925
property :contributor, -> (material) { material.contributors.map { |p| person(p) } }
2026
property :provider, -> (material) { provider(material) }
2127
property :audience, -> (material) {

lib/ingestors/material_csv_ingestor.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def read(url)
4242
material.date_published = get_column row, 'Published'
4343
material.date_modified = get_column row, 'Modified'
4444
material.difficulty_level = process_competency row, 'Competency'
45-
material.authors = process_array row, 'Authors'
45+
material.authors_attributes = process_authors(process_array(row, 'Authors'))
4646
material.contributors = process_array row, 'Contributors'
4747
material.fields = process_array row, 'Fields'
4848
material.target_audience = process_array row, 'Audiences'
@@ -65,6 +65,23 @@ def read(url)
6565

6666
private
6767

68+
def process_authors(authors_array)
69+
return [] if authors_array.blank?
70+
71+
authors_array.map do |author_name|
72+
# Parse name into first and last name
73+
name_parts = author_name.to_s.strip.split(/\s+/, 2)
74+
first_name = name_parts.length > 1 ? name_parts[0] : ''
75+
last_name = name_parts.length > 1 ? name_parts[1] : name_parts[0]
76+
77+
{
78+
first_name: first_name,
79+
last_name: last_name,
80+
orcid: nil
81+
}
82+
end
83+
end
84+
6885
def process_competency(row, header)
6986
row[header].nil? ? 'notspecified' : row[header]
7087
end

lib/ingestors/zenodo_ingestor.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def process_material(input)
6060
material = OpenStruct.new
6161
material.status = 'active'
6262
material.doi = input['doi'] unless metadata['doi'].nil?
63-
material.authors = []
63+
material.authors_attributes = []
6464
material.contributors = []
6565
unless metadata.nil?
6666
material.title = metadata['title'] unless metadata['title'].nil?
@@ -69,8 +69,16 @@ def process_material(input)
6969
material.licence = metadata['license']['id'] unless metadata.dig('license', 'id').nil?
7070
unless metadata['creators'].nil?
7171
metadata['creators'].each do |c|
72-
entry = c['orcid'].nil? ? c['name'] : "#{c['name']} (orcid: #{c['orcid']})"
73-
material.authors << entry
72+
# Parse name into first and last name
73+
name_parts = c['name'].to_s.strip.split(/\s+/, 2)
74+
first_name = name_parts.length > 1 ? name_parts[0] : ''
75+
last_name = name_parts.length > 1 ? name_parts[1] : name_parts[0]
76+
77+
material.authors_attributes << {
78+
first_name: first_name,
79+
last_name: last_name,
80+
orcid: c['orcid']
81+
}
7482
end
7583
end
7684
unless metadata['contributors'].nil?

0 commit comments

Comments
 (0)