1 class CollectionsController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:graph]
3 skip_before_filter :check_user_agreements, :only => [:show_file]
10 if params[:search].andand.length.andand > 0
11 tags = Link.where(any: ['contains', params[:search]])
12 @collections = (Collection.where(uuid: tags.collect(&:head_uuid)) |
13 Collection.where(any: ['contains', params[:search]])).
16 @collections = Collection.limit(100)
18 @links = Link.limit(1000).
19 where(head_uuid: @collections.collect(&:uuid))
21 @collections.each do |c|
22 @collection_info[c.uuid] = {
31 @collection_info[link.head_uuid] ||= {}
32 info = @collection_info[link.head_uuid]
35 info[:tags] << link.name
38 info[:wanted_by_me] ||= link.tail_uuid == current_user.uuid
40 info[:provenance] << link.name
44 @request_url = request.url
48 opts = params.merge(arvados_api_token: Thread.current[:arvados_api_token])
49 if r = params[:file].match(/(\.\w+)/)
52 self.response.headers['Content-Type'] =
53 Rack::Mime::MIME_TYPES[ext] || 'application/octet-stream'
54 self.response.headers['Content-Length'] = params[:size] if params[:size]
55 self.response.headers['Content-Disposition'] = params[:disposition] if params[:disposition]
56 self.response_body = FileStreamer.new opts
60 return super if !@object
63 @output2colorindex = {}
64 @sourcedata = {params[:uuid] => {uuid: params[:uuid]}}
71 Job.where(output: @sourcedata.keys).sort_by { |a| a.finished_at || a.created_at }.reverse.each do |job|
72 if !@output2colorindex[job.output]
74 @output2colorindex[job.output] = (colorindex += 1) % 10
75 @provenance << {job: job, output: job.output}
76 @sourcedata.delete job.output
77 @output2job[job.output] = job
78 job.dependencies.each do |new_source_data|
79 unless @output2colorindex[new_source_data]
80 @sourcedata[new_source_data] = {uuid: new_source_data}
87 Link.where(head_uuid: @sourcedata.keys | @output2job.keys).each do |link|
88 if link.link_class == 'resources' and link.name == 'wants'
89 @protected[link.head_uuid] = true
92 Link.where(tail_uuid: @sourcedata.keys).each do |link|
93 if link.link_class == 'data_origin'
94 @sourcedata[link.tail_uuid][:data_origins] ||= []
95 @sourcedata[link.tail_uuid][:data_origins] << [link.name, link.head_kind, link.head_uuid]
98 Collection.where(uuid: @sourcedata.keys).each do |collection|
99 if @sourcedata[collection.uuid]
100 @sourcedata[collection.uuid][:collection] = collection
107 def initialize(opts={})
111 return unless @opts[:uuid] && @opts[:file]
114 'ARVADOS_API_HOST' =>
115 $arvados_api_client.arvados_v1_base.
116 sub(/\/arvados\/v1/, '').
117 sub(/^https?:\/\//, ''),
118 'ARVADOS_API_TOKEN' =>
119 @opts[:arvados_api_token],
120 'ARVADOS_API_HOST_INSECURE' =>
121 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
123 IO.popen([env, 'arv-get', "#{@opts[:uuid]}/#{@opts[:file]}"],
125 while buf = io.read(2**20)
129 Rails.logger.warn("#{@opts[:uuid]}/#{@opts[:file]}: #{$?}") if $? != 0