Skip to content

Commit

Permalink
Add datePublished to RO-Crate root metadata #2013
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Oct 16, 2024
1 parent e4a0399 commit 9859745
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/concerns/workflow_extraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def populate_ro_crate(crate)
remotes.each do |path, url|
crate.add_external_file(url)
end

crate['datePublished'] = git_version.commit_object&.time
else
unless crate.main_workflow
crate.main_workflow = ROCrate::Workflow.new(crate, content_blob.filepath, content_blob.original_filename, contentSize: content_blob.file_size)
Expand All @@ -156,6 +158,7 @@ def populate_ro_crate(crate)
merge_entities(crate, self)

crate['isBasedOn'] = source_link_url if source_link_url && !crate['isBasedOn']
crate['datePublished'] = Time.now unless crate['datePublished']
crate['sdDatePublished'] = Time.now unless crate['sdDatePublished']
crate['creativeWorkStatus'] = I18n.t("maturity_level.#{maturity_level}") if maturity_level

Expand Down
11 changes: 11 additions & 0 deletions test/unit/workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,15 @@ def bad_generator.write_graph(struct)
assert_equal 0, policy.permissions.count
end
end

test 'sets datePublished in RO-Crate metadata' do
time = Time.zone.local(2024, 9, 15, 12, 0, 0)
travel_to(time) do
assert_equal time, FactoryBot.create(:cwl_workflow).ro_crate['datePublished'],
'Should set datePublished to current time'
end

assert_equal '2021-03-31 15:01:47 UTC', FactoryBot.create(:remote_git_workflow).ro_crate['datePublished'].utc.to_s,
'Should set datePublished to time of git commit'
end
end

0 comments on commit 9859745

Please sign in to comment.