1 class CollectionsController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:provenance]
3 skip_before_filter :check_user_agreements, :only => [:show_file]
6 %w(Files Attributes Metadata Provenance_graph Used_by JSON API)
9 if params[:search].andand.length.andand > 0
10 tags = Link.where(any: ['contains', params[:search]])
11 @collections = (Collection.where(uuid: tags.collect(&:head_uuid)) |
12 Collection.where(any: ['contains', params[:search]])).
16 limit = params[:limit].to_i
22 offset = params[:offset].to_i
27 @collections = Collection.limit(limit).offset(offset)
29 @links = Link.limit(1000).
30 where(head_uuid: @collections.collect(&:uuid))
32 @collections.each do |c|
33 @collection_info[c.uuid] = {
42 @collection_info[link.head_uuid] ||= {}
43 info = @collection_info[link.head_uuid]
46 info[:tag_links] << link
49 info[:wanted_by_me] ||= link.tail_uuid == current_user.uuid
51 info[:provenance] << link.name
55 @request_url = request.url
59 opts = params.merge(arvados_api_token: Thread.current[:arvados_api_token])
60 if r = params[:file].match(/(\.\w+)/)
63 self.response.headers['Content-Type'] =
64 Rack::Mime::MIME_TYPES[ext] || 'application/octet-stream'
65 self.response.headers['Content-Length'] = params[:size] if params[:size]
66 self.response.headers['Content-Disposition'] = params[:disposition] if params[:disposition]
67 self.response_body = FileStreamer.new opts
72 return super if !@object
75 @output2colorindex = {}
76 @sourcedata = {params[:uuid] => {uuid: params[:uuid]}}
83 Job.where(output: @sourcedata.keys).sort_by { |a| a.finished_at || a.created_at }.reverse.each do |job|
84 if !@output2colorindex[job.output]
86 @output2colorindex[job.output] = (colorindex += 1) % 10
87 @provenance << {job: job, output: job.output}
88 @sourcedata.delete job.output
89 @output2job[job.output] = job
90 job.dependencies.each do |new_source_data|
91 unless @output2colorindex[new_source_data]
92 @sourcedata[new_source_data] = {uuid: new_source_data}
99 Link.where(head_uuid: @sourcedata.keys | @output2job.keys).each do |link|
100 if link.link_class == 'resources' and link.name == 'wants'
101 @protected[link.head_uuid] = true
104 Link.where(tail_uuid: @sourcedata.keys).each do |link|
105 if link.link_class == 'data_origin'
106 @sourcedata[link.tail_uuid][:data_origins] ||= []
107 @sourcedata[link.tail_uuid][:data_origins] << [link.name, link.head_kind, link.head_uuid]
110 Collection.where(uuid: @sourcedata.keys).each do |collection|
111 if @sourcedata[collection.uuid]
112 @sourcedata[collection.uuid][:collection] = collection
116 Collection.where(uuid: @object.uuid).each do |u|
118 @prov_svg = ProvenanceHelper::create_provenance_graph(u.provenance, "provenance_svg",
119 {:request => request,
120 :direction => :bottom_up,
121 :combine_jobs => :script_only}) rescue nil
122 @used_by_svg = ProvenanceHelper::create_provenance_graph(u.used_by, "used_by_svg",
123 {:request => request,
124 :direction => :top_down,
125 :combine_jobs => :script_only,
126 :pdata_only => true}) rescue nil
132 def initialize(opts={})
136 return unless @opts[:uuid] && @opts[:file]
139 'ARVADOS_API_HOST' =>
140 $arvados_api_client.arvados_v1_base.
141 sub(/\/arvados\/v1/, '').
142 sub(/^https?:\/\//, ''),
143 'ARVADOS_API_TOKEN' =>
144 @opts[:arvados_api_token],
145 'ARVADOS_API_HOST_INSECURE' =>
146 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
148 IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
150 while buf = io.read(2**20)
154 Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0