Skip to content

Commit ce265d7

Browse files
committed
update to apply identifier=>doi where the doi is present and the type responds, for all CreativeWork types, not just DataFile
1 parent c610583 commit ce265d7

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

lib/seek/bio_schema/resource_decorators/creative_work.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ class CreativeWork < Thing
1616
content_type: :encodingFormat,
1717
subject_of: :subjectOf,
1818
part_of: :isPartOf,
19-
previous_version_url: :isBasedOn
19+
doi: :identifier,
20+
previous_version_url: :isBasedOn
21+
22+
def doi
23+
"https://doi.org/#{resource.doi}" if resource.try(:doi).present?
24+
end
2025

2126
def content_type
2227
return unless resource.respond_to?(:content_blob) && resource.content_blob

lib/seek/bio_schema/resource_decorators/data_file.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ class DataFile < CreativeWork
66
include ActionView::Helpers::NumberHelper
77

88

9-
schema_mappings doi: :identifier,
10-
distribution: :distribution
9+
schema_mappings distribution: :distribution
1110

1211
DATASET_PROFILE = 'https://bioschemas.org/profiles/Dataset/0.3-RELEASE-2019_06_14/'.freeze
1312

14-
def doi
15-
"https://doi.org/#{resource.doi}" if resource.doi
16-
end
17-
1813
def description
1914
description = resource.description&.truncate(4999)
2015
description = 'Description not specified' if description.blank?

test/unit/bio_schema/decorator_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DecoratorTest < ActiveSupport::TestCase
1919

2020
test 'CreativeWork' do
2121
event = FactoryBot.create(:event, policy: FactoryBot.create(:public_policy))
22-
document = FactoryBot.create(:document, events: [event], license: 'CC-BY-4.0', creators: [FactoryBot.create(:person)])
22+
document = FactoryBot.create(:document, events: [event], license: 'CC-BY-4.0', creators: [FactoryBot.create(:person)], doi: '10.10.10.10/test.1')
2323
document.add_annotations('yellow, lorry', 'tag', User.first)
2424
disable_authorization_checks { document.save! }
2525

@@ -29,14 +29,15 @@ class DecoratorTest < ActiveSupport::TestCase
2929
assert_equal %w[lorry yellow], decorator.keywords.split(',').collect(&:strip).sort
3030
assert_equal 'https://spdx.org/licenses/CC-BY-4.0', decorator.license
3131
assert_equal 'application/pdf', decorator.content_type
32+
assert_equal 'https://doi.org/10.10.10.10/test.1', decorator.doi
3233
project = document.projects.first
3334
person = document.creators.first
3435
assert_equal [{ :@type => 'Event', :@id => "http://localhost:3000/events/#{event.id}", :name => event.title }], decorator.subject_of
3536
assert_equal [{ :@type => ['Project','Organization'], :@id => "http://localhost:3000/projects/#{project.id}", :name => project.title }], decorator.producer
3637
assert_equal [{ :@type => 'Person', :@id => "http://localhost:3000/people/#{person.id}", :name => person.title }], decorator.all_creators
3738

3839
properties = decorator.attributes.collect(&:property).collect(&:to_s).sort
39-
assert_equal ['@id', 'creator', 'dateCreated', 'dateModified', 'description', 'encodingFormat', 'image', 'isBasedOn', 'isPartOf', 'keywords', 'license', 'name', 'producer', 'subjectOf', 'url', 'version'], properties
40+
assert_equal %w[@id creator dateCreated dateModified description encodingFormat identifier image isBasedOn isPartOf keywords license name producer subjectOf url version], properties
4041
end
4142

4243
test 'Dataset pads or truncates description' do

test/unit/bio_schema/schema_ld_generation_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def setup
411411

412412
test 'document' do
413413
document = travel_to(@current_time) do
414-
document = FactoryBot.create(:document, contributor: @person)
414+
document = FactoryBot.create(:document, contributor: @person, doi: '10.10.10.10/test.1')
415415
document.add_annotations('wibble', 'tag', User.first)
416416
disable_authorization_checks { document.save! }
417417
document
@@ -433,6 +433,7 @@ def setup
433433
{ '@type' => %w[Project Organization], '@id' => "http://localhost:3000/projects/#{document.projects.first.id}",
434434
'name' => document.projects.first.title }
435435
],
436+
'identifier' => 'https://doi.org/10.10.10.10/test.1',
436437
'isPartOf' => [],
437438
'subjectOf' => []
438439
}
@@ -482,7 +483,7 @@ def setup
482483
title: 'This workflow',
483484
description: 'This is a test workflow for bioschema generation',
484485
contributor: @person,
485-
license: 'APSL-2.0')
486+
license: 'APSL-2.0', doi: '10.10.10.10/test.1')
486487

487488
workflow.assets_creators.create!(creator: @person, pos: 1)
488489
workflow.assets_creators.create!(creator: creator2, pos: 2)
@@ -510,6 +511,7 @@ def setup
510511
'url' => "http://localhost:3000/workflows/#{workflow.id}",
511512
'keywords' => 'wibble',
512513
'license' => Seek::License.find('APSL-2.0')&.url,
514+
'identifier' => 'https://doi.org/10.10.10.10/test.1',
513515
'creator' => [
514516
{ '@type' => 'Person', '@id' => "http://localhost:3000/people/#{@person.id}", 'name' => @person.name },
515517
{ '@type' => 'Person', '@id' => "http://localhost:3000/people/#{creator2.id}", 'name' => creator2.name },

0 commit comments

Comments
 (0)