1 class ActionsController < ApplicationController
4 def self.expose_action method, &block
5 @@exposed_actions[method] = true
6 define_method method, block
10 ArvadosBase::resource_class_for_uuid(params[:uuid])
14 params.keys.collect(&:to_sym).each do |param|
15 if @@exposed_actions[param]
16 return self.send(param)
22 expose_action :copy_selections_into_project do
23 link_selections = Link.filter([['uuid','in',params["selection"]]])
24 link_uuids = link_selections.collect(&:uuid)
26 # Given a link uuid, we'll add the link's head_uuid. Given another
27 # type, we'll add the object itself.
28 uuids_to_add = params["selection"] - link_uuids
29 uuids_to_add += link_selections.collect(&:head_uuid)
31 # Skip anything that's already here.
33 filter([['tail_uuid','=',@object.uuid],
34 ['head_uuid','in',uuids_to_add],
35 ['link_class','=','name']]).
37 uuids_to_add -= already_named
39 # Given a name link, we'll try to add the linked object using the
43 select { |x| x.link_class == 'name' }.
45 name_for[link.head_uuid] = link.name
48 uuids_to_add.each do |s|
49 name = name_for[s] || s
51 Link.create(tail_uuid: @object.uuid,
56 Link.create(tail_uuid: @object.uuid,
59 name: name + " (#{Time.now.localtime})")
65 expose_action :combine_selected_files_into_collection do
68 params["selection"].each do |s|
69 m = CollectionsHelper.match(s)
70 if m and m[1] and m[2]
71 lst.append(m[1] + m[2])
76 collections = Collection.where(uuid: lst)
79 collections.each do |c|
86 mt = chash[m[1]+m[2]].manifest_text
88 IO.popen(['arv-normalize', '--extract', m[4][1..-1]], 'w+b') do |io|
91 while buf = io.read(2**20)
96 combined += chash[m[1]+m[2]].manifest_text
101 IO.popen(['arv-normalize'], 'w+b') do |io|
104 while buf = io.read(2**20)
111 d = Digest::MD5.new()
113 newuuid = "#{d.hexdigest}+#{normalized.length}"
117 'ARVADOS_API_HOST' =>
118 arvados_api_client.arvados_v1_base.
119 sub(/\/arvados\/v1/, '').
120 sub(/^https?:\/\//, ''),
121 'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
122 'ARVADOS_API_HOST_INSECURE' =>
123 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
126 IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
129 while buf = io.read(2**20)
134 newc = Collection.new({:uuid => newuuid, :manifest_text => normalized})
141 link_class: "provenance",
147 redirect_to controller: 'collections', action: :show, id: newc.uuid