Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/models/concerns/workflow_extraction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ def populate_ro_crate(crate)
remotes = git_version.remote_sources
m = main_workflow_blob
if m
crate.main_workflow = main_workflow_blob.to_crate_entity(crate, type: ROCrate::Workflow)
crate.main_workflow = main_workflow_blob.to_crate_entity(crate, type: ROCrate::Workflow, properties: { contentUrl: content_url(m) })
remotes.delete(main_workflow_blob.path)
crate.main_workflow.programming_language = ROCrate::ContextualEntity.new(crate, nil, workflow_class&.ro_crate_metadata || Seek::WorkflowExtractors::Base::NULL_CLASS_METADATA)
end

d = diagram_blob
if d
remotes.delete(d.path)
diagram_entity = d.to_crate_entity(crate, type: ROCrate::WorkflowDiagram)
diagram_entity = d.to_crate_entity(crate, type: ROCrate::WorkflowDiagram, properties: { contentUrl: content_url(d) })
crate.add_data_entity(diagram_entity)
crate.main_workflow.diagram = diagram_entity if crate.main_workflow
else # Was the diagram generated?
Expand All @@ -125,7 +125,7 @@ def populate_ro_crate(crate)
c = abstract_cwl_blob
if c
remotes.delete(c.path)
cwl_entity = c.to_crate_entity(crate, type: ROCrate::WorkflowDescription)
cwl_entity = c.to_crate_entity(crate, type: ROCrate::WorkflowDescription, properties: { contentUrl: content_url(c) })
crate.add_data_entity(cwl_entity)
crate.main_workflow.cwl_description = cwl_entity if crate.main_workflow
end
Expand Down Expand Up @@ -254,6 +254,17 @@ def ro_crate_url(action = nil)
Seek::Util.routes.polymorphic_url(resource, version: version)
end

def content_url(blob)
return unless is_git_versioned?

return unless blob

return blob.url if blob.remote? && blob.fetched?

resource = is_a_version? ? parent : self
Seek::Util.routes.polymorphic_url([resource, :git_download], version: version, path: blob.path)
end

[:main_workflow, :diagram, :abstract_cwl].each do |type|
s_type = type.to_s

Expand Down
4 changes: 2 additions & 2 deletions test/factories/workflows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@
ref: 'refs/heads/main',
commit: 'b6312caabe582d156dd351fab98ce78356c4b74c',
main_workflow_path: 'concat_two_files.ga',
diagram_path: 'diagram.png',
diagram_path: 'diagram.png'
}
}
end

factory(:annotationless_local_git_workflow, class: Workflow) do
title { 'Concat two files' }
with_project_contributor
Expand Down
23 changes: 23 additions & 0 deletions test/unit/workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,27 @@ def bad_generator.write_graph(struct)
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

test 'sets contentUrl in RO-Crate metadata' do
workflow = FactoryBot.create(:local_git_workflow)
disable_authorization_checks do
gv = workflow.git_version
c = gv.add_file('concat_two_files.cwl', StringIO.new(SecureRandom.random_bytes(50)))
gv.update_column(:commit, c)
gv.abstract_cwl_path = 'concat_two_files.cwl'
gv.save!
end

assert workflow.ro_crate.main_workflow.present?
assert_equal "http://localhost:3000/workflows/#{workflow.id}/git/1/download/concat_two_files.ga",
workflow.ro_crate.main_workflow.properties[:contentUrl]

assert workflow.ro_crate.main_workflow_diagram.present?
assert_equal "http://localhost:3000/workflows/#{workflow.id}/git/1/download/diagram.png",
workflow.ro_crate.main_workflow_diagram.properties[:contentUrl]

assert workflow.ro_crate.main_workflow_cwl.present?
assert_equal "http://localhost:3000/workflows/#{workflow.id}/git/1/download/concat_two_files.cwl",
workflow.ro_crate.main_workflow_cwl.properties[:contentUrl]
end
end
Loading