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
26 expose_action :move_selections_into_project do
30 def move_or_copy action
31 uuids_to_add = params["selection"]
33 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
35 each do |resource_class|
36 resource_class.filter([['uuid','in',uuids_to_add]]).each do |src|
37 if resource_class == Collection
38 dst = Link.new(owner_uuid: @object.uuid,
39 tail_uuid: @object.uuid,
47 if dst.respond_to? :'name='
49 dst.name = "Copy of #{dst.name}"
51 dst.name = "Copy of unnamed #{dst.class_for_display.downcase}"
57 raise ArgumentError.new "Unsupported action #{action}"
59 dst.owner_uuid = @object.uuid
60 dst.tail_uuid = @object.uuid if dst.class == Link
65 dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
73 def arv_normalize mt, *opts
75 IO.popen(['arv-normalize'] + opts, 'w+b') do |io|
78 while buf = io.read(2**16)
85 expose_action :combine_selected_files_into_collection do
88 params["selection"].each do |s|
89 a = ArvadosBase::resource_class_for_uuid s
93 m = CollectionsHelper.match(Link.find(s).head_uuid)
97 m = CollectionsHelper.match(s)
100 if m and m[1] and m[2]
101 lst.append(m[1] + m[2])
106 collections = Collection.where(uuid: lst)
109 collections.each do |c|
116 mt = chash[m[1]+m[2]].manifest_text
118 combined += arv_normalize mt, '--extract', m[4][1..-1]
120 combined += chash[m[1]+m[2]].manifest_text
124 normalized = arv_normalize combined
125 normalized_stripped = arv_normalize combined, '--strip'
129 d = Digest::MD5.new()
130 d << normalized_stripped
131 newuuid = "#{d.hexdigest}+#{normalized_stripped.length}"
135 'ARVADOS_API_HOST' =>
136 arvados_api_client.arvados_v1_base.
137 sub(/\/arvados\/v1/, '').
138 sub(/^https?:\/\//, ''),
139 'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
140 'ARVADOS_API_HOST_INSECURE' =>
141 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
144 IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
145 io.write normalized_stripped
147 while buf = io.read(2**16)
151 newc = Collection.new({:uuid => newuuid, :manifest_text => normalized})
158 link_class: "provenance",
164 redirect_to controller: 'collections', action: :show, id: newc.uuid