diff --git a/app/models/concerns/workflow_extraction.rb b/app/models/concerns/workflow_extraction.rb index 8e81c30cfb..a256c34f9e 100644 --- a/app/models/concerns/workflow_extraction.rb +++ b/app/models/concerns/workflow_extraction.rb @@ -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) @@ -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 diff --git a/test/unit/workflow_test.rb b/test/unit/workflow_test.rb index e4eb076f71..796dfedf5d 100644 --- a/test/unit/workflow_test.rb +++ b/test/unit/workflow_test.rb @@ -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