4031: Find for collection dependencies even in the middle of script parameter
[arvados.git] / apps / workbench / app / controllers / jobs_controller.rb
index 40f4378544cb7c38ee659a3055874bed8f9cb533..00ce0a53825fa0228c267cc9365080e62099a630 100644 (file)
@@ -3,17 +3,29 @@ class JobsController < ApplicationController
   def generate_provenance(jobs)
     return if params['tab_pane'] != "Provenance"
 
-    nodes = []
+    nodes = {}
     collections = []
+    hashes = []
     jobs.each do |j|
-      nodes << j
-      collections << j[:output]
-      collections.concat(ProvenanceHelper::find_collections(j[:script_parameters]))
-      nodes << {:uuid => j[:script_version]}
+      nodes[j[:uuid]] = j
+      hashes << j[:output]
+      ProvenanceHelper::find_collections(j[:script_parameters]) do |hash, uuid|
+        collections << uuid if uuid
+        hashes << hash if hash
+      end
+      nodes[j[:script_version]] = {:uuid => j[:script_version]}
     end
 
     Collection.where(uuid: collections).each do |c|
-      nodes << c
+      nodes[c[:portable_data_hash]] = c
+    end
+
+    Collection.where(portable_data_hash: hashes).each do |c|
+      nodes[c[:portable_data_hash]] = c
+    end
+
+    nodes.each do |n|
+      puts "\n#{n.inspect}"
     end
 
     @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {